Github完整源码:https://github.com/xiaoming000/wechat.git
官方文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
正常的模板消息使用步骤是选择所处的行业(可选择2个),然后申请模板(同时最多25个);
但是我们用的测试账号,所以直接在测试账号中按要求设置模板消息,然后进行模板消息发送!
<?php
require "public.php";
class Templates{
// http请求方式: POST
// https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
public function send_template($openid, $name){
$arr = array(
"touser"=>$openid,
"template_id"=>"7D5ybniJpsoxq8NXi-09MWPm7qhNBrCYhyoIXrMiPts",
"url"=>"http://weixin.qq.com/download",
"data"=>array(
'name'=>array('value'=>$name, 'color'=>"#173177")
)
);
$fun = new PublicFunction();
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$fun->getWxAccessToken();
$res = $fun -> http_curl($url, 'post', 'json', json_encode($arr));
var_dump($res);
}
}
$temp = new Templates();
$openid = "oyfLo1Uh9dhVXb6uEYkYM1bmdqt0";
$name = "xiaoxiaoming";
$temp -> send_template($openid, $name);
// 这里关注的模板消息回复只需要的index.php的被关注事件中调用这个函数就可以!