In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "WeChat Mini Programs API template message so use", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "WeChat Mini Programs API template message so use"!
instructions
Step 1: get the template ID
There are two ways to get a template ID
Obtain template ID through template message management API (see template message management for details)
Manually configure to obtain template ID on Wechat public platform
Log in to https://mp.weixin.qq.com to obtain the template. If you do not have a suitable template, you can apply to add a new template. You can use it after approval. For more information, please see the template audit instructions.
Step 2: the component of the page. When the attribute report-submit is true, you can declare that you need to send a template message. Click the button to submit the form to get the formId, which is used to send the template message. Or when the user completes the payment behavior, you can get the prepay_id to send the template message.
Step 3: call the API to send template messages
Template message Management 1. Get the title list of Mini Program template Library
Interface address
Https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
The required parameter indicates that access_token is the API call credential offset is used for paging by offset and count, which means that starting from offset, count records are pulled. Offset starts from 0, and the maximum count is 20. Count is used for paging by offset and count, which means that count records are pulled from offset. Offset starts from 0, and the maximum count is 20.
Example:
{"offset": 0, "count": 5}
Error code description:
After invoking the template message interface, a JSON packet is returned.
Example of returning JSON packets under normal conditions:
{"errcode": 0, "errmsg": "ok", "list": [{"id": "AT0002", "title": "purchase success Notification"}, {"id": "AT0003", "title": "purchase failure Notification"}, {"id": "AT0004", "title": "transaction reminder", {"id": "AT0005", "title": "payment success Notification"}, {"id": "AT0006" "title": "payment failure Notification"}], "total_count": 599}
Return parameter description:
Parameter description id template title id (required to obtain the keyword library under the template title) title template title content total_count template library total title 2. Get the keyword library under the title of a template library
Interface address
Https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
The required parameter indicates that access_token is the API call credential id is the template title id, which can be obtained through the API, or you can log in to Mini Program backend to view it.
Example:
{"id": "AT0002"}
Error code description:
After invoking the template message interface, a JSON packet is returned.
Example of returning JSON packets under normal conditions:
{"errcode": 0, "errmsg": "ok", "id": "AT0002", "title": "notice of success of purchase", "keyword_list": [{"keyword_id": 3, "name": "place of purchase", "example": "TIT shipyard"}, {"keyword_id": 4, "name": "purchase time", "example": "June 6, 2016"} {"keyword_id": 5, "name": "item name", "example": "Coffee"]}
Return parameter description:
Parameter description keyword_id keyword id, adding template requires name keyword content example keyword content corresponding to example 3. Combine the templates and add them to the personal template library under the account
Interface address
Https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
The required parameters indicate that access_token is the API call credential id is the template title id, which can be obtained through the API. You can also log in to the Mini Program backend to view and obtain the template keyword list composed by the developer. The keyword order can be matched freely (for example, [3meme 5meme 4] or [4meme 5meme 3]). A maximum of 10 keyword combinations are supported for example: {"id": "AT0002", "keyword_id_list": [3mem4mem5]}
Error code description:
After invoking the template message interface, a JSON packet is returned.
Example of returning JSON packets under normal conditions:
{"errcode": 0, "errmsg": "ok", "template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"}
Return parameter description:
Parameters indicate that template_id is added to the template id under the account, and 4. 5% is required to send Mini Program template messages. Get the list of templates that already exist under the account
Interface address
Https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
The required parameter indicates that access_token is the API call credential offset is used for paging by offset and count, which means that starting from offset, count records are pulled. Offset starts from 0, and the maximum count is 20. The list length of the last page may be less than the requested countcount. Offset and count are used for paging, which means that starting from offset, count records are pulled. Offset starts from 0, and the maximum count is 20. The list length of the last page may be less than the requested count
Example:
{"offset": 0, "count": 1}
Error code description:
After invoking the template message interface, a JSON packet is returned.
Example of returning JSON packets under normal conditions:
{"errcode": 0, "errmsg": "ok", "list": [{"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc", "title": "notice of success of purchase", "content": "place of purchase {{keyword1.DATA}}\ npurchase time {{keyword2.DATA}}\ nitem name {{keyword3.DATA}}\ n" "example": "place of purchase: TIT shipyard\ npurchase time: June 6, 2016\ nitem name: coffee\ n"]}
Return parameter description:
Parameters indicate that the template list under the list account template_id is added to the template id under the account, and the required title template title content template content example template content example 5. Delete a template under the account
Interface address
Https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
Required parameter indicates that access_token is the API call credential template_id is the template id to be deleted
Example:
{"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"}
Error code description:
After invoking the template message interface, a JSON packet is returned.
Example of returning JSON packets under normal conditions:
{"errcode": 0, "errmsg": "ok"} send template message 1. Get access_token
Access_token is the only credential for calling APIs globally. Developers need to use access_token when calling each API. Please save it properly. At least 512 character space should be reserved for access_token storage. The access_token is valid for 2 hours and needs to be refreshed regularly. Repeated acquisition will invalidate the last acquired access_token.
Description of the use and generation of access_token required for API calls on the public platform:
In order to keep appsecrect secret, a third party needs a central control server that is acquired and refreshed by access_token. However, the access_token used by other business logic servers comes from the central control server and should not be refreshed separately, otherwise it will cause access_token coverage and affect the business.
Currently, the validity period of access_token is communicated through the returned expire_in, which is currently within 7200 seconds. The central control server needs to refresh the new access_token in advance according to this effective time. In the refresh process, the output of the central control server is still the old access _ token. At this time, the public platform backend will ensure that both the new and old access_token are available within a short period of time, which ensures a smooth transition of third-party business.
The validity period of access_token may be adjusted in the future, so the central control server not only needs to refresh actively internally, but also needs to provide an interface to passively refresh access_token, so that when the API call learns that access_token has timed out, the business server can trigger the refresh process of access_token.
Developers can use AppID and AppSecret to call this API to obtain access_token. AppID and AppSecret can be obtained from the official website of Wechat Public platform-Settings-Development Settings (you need to be bound as a developer and the account has no abnormal status). Please save the AppSecret after it is generated, because each time you generate a view on the public platform, the AppSecret will be reset. Note that https protocol is required when calling all Wechat APIs. If the third party does not use the central control server, but chooses each business logic point to refresh the access_token, then there may be conflicts, resulting in service instability.
Interface address:
Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
HTTP request method:
GET
Parameter description:
The required parameter indicates that grant_type is used to obtain access_token. Enter client_credentialappid as the only credential for third-party users. Secret is the unique credential key for third-party users, that is, appsecret.
Return parameter description:
Normally, Wechat returns the following JSON packets to developers:
{"access_token": "ACCESS_TOKEN", "expires_in": 7200} parameters indicate the validity period of the expires_in credential obtained by access_token (in seconds)
Wechat will return information such as error code when an error occurs. An example of JSON packet is as follows (this example is an invalid AppID error):
{"errcode": 40013, "errmsg": "invalid appid"} 2. Send template message
API address: (ACCESS_TOKEN needs to be replaced with the access_token obtained above)
Https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN
HTTP request method:
POST
POST parameter description:
Parameter required indicates that touser is the recipient (user) openidtemplate_id is the idpage of the template message to be sent No Click on the template to view the details jump page, if left empty, the template without jump form_id is the formId brought to the submit event in the form submission scenario In the payment scenario, the prepay_idvalue paid for this time is the template content. If you leave it empty, send the blank template color No template font color, leave the default black emphasis_keyword No template keywords that need to be enlarged, and leave it empty or no magnification by default.
Example:
{"touser": "OPENID", "template_id": "TEMPLATE_ID", "page": "index", "form_id": "FORMID", "data": {"keyword1": {"value": "339208499", "color": "# 173177"} "keyword2": {"value": "12:30, January 05, 2015", "color": "# 173177"}, "keyword3": {"value": "Sheraton Guangdong Hotel", "color": "# 173177"} "keyword4": {"value": "208Tianhe Road, Tianhe District, Guangzhou", "color": "# 173177"}}, "emphasis_keyword": "keyword1.DATA"}
Error code description:
After invoking the template message interface, a JSON packet is returned.
Example of returning JSON packets under normal conditions:
{"errcode": 0, "errmsg": "ok",}
Error code information is returned when an error occurs, which is described as follows:
The return code indicates that the 40037template_id is incorrect, the 41028form_id is incorrect, or the expired 41029form_id has been used 41030page incorrect API 45009 to call more than the limit (currently, the default limit for each account is 1 million per day).
Pay for
When users have completed payment in Mini Program, developers can be allowed to push a limited number of template messages to users within 7 days (3 messages can be sent for one payment, and the number of messages sent for multiple payments is independent of each other)
Submit the form
When a user has submitted a form in Mini Program and the form is declared to send a template message, the developer needs to provide services to the user. Developers are allowed to push a limited number of template messages to users within 7 days (one can be sent after one submission, and the number of multiple submissions is independent of each other).
Audit description 1. Title
1.1 the title cannot be the same.
1.2 there should be no excessive similarity in the meaning of the title.
1.3 the title must end with "reminder" or "notice"
1.4 the title cannot carry special symbols, personalized words and other contents that are not universal to the industry.
1.5 the title must reflect the specific service scenario
1.6 the title shall not involve marketing-related content, including not limited to:
Notice of marketing tendencies such as consumer discounts, shopping rebates, commodity updates, coupons, vouchers, red envelopes, membership cards, credits, activities, etc.
two。 Keywords
2.1 keywords cannot be the same under the same title
2.2 under the same title, keywords cannot be overly similar.
2.3 keywords cannot carry special symbols, personalized words and other content that have no industry versatility.
2.4 keyword content examples must match keywords
2.5 keywords should not be too broad and need to be restrictive, for example, "content" is too broad to be approved.
Violation description
In addition to operating rules that cannot be violated, the following rules cannot be violated, including but not limited to:
It is not allowed to maliciously induce users to carry out trigger operations, so as to achieve the purpose of sending templates to users.
Malicious harassment is not allowed. Send templates that cause harassment to users.
Malicious marketing is not allowed, and the marketing purpose template is issued.
Punishment statement
A corresponding gradient of punishment shall be given according to the violation, and the general rules of punishment are as follows:
For the first violation, delete the violation template as a warning
The second violation, blocking the interface for 7 days.
For the third time, the interface was blocked for 30 days.
The fourth violation, permanently blocking the interface.
The result and reason of the punishment will be informed in the form of internal letter.
Bug & Tip
Tip: template function is supported in Wechat 6.5.2 and above. Template messages will not be received below this version.
Thank you for your reading, the above is the content of "WeChat Mini Programs API template message so used". After the study of this article, I believe you have a deeper understanding of the use of WeChat Mini Programs API template message in this way, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.