# Mini Program Subscription Messages (Users Subscribe via Popup) Development Guide

# Instructions

# Step 1: Get the template ID

Manually configure the template on WeChat Official Platform ID:
log in https://mp.weixin.qq.com Get the template, if there is no suitable template, you can apply to add a new template, after approval can be used.

intro

# Step 2: Get Permission

One-time subscription messages and long-term subscription messages, see Interface wx.requestSubscribeMessage

Device subscription messages, see Interface wx.requestSubscribeDeviceMessage

# Step 3: Call the interface to issue a subscription message

One-time subscription messages and long-term subscription messages, see Server Side Interface subscribeMessage.send, the number of restrictions: the opening of the ability to pay small procedures issued by the upper limit is 3kw/The first day was 1kw./Day.

Device subscription messages, see Server Side Interface hardwareDevice.send

# Note

  • User Check "Always keep the above options open and never ask again" After that, the next subscription calls wx.requestSubscribeMessage Will not pop up, keep the previous selection, modify the selection need to open the Mini Program settings to modify.

# Subscribe Message Event Push

1, when the user triggers the subscription message pop-up box, the user's relevant behavioral event results will be pushed to the server address configured by the developer or[WeChat cloud hosting](https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun /src/Guide/Weixin/push.html)Services.

# XML Format Examples

<xml>
    <ToUser ><![CDATA[gh_123456789abc ]]></ToUser >
    <FromUserName><![CDATA[otFpruAK8D-E6EfStSYonYSBZ8_4]]></FromUserName>
    <CreateTime>1610969440</CreateTime>
    <MsgType ><![CDATA[event]]></MsgType >
    <Event><![CDATA[subscribe_msg_popup_event]]></Event>
    <SubscribeMsgPopupEvent>
        <List>
            <TemplateId><![CDATA[VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc ]]></TemplateId>
            <SubscribeStatusString><![CDATA[accept]]></SubscribeStatusString>
            <PopupScene>2</PopupScene>
        </List>
        <List>
            <TemplateId><![CDATA[9nLIlbOQZC5Y89AZteFEux3WCXRRRG5Wfzkpssu4bLI]]></TemplateId>
            <SubscribeStatusString><![CDATA[reject]]></SubscribeStatusString>
            <PopupScene>2</PopupScene>
        </List>
    </SubscribeMsgPopupEvent>
</xml>

# JSON Sample Format

{
  "ToUserName":  "gh_123456789abc, 
  "FromUserName": "o7esq5OI1Uej6Xixw1lA2H7XDVbc",
  "CreateTime": "1620973045",
  "MsgType": "event",
  "Event": "subscribe_msg_popup_event",
  "List": [   {
        "TemplateId": hD-ixGOhYmUfjOnI8MCzQMPshzGVeux _2vzyvQu7O68",
        "SubscribeStatusString": "accept",
        "PopupScene": "0"
    }],
 }

if "List" Only one object, then only the object itself is returnedif "List" More than one object, an array containing all the objects is returned.

# Dxplaination of parameters

