Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat program API subscribes to messages


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.requestSubscribeMessage(Object object)

Base Library 2.4.4 starts to support, and low versions need to be compatible.

Call up the client program subscription message interface and return the results of the user's subscription message. When the user ticks "Always keep the above selection, don't ask again" in the subscription panel, the template message is added to the user's small program settings page, and the user's subscription status to the relevant template message is obtained through the wx.getSetting interface.

Precautions

  • The one-time template id and the permanent template id cannot be used at the same time.
  • The low-version base library 2.4.4 to 2.8.3 already supports subscription message interface calls and only one-time tmplId / permanent tmplId.
  • 2.8.2 The subscription message interface can only be recalled after the user has clicked or initiated a payment callback since the release began.
  • Starting with version 2.10.0, the development and experience applets will prohibit the use of the template message formId.

Parameters

Object object

Property Type The default Required Description
tmplIds Array Is A collection of ids that require a subscription to a message template that can subscribe to up to 3 messages at a time (Note: iOS client version 7.0.6, android client 7.0.7 version after one-time subscription/long-term subscription only supports multiple template messages, i Only one template message is supported for a subscription prior to OS Client 7.0.5, Android Client 7.0.6, and the message template id is configured in the WeChat Public Platform (mp.weixin.qq.com) - Feature - Subscription Message
success function no Interface call successful callback function
fail function no Interface call failed callback function
complete function no The callback function ended in the interface call (the call is successful, failed)

Object.success callback function

parameter
Object res
Attributes type illustrate
errMsg String The Errmsg value is 'RequestSubscribeMessage: OK' when the interface call is successful.
TEMPLATE_ID String The TEMPLATE_ID is the dynamic key, the template id, and the values include 'accept', 'reject', 'ban'. ' accept' means that the user agrees to subscribe to the template message for the id, 'reject' means that the user refuses to subscribe to the template message for the id, and 'ban' means that it has been blocked in the background. For example, "requestSubscribeMessage:ok," zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept") means that the user agrees to subscribe to zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE message

object.fail callback function

Parameters
Object res
Property Type Description
errMsg String The interface call failed with an error message
errCode Number The interface call failed the error code

Error code

errCode errMsg Description
10001 TmplIds can't be empty The argument is empty
10002 Request list fail Network problem, request message list failed
10003 Request subscribe fail Network problem, subscription request failed to send
10004 Invalid template id The argument type is wrong
10005 Cannot show subscribe message UI The UI cannot be displayed, and is generally caused by the small program going back to the background at this time
20001 No template data return, verify the template id exist Without template data, it is generally caused by the absence of a template ID or a non-correspondence with the template type
20002 Templates type must be same Template message types are both one-time and permanent
20003 Templates count out of max bounds The number of template messages exceeds the upper limit
20004 The main switch is switched off The user turned off the main switch and could not subscribe
20005 This mini program was banned from subscribing messages Small programs are banned

The sample code

wx.requestSubscribeMessage({
  tmplIds: [''],
  success (res) { }
})