php微信模板信息发送的代码例子,微信模板消息发送样例
微信模板消息發(fā)送樣例:
//先構(gòu)建一個http發(fā)送
function http_request($url, $data = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// post數(shù)據(jù)
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的變量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
//然后可以去實現(xiàn)發(fā)送,中間獲取openid的就不寫了 我這里直接給大家展示可以用的,你去修改一些微信公眾號的數(shù)據(jù)就行
//去實現(xiàn)模板發(fā)送吧
public function send(){
echo "測試是否進入方法";
$tpl = array(
//接收者 這里面要用到用戶的openid
"touser"=>"",
//這里是你要發(fā)送的模板類型
"template_id"=>"LikmE1ecqhNMRnqFOBiJdQ9N0FT6ONA_lRiIlRgnZxw",
//這里是點擊模板跳轉(zhuǎn)的頁面
"url" => "www.wdphp.com",
//標(biāo)題顏色
"topcolor" => "#FFAE89",
"data" => array(
//這里的first,keyword 都要對應(yīng)這模板里面的信息寫
"first" => array("value" => "學(xué)生到校通知","color" => "#FF83FA"),
"keyword1" => array("value" => "名字:小陳","color" => "#FF7536"),
"keyword2" => array("value" => "班級信息","color" => "#FF69FA"),
"keyword3" => array("value" => "時間".date('Y-m-d H:i:s'),"color" => "#FF7526"),
//這里是通用的 就類似與備注的存在
"remark" => array("value" => "謝謝您關(guān)注我們的公眾號","color" => "#FF7256"),
),
);
$json_template = json_encode($tpl);
//這里后面的sccse_token 要替換成自己的accse_token
//獲取地址 點擊這個 直接復(fù)制出去替換成自己的 會返回你的sccse_token的
//https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ovmANbdqnWh--fZprl4nrN_d1TCqbo_x_hVzZTSuMPcASg-3sI-p7pZwGKTngytBHNlklBaZ9f5iEfJlXEWDH-IjtcmjkwMkhLN4crPFkEoONEdAFACBS";
$res = json_decode($this->http_request($url,$json_template),true);
if ($res["errcode"] == 0){
echo "成了";
}else{
echo json_encode($res);
}
}
總結(jié)
以上是生活随笔為你收集整理的php微信模板信息发送的代码例子,微信模板消息发送样例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电动车还配谈汽车文化吗?
- 下一篇: 特斯拉Model 3劲敌!蔚来ET5工信