Wind 订阅消息推送流程
Wind 订阅消息推送流程
1. 获取消息模版ID
在小游戏控制台中配置订阅消息模版,获取消息模版ID
- 微信小游戏

- 抖音小游戏


2. 订阅消息模版
调用 WindSDK 中的 API 来订阅消息模版,参见各平台的 SDK API 说明:
示例程序
public static void RequestSubscribeMessage(string tmplId)
{
// 第一次点击会注册事件,第二次点击会触发订阅
UOSWindService.Platform.OnTouchEnd(result =>
{
templateId = tmplId; // 第一步中各平台获取到的模版ID/消息ID
UOSWindService.Platform.RequestSubscribeMessage(
tmplIds: new string[] { tmplId },
success: response =>
{
Debug.Log("RequestSubscribeMessage success " + JsonConvert.SerializeObject(response));
foreach (var key in response.Keys)
{
var value = response.TryGetValue(key, out string v) ? v : "empty";
Debug.Log("RequestSubscribeMessage success with key: " + key + " and value: " + value);
}
},
fail: response =>
{
Debug.Log("RequestSubscribeMessage fail, errCode:" + response.errCode + ", errMsg: " + response.errMsg);
},
complete: response =>
{
Debug.Log("RequestSubscribeMessage complete, errMsg: " + response.errMsg);
}
);
});
}3. 调试推送消息
在 UOS 面板中开启 Wind 应用,复制 subscribePusher 云函数地址
用 Post 方法 call 云函数 subscribePusher 来推送消息,在 Headers 中填入 Platform
基本信息
| URL | Method | Content-Type | Headers/Platform |
|---|---|---|---|
| Wind面板中subscribePusher的云函数地址 | POST | application/json | weixin douyin kuaishou |
请求参数
{
"openId": "ofoYC7B_W66bblKTWroTu6kYeqhI",
"data": {
"thing1": {
"value": "29名"
},
"number2": {
"value": "100"
},
"name3": {
"value": "某玩家"
},
"time4": {
"value": "21:28"
}
},
"templateId": "zySZbqaWCimrPe_--T2r7-Aa5kgpSJd4V6z-SOzQOJ4",
"page": ""
}参数说明
| 参数名 | 描述 | 类型 | 必填 |
|---|---|---|---|
| openId | 通过code2Session云函数得到的用户唯一标识ID | String | 是 |
| data | 推送消息内容,格式由消息模版定义 | JSON | 是 |
| templateId | 推送消息模版ID | String | 是 |
| page | 接收到推送消息后点击跳转的页面 | String | 否 |
微信的Data格式
{
"thing1": {
"value": "29名"
},
"number2": {
"value": "100"
},
"name3": {
"value": "某玩家"
},
"time4": {
"value": "21:28"
}
}抖音的Data格式
{
"体力值": "1000",
"温馨提示": "测试提示",
"变更提示": "测试提示",
"活动名称": "测试活动",
"当前体力": "100"
}4. 查看推送消息
可在微信或抖音中收到推送消息