parameter Introductions
ToUser Mini Program account ID
FromUserName User openid
CreateTime timestamp
TemplateId Template id (there may be more than one id for a single subscription)
SubscribeStatusString Subscribe results (accept receiveReject
PopupScene Frame scene, 0 is in the Mini Program page

2, when the user in the mobile phone service notification message card in the upper right corner of... "" management messages, the corresponding behavioral events will be pushed to the developer configured server address or[WeChat cloud hosting](https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun /src/Guide/Weixin/push.html)Services. (Currently only push unsubscribed events, i.e. set "reject" for messages)

# XML Sample Format

<xml>
    <ToUser ><![CDATA[gh_123456789abc ]]></ToUser >
    <FromUserName><![CDATA[otFpruAK8D-E6EfStSYonYSBZ8_4]]></FromUserName>
    <CreateTime>1610969440</CreateTime>
    <MsgType ><![CDATA[event]]></MsgType >
    <Event><![CDATA[subscribe_msg_Change_event]]></Event>
    <SubscribeMsgChangeEvent>
        <List>          <TemplateId><![CDATA[VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc ]]></TemplateId>
            <SubscribeStatusString><![CDATA[reject]]></SubscribeStatusString>
        </List>
    </SubscribeMsgChangeEvent>
</xml>

# JSON Sample Format

{
      "ToUserName":  "gh_123456789abc, 
      "FromUserName": "o7esq5OI1Uej6Xixw1lA2H7XDVbc",
      "CreateTime": "1610968440",
      "MsgType": "event",
      "Event": "subscribe_msg_Change_event",
      "List": [  {
                "TemplateId":"BEwX0BOT3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8",
                "SubscribeStatusString": "reject"
      }],
}

if "List" Only one object, then only the object itself is returnedif "List" More than one object, an array containing all the objects is returned.

# Dxplaination of parameters

parameter Introductions
ToUser Mini Program account ID
FromUserName User openid
CreateTime timestamp
TemplateId Template id (there may be more than one id for a single subscription)
SubscribeStatusString Result of subscription (reject)

3, call the subscription message interface to send a message to the end result of the user, will push the result event to the server address configured by the developer or[WeChat cloud hosting](https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun /src/Guide/Weixin/push.html)Services.

# XML Format Examples

<xml>
    <ToUser ><![CDATA[gh_123456789abc ]]></ToUser >
    <FromUserName><![CDATA[otFpruAK8D-E6EfStSYonYSBZ8_4]]></FromUserName>
    <CreateTime>1610969468</CreateTime>
    <MsgType ><![CDATA[event]]></MsgType >
    <Event><![CDATA[subscribe_msg_sent_event]]></Event>
    <SubscribeMsgSentEvent>
        <List>       <TemplateId><![CDATA[VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc ]]></TemplateId>
            <MsgID>1700827132819554304</MsgID>
            <ErrorCode>0</ErrorCode>
            <ErrorStatus ><![CDATA[success]]></ErrorStatus >
        </List>
    </SubscribeMsgSentEvent>
</xml>

# JSON Sample Format

{
    "ToUserName":  "gh_123456789abc, 
    "FromUserName": "o7esq5PHRGBQYmeNyfG064wEFVpQ",
    "CreateTime": "1620963428",
    "MsgType": "event",
    "Event": "subscribe_msg_sent_event",
    "List": {
        "TemplateId": "BEwX0BO-T3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8",
        "MsgID": "1864323726461255680",
        "ErrorCode": "0",
        "ErrorStatus":  "success"
      }
      
}

# Dxplaination of parameters

parameter Introductions
ToUser Mini Program account ID
FromUserName User openid
CreateTime timestamp
TemplateId Template id (there may be more than one id for a single subscription)
MsgID Message id (also returned when calling the interface)
ErrorCode Push result status code (0 means success)
ErrorStatus The meaning of the status code corresponding to the push result

Note: Failures include only system failures due to asynchronous push

# Subscribe to Message Voice Alerts

From the base library 2.18.0 Start support

At present, the prompt sound of the Mini Program subscription message notification is the same as that of the WeChat message notification, and for some subscription message templates, the voice reminder capability is added, and some fields of the broadcast corpus can be defined by developers.

When the developer callswx.requestSubscribeMessageWhen subscribing only 1 message and the template supports opening voice reminder, users can choose to open voice reminder when subscribing. When enabled, voice alerts will be broadcast synchronously when receiving subscription messages.

When the user turns on the voice alert, the developer uses thewx.getSettingThe subscription status of the template obtained is' acceptWithAudio '.

The subscription pop-up style is as follows:

intro

The current template and broadcast corpus supporting voice reminder are as follows:

title type category Broadcast corpus
Receipt notice Long term subscription Financial Services - Banking, Finance - Acquiring Merchant Services The Mini Program example receives 10 yuan, where the "Mini Program example" will be broadcast as the Mini Program abbreviation of the Mini Program issued, and 10 will be broadcast as the amount of the collection in the template.

The following conditions will prevent voice alerts from being broadcast:

  1. Users set service notifications to be Do Not Disturb
  2. The user has turned on the phone silent mode or the phone volume is too low
  3. Users do not open WeChat new message notification, can guide users to WeChat - "I" - "Settings" - "New Message Notification" to open
  4. The user does not open the system notification to WeChat
  5. User turns on low power mode
  6. User version is too low: iOS is required 8.0.6 with Android 8.0.3 and above

# Subscribe to a message Add a reminder

From the base library 2.22.0 Start support

Users subscribe to Mini programsLong Term Subscription MessagesYou can add reminders based on your usage. After the addition, users will be notified by a banner in WeChat when they receive a message.

When the user adds a reminder, the developer uses thewx.getSettingThe subscription status of the template obtained is' acceptWithAlert '.

The subscription pop-up style is as follows:

intro