accept", it indicates that the user has agreed to subscribe to the template message corresponding to the template ID, and the template is available.
Page({// 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})}})},})
orderSubscribe shown in the above example. The mini program backend must persist the successfully subscribed templates, subscription times, and subscribers (openid). After the subscription action is completed, sending the message is usually a future action. The mini program backend should provide a platform for message dispatch or use other middleware or APIs to trigger message sending.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"}}}




// Define an array variable jsonDatas, used to store the acquired data, the initial value is nilBLOCK_ARRAY jsonDatas = nil;// Call getMessage method of the singleton SubscriptionManager to retrieve message data// Parameters:// - token: The token of the logged-in user// - appId: The appKey from the configuration file (tcmpp-ios-configurations.json or tcmpp-android-configurations.json)// Successful callback:// - message: The array of retrieved message data// Failed callback:// - error: Error information[SubscriptionManager.sharedInstance getMessage: UserInfo.sharedInstance.tokenappId: MiniAppSDKManager.sharedInstance.configAppKeysuccess:^(ARRAY message) {// Check if message is an array; if not, return immediatelyif (![message isArray]) {return;}// Check if the message array is empty; if so, return immediatelyif ([message isEmpty]) {return;}// Assign the retrieved message data array to the jsonDatas variablejsonDatas = message;// Create a mutable array arrayDatas to store the parsed data modelsMUTABLE_ARRAY arrayDatas = [NSMutableArray array];// Iterate over the jsonDatas arrayfor (DICTIONARY json in jsonDatas) {// Parse each json data into a SubscribeInfoModel objectSubscribeInfoModel *model = [[SubscribeInfoModel alloc] initWithJsonDatas: json];// Add the model object to the arrayDatas array[arrayDatas addObject: model];}// Assign the arrayDatas array to the self.modelDatas propertyself.modelDatas = [NSArray arrayWithArray: arrayDatas];// Asynchronously execute the tableView's reloadData method on the main thread to refresh the table data[self.tableView performSelectorOnMainThread: @selector(reloadData)withObject: nilwaitUntilDone: YES];}failure:^(ERROR error) {// Handle the failure to retrieve message data, providing failure prompts based on the business scenario}];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{// Get the subscription model object corresponding to the tapped cardSubscribeInfoModel *model = self.modelDatas[indexPath.row];// Pass the parameters of the subscription model object and call the SDK's method to open the mini program[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:model.MnpId verType:model.vertype scene:0 firstPage:model.Page paramsStr:nil parentVC:self completion:^(NSError * _Nullable error) {if(error) {// If opening fails, provide a prompt based on the business scenarioreturn;}// If opening succeeds, provide a prompt based on the business scenario}];}
Feedback