May 20, 2021 WeChat Mini Program Development Document
This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0
Send a subscription message
How to call:
POST https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN
Property | Type | The default | Required | Description |
---|---|---|---|---|
access_token | string | Is | The interface calls the credentials | |
touser | string | Is | The openid of the recipient (user). | |
template_id | string | Is | The subscription template id that you want to issue | |
page | string | Whether | Click the jump page after the template card, only the page within this small program. S upport with parameters, (example index?foo=bar). If the field is not filled in, the template does not jump. | |
data | Object | Is | The contents of the template, in the form of a "key1": "value": any, "key2": "value": any . . . | |
miniprogram_state | string | Whether | Jump small program types: developer for development, trial for experience, formal for the official version, default to the official version | |
Lang | string | Whether | Go to the small program to see the language type, which supports zh_CN (Chinese Simplified), en_US (English), zh_HK (Chinese Traditional), zh_TW (Chinese Traditional), which is zh_CN |
The returned JSON packet
Property | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | string | The error message |
The legal value of errcode
Value | Description | The lowest version |
---|---|---|
40003 | The touser field openid is empty or incorrect | |
40037 | The subscription template id is empty incorrectly | |
43101 | The user refuses to accept the message, and if the user has previously subscribed, the user cancels the subscription relationship | |
47003 | The template parameters are inaccurate, may be empty, or do not meet the rules, and errmsg will indicate which field is wrong | |
41030 | The page path is incorrect and needs to be guaranteed to exist in the current version of the applet, consistent with app.json |
Number of times limit: open payment capacity is 3kw / day, not open is 1kw / day.
{
"touser": "OPENID",
"template_id": "TEMPLATE_ID",
"page": "index",
"miniprogram_state":"developer",
"lang":"zh_CN",
"data": {
"number01": {
"value": "339208499"
},
"date01": {
"value": "2015年01月05日"
},
"site01": {
"value": "TIT创意园"
} ,
"site02": {
"value": "广州市新港中路397号"
}
}
}
The parameter category | Description of the parameters | The parameter value limit | Description |
---|---|---|---|
thing. DATA | Things | 20 characters or less | Can be combined with Chinese characters, numbers, letters, or symbols |
number. DATA | Digital | Numbers up to 32 digits | Only numbers can be taken with a small number |
letter. DATA | Letters | Letters up to 32 bits | Only letters are 1 |
symbol. DATA | Symbol | Within 5 bits of the symbol | Only symbols are signed |
character_string. DATA | String | A number, letter, or symbol within 32 digits | Can be combined with numbers, letters, or symbols |
time. DATA | Time | The 24-hour time format (supports the date of year and month), supports filling in the time period, and connects between the two points in time with the "-" symbol | For example: 15:01, or: October 1, 2019 at 15:01 |
date. DATA | Date | The year-to-day format (supports a 24-hour clock time), supports filling in time periods, and connects between two points in time with the "-" symbol | For example: October 1, 2019, or October 1, 2019 at 15:01 |
amount. DATA | Amount | 1 currency symbol plus 10 digits or less pure number, can be with a small number, the end can be with a "yuan" | Can be taken with a small number |
phone_number. DATA | Phone | Within 17 digits, numbers, symbols | Phone number, e.g. : 86-0766-66888866 |
car_number. DATA | License plate | Within 8 digits, the first and last digits can be Chinese characters, and the rest are letters or numbers | License plate number: Guangdong A8Z888 hanging |
name. DATA | Name | 10 or less pure Chinese characters or 20 or less pure letters or symbols | Chinese 10 chinese characters; 20 letters in pure English; Chinese and letters are mixed into Chinese characters, within 10 words |
phrase. DATA | Chinese characters | 5 chinese characters or less | 5 or less pure Chinese characters, e.g. in distribution |
Symbols represent common Chinese, English, and numbers, and cannot have control characters such as line breaks. T he time format supports HH:MM:SS or HH:MM. D ates include the date of the year, which is y year m month d day, y year m month, m month d day format, or with '-,','/,'.'" S ymbolic connections such as 2018-01-01, 2018/01/01, 2018.01.01, 2018-01,01-01. E ach template parameter is prefixed with a type, for example, the first number template parameter is number01. D ATA, the second is number02. DATA
For example, the content of the template is
姓名: {{name01.DATA}}
金额: {{amount01.DATA}}
行程: {{thing01.DATA}}
日期: {{date01.DATA}}
The corresponding johnson is
{
"touser": "OPENID",
"template_id": "TEMPLATE_ID",
"page": "index",
"data": {
"name01": {
"value": "某某"
},
"amount01": {
"value": "¥100"
},
"thing01": {
"value": "广州至北京"
} ,
"date01": {
"value": "2018-01-01"
}
}
}
Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.
openapi.subscribeMessage.send
The permissions for the subscribeMessage.send API need to be configured in config.json, details
Property | Type | The default | Required | Description |
---|---|---|---|---|
touser | string | Is | The openid of the recipient (user). | |
templateId | string | Is | The subscription template id that you want to issue | |
page | string | Whether | Click the jump page after the template card, only the page within this small program. S upport with parameters, (example index?foo=bar). If the field is not filled in, the template does not jump. | |
data | Object | Is | The contents of the template, in the form of a "key1": "value": any, "key2": "value": any . . . | |
miniprogramState | string | Whether | Jump small program types: developer for development, trial for experience, formal for the official version, default to the official version | |
Lang | string | Whether | Go to the small program to see the language type, which supports zh_CN (Chinese Simplified), en_US (English), zh_HK (Chinese Traditional), zh_TW (Chinese Traditional), which is zh_CN |
The returned JSON packet
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|---|---|
0 | Success |
The exception thrown
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|---|---|
40003 | The touser field openid is empty or incorrect | |
40037 | The subscription template id is empty incorrectly | |
43101 | The user refuses to accept the message, and if the user has previously subscribed, the user cancels the subscription relationship | |
47003 | The template parameters are inaccurate, may be empty, or do not meet the rules, and errmsg will indicate which field is wrong | |
41030 | The page path is incorrect and needs to be guaranteed to exist in the current version of the applet, consistent with app.json |
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.subscribeMessage.send({
touser: 'OPENID',
page: 'index',
lang: 'zh_CN',
data: {
number01: {
value: '339208499'
},
date01: {
value: '2015年01月05日'
},
site01: {
value: 'TIT创意园'
},
site02: {
value: '广州市新港中路397号'
}
},
templateId: 'TEMPLATE_ID',
miniprogramState: 'developer'
})
return result
} catch (err) {
return err
}
}