模板消息僅用於公衆號向用戶發送重要的服務通知,只能用於符合其要求的服務場景中,如信用卡刷卡通知,商品購買成功通知等。不支持廣告等營銷類消息以及其它全部可能對用戶形成騷擾的消息。javascript
<?php @header('Content-type: text/plain;charset=UTF-8'); require_once("../Utils.php"); $data = '{ "industry_id1":"1", "industry_id2":"4" }'; $url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?" ."access_token=".Utils::get_access_token(); $result = Utils::https_request($url, $data); echo $result;返回:
{"errcode":0,"errmsg":"ok"}
<?php @header('Content-type: text/plain;charset=UTF-8'); require_once("../Utils.php"); $url = "https://api.weixin.qq.com/cgi-bin/template/get_industry?" ."access_token=".Utils::get_access_token(); $result = Utils::https_request($url); echo $result;返回:
{ "primary_industry": { "first_class": "IT科技", "second_class": "互聯網|電子商務" }, "secondary_industry": { "first_class": "IT科技", "second_class": "電子技術" } }
<?php @header('Content-type: text/plain;charset=UTF-8'); require_once("../Utils.php"); $data = '{ "template_id_short":"TM00015" }'; $url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?" ."access_token=".Utils::get_access_token(); $result = Utils::https_request($url, $data); echo $result;返回:
{ "errcode": 0, "errmsg": "ok", "template_id": "V4Gx8O_WixAGUIkYwjm2EuWBbq-L-wz8KUJzhMoUJXk" }
@header('Content-type: text/plain;charset=UTF-8'); require_once("../Utils.php"); $url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?" ."access_token=".Utils::get_access_token(); $result = Utils::https_request($url); echo $result;返回:
{ "template_list": [ { "template_id": "V4Gx8O_WixAGUIkYwjm2EuWBbq-L-wz8KUJzhMoUJXk", "title": "訂單支付成功", "primary_industry": "IT科技", "deputy_industry": "互聯網|電子商務", "content": "{{first.DATA}}\n\n支付金額:{{orderMoneySum.DATA}}\n商品信息:{{orderProductName.DATA}}\n{{Remark.DATA}}", "example": "咱們已收到您的貨款,開始爲您打包商品,請耐心等待: )\n支付金額:30.00元\n商品信息:我是商品名字\n\n若有問題請致電400-828-1878或直接在微信留言,小易將第一時間爲您服務!" } ] }
<?php @header('Content-type: text/plain;charset=UTF-8'); require_once("../Utils.php"); $data = '{ "template_id" : "Dyvp3-Ff0cnail_CDSzk1fIc6-9lOkxsQE7exTJbwUE" }'; $url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?" ."access_token=".Utils::get_access_token(); $result = Utils::https_request($url, $data); echo $result;返回:
{ "errcode" : 0, "errmsg" : "ok" }
<?php @header('Content-type: text/plain;charset=UTF-8'); require_once("../Utils.php"); $data = '{ "touser": "o4WmZ0h-4huBUVQUczx2ezaxIL9c", "template_id": "V4Gx8O_WixAGUIkYwjm2EuWBbq-L-wz8KUJzhMoUJXk", "url": "http://www.baidu.com", "data": { "first": { "value": "咱們已收到您的貨款,開始爲您打包商品,請耐心等待:", "color": "#173177" }, "orderMoneySum": { "value": "30.00元", "color": "#173177" }, "orderProductName": { "value": "洗髮水", "color": "#173177" }, "Remark": { "value": "若有問題請致電400-828-1878或直接在微信留言,小易將第一時間爲您服務!", "color": "#173177" } } }'; $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?" ."access_token=".Utils::get_access_token(); $result = Utils::https_request($url, $data); echo $result;返回:
{"errcode":0,"errmsg":"ok","msgid":414862553}
<xml> <ToUserName> <![CDATA[gh_6b9aa8a6f1e2]]> </ToUserName> <FromUserName> <![CDATA[o4WmZ0h-4huBUVQUczx2ezaxIL9c]]> </FromUserName> <CreateTime>1505407812</CreateTime> <MsgType> <![CDATA[event]]> </MsgType> <Event> <![CDATA[TEMPLATESENDJOBFINISH]]> </Event> <MsgID>414862553</MsgID> <Status> <![CDATA[success]]> </Status> </xml>送達因爲用戶拒收(用戶設置拒絕接收公衆號消息)而失敗時,推送的XML以下:
<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>送達因爲其餘緣由失敗時,推送的XML以下:
<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>