Template message interface



1474854871571022.jpg


##Template message interface

Template messages are only used by official accounts to send important service notifications to users, and can only be used in service scenarios that meet their requirements. , such as credit card swipe notifications, product purchase success notifications, etc. Marketing messages such as advertisements and all other messages that may cause harassment to users are not supported.

Regarding usage rules, please note:

1、所有服务号都可以在功能->添加功能插件处看到申请模板消息功能的入口,但只有认证后的服务号才可以申请模板消息的使用权限并获得该权限;
2、需要选择公众账号服务所处的2个行业,每月可更改1次所选行业;
3、在所选择行业的模板库中选用已有的模板进行调用;
4、每个账号可以同时使用25个模板。
5、当前每个账号的模板消息的日调用上限为10万次,单个模板没有特殊限制。【2014年11月18日将接口调用频率从默认的日1万次提升为日10万次,可在MP登录后的开发者中心查看】。当账号粉丝数超过10W/100W/1000W时,模板消息的日调用上限会相应提升,以公众号MP后台开发者中心页面中标明的数字为准。

Regarding interface documentation, please note:

1、模板消息调用时主要需要模板ID和模板中各参数的赋值内容;
2、模板中参数内容必须以".DATA"结尾,否则视为保留字;
3、模板保留符号"{{ }}"。


Set the industry

Setting the industry can be completed in MP. The industry can be modified once a month. The account can only use templates related to the industry to which it belongs. To facilitate third-party developers, a method of modifying the industry to which the account belongs is provided through interface calling. The details are as follows:

Interface call request description

http请求方式: POST
https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN

POST data description

POST data examples are as follows:

      {
          "industry_id1":"1",
          "industry_id2":"4"
       }

Parameter description

ParameterIs it required?Description
access_tokenYes Interface call credentials

industry_id1

is The industry number to which the public account template message belongs
industry_id2 is The public account template message Industry number

Industry Code Query

##IT TechnologyIT Software and Services2IT TechnologyIT Hardware and Equipment3IT TechnologyElectronic Technology 4##IT TechnologyIT TechnologyFinancial Industry##Financial IndustryInsurance9CateringCatering10Hotel Travelhotel11hotel tourismtourism12##Transportation And warehousingTransportation and warehousingTransportation and Warehousing##EducationTraining 16Institutions Academic Scientific ResearchTraffic Police## Medical NursingNursing and Beauty23Medical NursingHealth and Hygiene24TransportationCar related25##TransportationTransportationTransportationReal EstateReal Estate##文体娱乐Entertainment and leisure39PrintingPrinting40##Others##

Get the set industry information

Get the account settings industry information. Industry information can be viewed on the MP official website. For the convenience of third-party developers, the industry information set by the account is obtained through interface calling. The details are as follows:

Interface call request instructions

http请求方式:GET
https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=ACCESS_TOKEN

Parameter description

Main IndustrySecondary IndustryCode
IT TechnologyInternet /E-commerce1
Communications and Operators5
Online Games6
Bank7
Financial IndustryFund|Financial Management|Trust8
Express13
Logistics14
Warehouse15
##Education
17Government and Public Utilities
18Government and Public Utilities
19
Government and Public UtilitiesMuseum20
Government and Public UtilitiesPublic Utilities|Non- Profitable organization21
Medical and NursingMedical and Medical22
Motorcycle related26
Train related27
Aircraft related28
Architecture29
Property30
Consumer GoodsConsumer Goods31
Business ServicesLegal32
Business ServiceConvention and Exhibition33
Business ServiceIntermediary Service34
Business ServicesCertification35
Business ServicesAudit36
Cultural and Sports EntertainmentMedia37
体育娱乐体育38
Others 41
ParameterIs it requiredDescription
access_tokenYesInterface call credentials

Return description

Return example after correct call:

{
"primary_industry":{"first_class":"运输与仓储","second_class":"快递"},
"secondary_industry":{"first_class":"IT科技","second_class":"互联网|电子商务"}
}

Return parameter description

##secondary_industry isSub-business industry for account setting

Get the template ID

Select from the industry template library The template goes to the account backend, and the process of obtaining the template ID can be completed in MP. For the convenience of third-party developers, we provide a way to obtain the template ID through interface calling, as follows:

Interface call request description

http请求方式: POST
https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN

POST data description

POST data examples are as follows:

      {
           "template_id_short":"TM00015"
       }

Parameter description

Parameter Is it required?Description
access_token is interface calling credential
primary_industry is the main industry of account settings
ParameterIs it requiredDescription
access_tokenYesInterface call credentials
template_id_short is the number of the template in the template library, including "TM**" and "OPENTMTM* *" and other forms

Return code description

After calling the template message interface, a JSON data packet will be returned. Example of returning JSON data packet when normal:

    {
           "errcode":0,
           "errmsg":"ok",
           "template_id":"Doclyl5uP7Aciu-qZ7mJNPtWkbkYnWBWVja26EGbNyk"
       }

##Get template list

Obtain the list of all templates that have been added to the account. You can view the template list information in MP. For the convenience of third-party developers, we provide a way to obtain all template information under the account through interface calls, as follows :

Interface call request description

http请求方式:GET
https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN

Parameter description

ParameterIs it requiredDescription
access_tokenYesInterface call credentials

Return description

Return example after correct call:

