微信公眾號之模板的群發
阿新 • • 發佈:2019-01-31
眾所周知,微信服務號的推送是有限制的,自從微信開放模板推送,那麼我們也可以借用模板達到推送的結果,切記不可亂用,造成封號的損失概不負責
我這裡只寫測試模板的傳送,還有傳送模板是所需要的資料,我相信大家都能解決的,若無法解決,可在下方平論
<?php
include "wechat.php";
$weObj=new Wechat();
for($i=0;$i<$count;$i++) {
$ars=$weObj->setcs_msg("使用者的唯一標示","模板的id",“跳轉的地址”,"標題,"內容"," 時間");
}
?>
wechat.php 原始碼
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------至於如何獲取accesstoken,這裡應該不用我贅述,另外如何獲取使用者建立的模板,這個應該也不贅述,如有需要,在下方評論,我將更詳細的寫出來!*/
public function setcs_msg($openid,$temp_id,$url,$title,$content,$time){
//獲取access_token
//下面是要填充模板的資訊
$formwork = '{
"touser":"'.$openid.'",
"template_id":"'.$temp_id.'",
"url":"'.$url.'",
"data":{
"title": {
"value":"' .$title.'",
"color":"#173177"
},
"content":{
"value":"'.$content.'",
"color":"#173177"
},
"time": {
"value":"'.$time.'",
"color":"#173177"
}
}
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}
?>
還有一點既然是測試模板,那麼大家可以在測試公眾號裡面測試 一下,最起碼程式碼時刻性的,我本人就在用這段程式碼!如果覺得不夠詳細,請在下發那個評論,我看到後,會再給大家寫一份更加詳細的傳送模板的程式碼,及解釋