简要描述:
websoket平台推送,用于app里面webview或iframe和html请求内容交互
频道KEY规则
string parentKey = $"owner-{pf.OwnerId}-{beforeKey}-{pf.ModuleKey}";
接口版本:
版本号 | 制定人 | 制定日期 | 修订日期 |
---|---|---|---|
v3 | 陈碧贵 | 2023-06-04 | xxxx-xx-xx |
请求URL:
http://{url参数}/bo/api/v3/hub/frontend-backend-interaction/{mkey}
http://localhost:5900/bo/api/v3/hub/frontend-backend-interaction/fbi124567
- {mkey} 为随机请求模式ID
请求方式:
- POST
请求头:
参数名 | 是否必须 | 类型 | 说明 |
---|---|---|---|
XownerId | 是 | string | 项目唯一ID,对应bo_project {ownerId} |
XsysId | 否 | string | 所属系统 对应 bo_system 表 |
XuserFromFirstShareId | string | 否 | 一级分享用户ID, bo_user user_id |
XuserFromSecondShareId | string | 否 | 二级分享用户ID, bo_user user_id |
XverifyApi | 是 | string | 加密规则encryptByDES(`${newGuid()} |
XfilterAreaCode | 否 | string | 行政区编码, 对应 bo_sys_area area_code |
Content-Type: | 是 | string | application/json; charset=utf-8 请求类型 |
Authorization | 是 | string | 当前用户认证信息,通过登录接口获取 Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6 |
请求参数:
{
"opsDataType":"1",
"wsDataType":"1",
"userId":null,
"ownerId" :null,
"sysId":null,
"appId":null,
"tenantId":null,
"channelReceiver":null,
"channelRule":null,
"moduleKey":"fbi+随机值",
"reponseField":null,
"fromTraceId":null,,
"ops":{
"a1":"传递给前端的值",
"a2":"传递给前端的值"
},
"ids":["ddd"]
"subBeforeKey":"mkey"
}
参数名 | 是否必须 | 类型 | 说明 |
---|---|---|---|
_nodejs | 是 | string | common-data 对应/Config/AppNodeJs/Plugins/fn- common-data.js, 通过nodejs插件,对响应结果进行二次处理 common-data 普通数据(小写驼峰)common-data-under 普通数据下划线 |
/// <summary>
/// 推送给websoket的数据是否对象,默认字符串 1 字符串 2 对象 3 数组
/// </summary>
public int OpsDataType { get; set; } = 1;
/// <summary>
/// 推送给websoket的数据是否对象,默认字符串 1 字符串 2 对象 3 数组
/// </summary>
public int WsDataType { get; set; } = 1;
/// <summary>
/// 操作主键信息, 字符串,避免ws时候数据传递失败
/// </summary>
public string OpsValues { get; set; }
返回示例:
正确时返回:
{
"data": {
"channelGlogal": "glogal",
"lastDate": "2023-06-04T16:40:25",
"timestamp": 0.0,
"ownerId": "smdcm",
"appId": "0",
"moduleKey": "fbi-124567",
"ops": {
"ids": "传递给前端的值"
},
"cap": true,
"fromOpRmt": "Null",
"requestModuleType": "Null",
"step": 0,
"steps": 0
},
"currentDay": "2023-06-04",
"cacheDateTimestamp": 0,
"code": "0",
"retCode": "0",
"success": true
}
错误时返回:
{
"code": 0,
"message": ""
"error":{
errorCode:null,
errorText:null
}
"success": false,
}
返回参数说明:
参数名 | 类型 | 说明 |
---|---|---|
success | bool | true 表示数据请求成功(跟code=0一致),调用者优先使用 |
code | int | true 表示数据请求成功(跟code=0一致),调用者优先使用 |
data | object | - |
cacheType | string | redis/sqlite/local 数据来源缓存 的类型(便于开发调试和性能优化) |
cacheDate | date | 最后数据获取时间 |
.netcore服务端实现代码参考:
public partial class HubController : BaseController
{
private readonly IHttpContextAccessor _accessor;
private readonly ISubPush _subPush;
/// <summary>
///
/// </summary>
/// <param name="accessor"></param>
public HubController(IHttpContextAccessor accessor, ISubPush subPush)
{
_accessor = accessor;
_subPush = subPush;
}
/// <summary>
/// 订阅和推送
/// </summary>
/// <param name="pf"></param>
/// <returns></returns>
[HttpPost("mkey")]
public async Task<IActionResult> Sub([FromBody] PFGlobalParameter pf)
{
SubResult result = new SubResult
{
LastDate = DateTimeUtil.Now(),
UserId = pf.UserId,// _authProvider.GetCurrentUserId(pf.OwnerId, pf.SysId),
OwnerId = pf.OwnerId,
SysId = pf.SysId,
AppId = pf.AppId,
TenantId = pf.TenantId,
ChannelReceiver = pf.ChannelReceiver,
ChannelRule = pf.ChannelRule,
ModuleKey = pf.ModuleKey,
ReponseField = pf.ReponseField,
Ops = pf.Ops,
FromTraceId = pf.FromTraceId
};
_subPush.Sub<ResultOps<object>>(new ResultOps<object> { Data = new { id = Guid.NewGuid() } }, pf);
return new JsonResult(new ResultDetail<object> { Success = true, Data = new { } });
}
}
前端VUE调用websoket,刷新数据
mounted() {
this.loadDataPue01();
this.loadDataPue07();
this.onWsWsPull();
},
onWsWsPull() {
let that = this;
that.$reqWs.pull(
(res) => {
that.loadDataPue01();
that.loadDataPue07();
},
{
ownerId: that.$store.getters.ownerId,
mkey: "fbi+随机值",//必须传递
subBeforeKey: "mkey",
position:"显示位置",
field:"reponseField值",
ops:{} //必须传递
}
);
},
},
Maui WS使用
#region websoket监控
WebsoketConnectionManager.OnAsync(new SubModule
{
Mkey = "fbi124567"
}, (reult) =>
{
var resultT = reult;
});
#endregion websoket监控
文档更新时间: 2023-06-04 22:33 作者:admin