{	
 "template_list": [{
      "template_id": "iPk5sOIt5X_flOVKn5GrTFpncEYTojx6ddbt8WYoV5s",
      "title": "领取奖金提醒",
      "primary_industry": "IT科技",
      "deputy_industry": "互联网|电子商务",
      "content": "{ {result.DATA} }\n\n领奖金额:{ {withdrawMoney.DATA} }\n领奖  时间:{ {withdrawTime.DATA} }\n银行信息:{ {cardInfo.DATA} }\n到账时间:  { {arrivedTime.DATA} }\n{ {remark.DATA} }",
      "example": "您已提交领奖申请\n\n领奖金额:xxxx元\n领奖时间:2013-10-10 12:22:22\n银行信息:xx银行(尾号xxxx)\n到账时间:预计xxxxxxx\n\n预计将于xxxx到达您的银行卡"
   }]
}

Return parameter description

#contentexample

##Delete template

Delete template can be done in MP Completed. To facilitate third-party developers, we provide a way to delete templates under an account through interface calls. The details are as follows:

Interface call request instructions

http请求方式:POST
https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN

POST The data description is as follows:

 {
     "template_id" : "Dyvp3-Ff0cnail_CDSzk1fIc6-9lOkxsQE7exTJbwUE"
 }

Parameter description

ParameterIs it required?Description
access_token is the interface call credential
template_id is template ID
title is the template title
primary_industry is the industry to which the template belongs The first-level industry
deputy_industry is the second-level industry
istemplate content
istemplate example
ParameterIs it requiredDescription
access_tokenYesInterface call credentials
template_id is template message ID under the public account

Return instructions

After calling the interface, a JSON data packet will be returned. Example of returned JSON data packet when normal:

{
   "errcode" : 0,
   "errmsg" : "ok"
}

##Send template message

Interface call request description

http请求方式: POST
https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN

POST data description

POST data examples are as follows:

      {
           "touser":"OPENID",
           "template_id":"ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY",
           "url":"http://weixin.qq.com/download",            
           "data":{
                   "first": {
                       "value":"恭喜你购买成功!",
                       "color":"#173177"
                   },
                   "keynote1":{
                       "value":"巧克力",
                       "color":"#173177"
                   },
                   "keynote2": {
                       "value":"39.8元",
                       "color":"#173177"
                   },
                   "keynote3": {
                       "value":"2014年9月22日",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"欢迎再次购买!",
                       "color":"#173177"
                   }
           }
       }

Parameter Description

ParameterIs it required?Description
touserYesReceiver openid
template_id is template ID
urlNoTemplate jump link
dataYesTemplate data


Return code description

After calling the template message interface, a JSON data packet will be returned. Example of returned JSON data packet when normal:

    {
           "errcode":0,
           "errmsg":"ok",
           "msgid":200228332
       }

##Event push

After the template message sending task is completed, the WeChat server will notify whether the delivery is successful and send it to the server configuration address filled in the Developer Center.

1. When the delivery is successful, the pushed XML is as follows:

           <xml>
           <ToUserName><![CDATA[gh_7f083739789a]]></ToUserName>
           <FromUserName><![CDATA[oia2TjuEGTNoeX76QEjQNrcURxG8]]></FromUserName>
           <CreateTime>1395658920</CreateTime>
           <MsgType><![CDATA[event]]></MsgType>
           <Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
           <MsgID>200163836</MsgID>
           <Status><![CDATA[success]]></Status>
           </xml>

Parameter description

ParametersDescription
ToUserNamePublic Account WeChat ID
FromUserNameThe openid of the user who received the template message
CreateTimeCreation time
MsgTypeThe message type is event
EventThe event is the end of template message sending
MsgIDMessage id
StatusThe sending status is successful

2. When the delivery fails due to user rejection (user settings refuse to receive public account messages), the pushed XML is as follows:

           <xml>
           <ToUserName><![CDATA[gh_7f083739789a]]></ToUserName>
           <FromUserName><![CDATA[oia2TjuEGTNoeX76QEjQNrcURxG8]]></FromUserName>
           <CreateTime>1395658984</CreateTime>
           <MsgType><![CDATA[event]]></MsgType>
           <Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
           <MsgID>200163840</MsgID>
           <Status><![CDATA[failed:user block]]></Status>
           </xml>

Parameter Description

##ToUserNamePublic Account WeChat IDFromUserNameThe openid of the user who receives the template messageCreateTimeCreation timeMsgType The message type is eventEventThe event is template message sending endMsgIDMessage id StatusThe sending status is that the user refuses to receive

3. When delivery fails due to other reasons, the pushed XML is as follows:

           <xml>
           <ToUserName><![CDATA[gh_7f083739789a]]></ToUserName>
           <FromUserName><![CDATA[oia2TjuEGTNoeX76QEjQNrcURxG8]]></FromUserName>
           <CreateTime>1395658984</CreateTime>
           <MsgType><![CDATA[event]]></MsgType>
           <Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
           <MsgID>200163840</MsgID>
           <Status><![CDATA[failed: system failed]]></Status>
           </xml>

Parameter description

ParameterDescription
Parameter description
ToUserNamePublic account WeChat account
FromUserNameThe openid of the user who receives the template message
CreateTimeCreate Time
MsgTypeThe message type is event
EventThe event is the end of template message sending
MsgIDMessage id
StatusThe sending status is failed to send (non-user rejected)


##