模板消息说明
模板消息用于公众号向用户发送重要的服务通知等。
必要条件
已认证的微信公众号。
实现步骤
1、登录微信公众号如果左侧没有模板消息按钮点击添加功能按钮添加模板消息。
2、点击“从模板库中添加”按钮选择合适的模板并添加(如果没有合适的点击“帮我们完善模板库”提交自己的模板)。
3、开发消息发送功能
使用$gracewechat->templateMsg($msg);函数发送消息
参数:模板消息数据
示例代码
<?php
class wxController extends grace{
public function index(){
//......
}
public function sendMsg(){
$gracewechat = tool('graceWeChat');
$msg = '{
"touser":"op15jsy7D14d8BAvDTTLTdumuz_I",
"template_id":"HPdb1gj1omKqj6ITUNtP85OeAs01wh0pQc5-QZutums",
"url":"http://www.phpgrace.com",
"topcolor":"#FF0000",
"data":{
"first": {
"value":"您的快递已经领取",
"color":"#173177"
},
"keyword1":{
"value":"'.mt_rand(111111, 999999).'",
"color":"#173177"
},
"keyword2": {
"value":"2017-07-07",
"color":"#173177"
},
"remark":{
"value":"如不是本人操作请联系客服",
"color":"#173177"
}
}
}';
$res = $gracewechat->templateMsg($msg);
echo $res;
}
}