May 19, 2021 WeChat Mini Program Development Document
4. 2. Get a template library under the title of a template keyword library
5. 3. Combine templates and add them to the personal template library under your account
7. 4. Get a list of templates that already exist under your account
8. 5. Delete a template under your account
10.. 2. Send a template message
11.. Issue a description of the conditions
13.. Description of the violation
Based on WeChat's notification channels, we provide developers with template messaging capabilities that can efficiently reach users in order to implement a closed loop of services and provide a better experience.
Template push location: Service notifications
Template release conditions: the user himself in the WeChat system and the page after interactive behavior triggered, see the release conditions description
Template Jump Capability: Click to see the details and only jump to the individual pages of the account that you can post the template
Step 1: Get the template ID
There are two ways to get a template ID
Sign in https://mp.weixin.qq.com get a template, if you don't have the right template, you can request to add a new template, you can use it after the approval, see the template review instructions
Step 2: The
<form/>
the
report-submit
true
can be declared as a template message to be sent, at which
point clicking
the button to
formId
which
is used to send the template message. O
r, when the user completes
the payment
behavior, they can
get
prepay_id
to send a
template message.
Step 3: Call the interface to issue template messages (see Send template message )
interface address
https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
parameter | Required | illustrate |
---|---|---|
access_token | Yes | Interface call credential |
offset | Is | Offset and count are used for pedding, indicating that starting with offset, pulling count records, offset starting from 0, counting up to 20. |
count | Is | Offset and count are used for pedding, indicating that starting with offset, pulling count records, offset starting from 0, counting up to 20. |
Example:
{
"offset":0,
"count":5
}
Return code description:
After the template message interface is called, the JSON packet is returned.
Example of returning JSON packets in normal time:
{
"errcode":0,
"errmsg":"ok",
"list":[
{"id":"AT0002","title":"购买成功通知"},
{"id":"AT0003","title":"购买失败通知"},
{"id":"AT0004","title":"交易提醒"},
{"id":"AT0005","title":"付款成功通知"},
{"id":"AT0006","title":"付款失败通知"}
],
"total_count":599
}
Return the parameter description:
Parameters | Description |
---|---|
Id | Template title id (required to get the keyword library under the template title) |
title | The content of the template title |
total_count | The total number of template library titles |
The interface address
https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=ACCESS_TOKEN
HTTP request:
POST
POST parameter description:
Parameters | Required | Description |
---|---|---|
access_token | Is | The interface calls the credentials |
Id | Is | Template title id, can be obtained through the interface, can also log in to the small program background view to get |
Example:
{
"id":"AT0002"
}
Return code description:
After the template message interface is called, the JSON packet is returned.
Example of returning JSON packets in normal time:
{
"errcode": 0,
"errmsg": "ok",
"id": "AT0002",
"title": "购买成功通知",
"keyword_list": [
{
"keyword_id": 3,
"name": "购买地点",
"example": "TIT造舰厂"
},
{
"keyword_id": 4,
"name": "购买时间",
"example": "2016年6月6日"
},
{
"keyword_id": 5,
"name": "物品名称",
"example": "咖啡"
}
]
}
Return the parameter description:
Parameters | Description |
---|---|
keyword_id | Keyword id, when adding templates |
name | Keywords content |
example | An example of a keyword content |
The interface address
https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN
HTTP request:
POST
POST parameter description:
Parameters | Required | Description |
---|---|---|
access_token | Is | The interface calls the credentials |
Id | Is | Template title id, can be obtained through the interface, can also log in to the small program background view to get |
keyword_id_list | Is | Developers combine their own list of template keywords, the order of keywords can be freely matched (e.g., 3, 5, 4, or 4, 5, 3), support up to 10 keyword combinations |
{
"id":"AT0002",
"keyword_id_list":[3,4,5]
}
Return code description:
After the template message interface is called, the JSON packet is returned.
Example of returning JSON packets in normal time:
{
"errcode": 0,
"errmsg": "ok",
"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}
Return the parameter description:
Parameters | Description |
---|---|
template_id | Add to the template id under your account, as needed to send a small program template message |
The interface address
https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
HTTP request:
POST
POST parameter description:
Parameters | Required | Description |
---|---|---|
access_token | Is | The interface calls the credentials |
offset | Is | Offset and count are used for pedding, indicating that starting with offset, pulling count records, offset starting from 0, counting up to 20. The list length of the last page may be less than the requested count |
count | Is | Offset and count are used for pedding, indicating that starting with offset, pulling count records, offset starting from 0, counting up to 20. The list length of the last page may be less than the requested count |
Example:
{
"offset":0,
"count":1
}
Return code description:
After the template message interface is called, the JSON packet is returned.
Example of returning JSON packets in normal time:
{
"errcode": 0,
"errmsg": "ok",
"list": [
{
"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc",
"title": "购买成功通知",
"content": "购买地点{{keyword1.DATA}}\n购买时间{{keyword2.DATA}}\n物品名称{{keyword3.DATA}}\n",
"example": "购买地点:TIT造舰厂\n购买时间:2016年6月6日\n物品名称:咖啡\n"
}
]
}
Return the parameter description:
Parameters | Description |
---|---|
list | A list of templates under your account |
template_id | Add to the template id under your account, as needed to send a small program template message |
title | The template title |
content | The content of the template |
example | Example of template content |
The interface address
https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=ACCESS_TOKEN
HTTP request:
POST
POST parameter description:
Parameters | Required | Description |
---|---|---|
access_token | Is | The interface calls the credentials |
template_id | Is | The template id to delete |
Example:
{
"template_id":"wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}
Return code description:
After the template message interface is called, the JSON packet is returned.
Example of returning JSON packets in normal time:
{
"errcode": 0,
"errmsg": "ok"
}
access_token is the global unique interface call credentials, developers call each interface need to use the access_token, please save it. a ccess_token store at least 512 characters of space. access_token is currently valid for 2 hours and needs to be refreshed on a timed period, and repeated acquisition will invalidate the last access_token acquired.
Description of how the API calls to the public access_token and how they are generated:
Developers can use AppID and AppSecret to call this interface to get access_token. A ppID and AppSecret can be obtained by logging on to WeChat's public platform official website-settings-development settings (requires that the developer has been bound and that the account has no abnormal status). S ave your appSecret after it's built, because each build view on the public platform causes the appSecret to be reset. N ote that the https protocol is required when calling all WeChat interfaces. If a third party does not use a central server and instead selects each business logic point to refresh the access_token, a conflict can arise that can lead to service instability.
Interface address:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
HTTP request:
GET
Description of the parameters:
Parameters | Required | Description |
---|---|---|
grant_type | Is | Get access_token fill client_credential |
appid | Is | Unique credentials for third-party users |
secret | Is | The third-party user's unique credential key, appsecret |
Return the parameter description:
Normally, WeChat returns the following JSON packets to the developer:
{"access_token":"ACCESS_TOKEN","expires_in":7200}
Parameters | Description |
---|---|
access_token | The credentials obtained |
expires_in | Voucher valid time, in seconds |
WeChat returns information such as error codes in the event of an error, and an example of a JSON packet is as follows (this example is an appID invalid error):
{"errcode":40013,"errmsg":"invalid appid"}
Interface address: (ACCESS_TOKEN need to be replaced with the information obtained access_token)
https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN
HTTP request:
POST
POST parameter description:
Parameters | Required | Description |
---|---|---|
touser | Is | The openid of the recipient (user). |
template_id | Is | The id of the template message that needs to be sent |
page | Whether | Click on the template to see the details jump page, do not fill in the template no jump |
form_id | Is | Form submission scenario, formId on the submit event, payment scenario, for this payment prepay_id |
value | Is | Template content, do not fill in the next empty template |
color | Whether | The color of the template content font, not the default black |
emphasis_keyword | Whether | The template needs to zoom in on the keywords, and if you don't fill in, you don't zoom in by default |
Example:
{
"touser": "OPENID",
"template_id": "TEMPLATE_ID",
"page": "index",
"form_id": "FORMID",
"data": {
"keyword1": {
"value": "339208499",
"color": "#173177"
},
"keyword2": {
"value": "2015年01月05日 12:30",
"color": "#173177"
},
"keyword3": {
"value": "粤海喜来登酒店",
"color": "#173177"
} ,
"keyword4": {
"value": "广州市天河区天河路208号",
"color": "#173177"
}
},
"emphasis_keyword": "keyword1.DATA"
}
Return code description:
After the template message interface is called, the JSON packet is returned.
Example of returning JSON packets in normal time:
{
"errcode":0,
"errmsg":"ok",
}
The error code message is returned when the error occurs, as follows:
Return code | Description |
---|---|
40037 | template_id is incorrect |
41028 | form_id is incorrect or out of date |
41029 | form_id is already in use |
41030 | The page is incorrect |
45009 | Interface calls exceed the limit (currently the default daily call limit for each account is 1 million) |
Effects:
Pay
When the user has completed the payment behavior in the small program, the developer can be allowed to push a limited number of template messages to the user within 7 days (1 payment can be issued 3, multiple payments issued independently, without affecting each other)
Submit the form
When a user has submitted a form behavior within a small program and the form is declared to send a template message, the developer needs to provide services to the user, the developer can be allowed to push a limited number of template messages to the user within 7 days (1 submission form can be issued 1, multiple submissions issued separately, each other does not affect)
1.1 The title cannot exist the same
1.2 The title meaning cannot be overly similar
1.3 The title must end with "Reminder" or "Notification"
1.4 Titles cannot be with special symbols, personalized words, etc. without industry commonality
1.5 The title must reflect the specific service scenario
1.6 Titles cannot relate to marketing-related content, including, but not limited to:
Consumer coupons, shopping rebates, product updates, coupons, vouchers, red envelopes, membership cards, points, activities and other marketing trends notice
2.1 Under the same heading, keywords cannot exist in the same way
2.2 Under the same heading, keywords cannot be overly similar
2.3 Keywords can not be with special symbols, personalized words and other content without industry versatility
2.4 The keyword content example must match the keyword
2.5 Keywords cannot be too broad and need to be restrictive, for example: "content" is too broad to be approved
In addition to not violating operational practices, the following rules cannot be violated, including but not limited to:
The corresponding gradient of penalties is given in the light of violations, and the general penalty rules are as follows:
For the first time, remove the violation template as a warning,
The second violation, blocking the interface for 7 days,
The third violation, blocking the interface for 30 days,
Fourth violation, permanently blocking the interface
The result and reason of the punishment are communicated in the form of an in-station letter
tip
WeChat 6.5.2 and above support template functionality.
Below this version, you will not receive a template message.