accept"时表示用户同意订阅模板 ID 对应的模板消息且模板可用。// tmplIds:Array of template IDs that need to be subscribedrequestSubscribeMessage(tmplIds) {wx.requestSubscribeMessage({tmplIds,success: (res) => {console.log('wx.requestSubscribeMessage success', res)const keysWithAccept = Object.entries(res).filter(([key, value]) => value === "accept").map(([key]) => key);if (keysWithAccept.length > 0) {// Send subscription messagethis.orderSubscribe(keysWithAccept)} else {wx.showModal({title: 'No available message templates',confirmText: 'Confirm',showCancel: false})}},fail: (res) => {console.log('wx.requestSubscribeMessage fail', res)wx.showModal({title: 'wx.requestSubscribeMessage fail',confirmText: 'Confirm',content: `${res.errMsg}【${res.errCode}】`,showCancel: false})}})}
this.orderSubscribe() 接口,小游戏服务端需要将用户订阅成功的模版、订阅时间、订阅者(openid) 持久化。name: {{name01.DATA}}amount: {{amount01.DATA}}journey: {{thing01.DATA}}date: {{date01.DATA}}
{"touser": "OPENID","template_id": "TEMPLATE_ID","page": "index","data": {"name01": {"value": "who "},"amount01": {"value": "$100"},"thing01": {"value": "from beijing to shanghai"} ,"date01": {"value": "2018-01-01"}}}




// 定义一个数组变量 jsonDatas,用于存储获取到的数据,初始值为 nilBLOCK_ARRAY jsonDatas = nil;// 调用单例 SubscriptionManager 的 getMessage 方法获取消息数据// 参数:// - token: 获取登录用户 token// - appId: 配置文件(tcmpp-ios-configurations.json或tcmpp-android-configurations.json) 中的appKey// 成功回调:// - message: 获取到的消息数据数组// 失败回调:// - error: 错误信息[SubscriptionManager.sharedInstance getMessage: UserInfo.sharedInstance.tokenappId: MiniAppSDKManager.sharedInstance.configAppKeysuccess:^(ARRAY message) {// 检查 message 是否为数组类型,如果不是则直接返回if (![message isArray]) {return;}// 检查 message 数组是否为空,如果为空则直接返回if ([message isEmpty]) {return;}// 将获取到的消息数据数组赋值给 jsonDatas 变量jsonDatas = message;// 创建一个可变数组 arrayDatas,用于存储解析后的数据模型MUTABLE_ARRAY arrayDatas = [NSMutableArray array];// 遍历 jsonDatas 数组for (DICTIONARY json in jsonDatas) {// 将每个 json 数据解析成 SubscribeInfoModel 模型对象SubscribeInfoModel *model = [[SubscribeInfoModel alloc] initWithJsonDatas: json];// 将模型对象添加到 arrayDatas 数组中[arrayDatas addObject: model];}// 将 arrayDatas 数组赋值给 self.modelDatas 属性self.modelDatas = [NSArray arrayWithArray: arrayDatas];// 在主线程上异步执行 tableView 的 reloadData 方法,刷新表格数据[self.tableView performSelectorOnMainThread: @selector(reloadData)withObject: nilwaitUntilDone: YES];}failure:^(ERROR error) {// 处理获取消息数据失败的情况,这里可根据业务场景进行失败提示}];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{// 获取当前点击卡片对应的订阅模型对象SubscribeInfoModel *model = self.modelDatas[indexPath.row];// 传入订阅模型对象的参数,调用SDK的打开小游戏接口[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:model.MnpId verType:model.vertype scene:0 firstPage:model.Page paramsStr:nil parentVC:self completion:^(NSError * _Nullable error) {if(error) {// 打开失败,可根据业务场景进行提示return;}// 打开成功,可根据业务场景进行提示}];}
文档反馈