PHP微信开发之模板消息回复

参考:http://www.jb51.net/article/87269.htm

代码:

<?php
//$ac = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx4e45725489bf95a6&secret=ebdb0802ccb233aec7f744646db895a5');
//$wxt = json_decode($ac,true); $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=Ka4dA44aDm2P94j4aWaD24PRdD7HADAd';//access_token改成你的有效值 $data = array(
'first' => array(
'value' => '您报考的龙门杯比赛有最新消息',
'color' => '#FF0000'
),
'keyword1' => array(
'value' => '三年级一班',
'color' => '#FF0000'
),
'keyword2' => array(
'value' => '商丘第一高级中学',
'color' => '#FF0000'
),
'keyword3' => array(
'value' => '2018/04/04 15:00~14:45',
'color' => '#FF0000'
),
'keyword4' => array(
'value' => '首先恭喜您通过了我们龙门杯的初选,通知您于18年4月20日来商丘教育局南院(商丘市神火大道86号)2楼会议室进行考试。如有疑问,请拨打电话13526859585 13596852458。',
'color' => '#FF0000'
),
'remark' => array(
'value' => '请您务必准时到场!',
'color' => '#FF0000'
)
);
$template_msg=array('touser'=>'oQJHg1MiLXLuk57BPYEds7QNCS28','template_id'=>'EHUHkPfa2_iJrlDCMDn7SNkGcyHu7BwwsdurOnQgy_Y',"url"=>"http://www.sqess.com/",'topcolor'=>'#FF0000','data'=>$data); $curl = curl_init($url);
$header = array();
$header[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
// 不输出header头信息
curl_setopt($curl, CURLOPT_HEADER, 0);
// 伪装浏览器
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
// 保存到字符串而不是输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($curl, CURLOPT_POST, 1);
// 请求数据
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($template_msg));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
exit;

完毕。

上一篇:第 3 章 镜像 - 020 - 搭建本地 Registry


下一篇:DragQueryFile