日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

微信开发3之php模板信息推送

發(fā)布時間:2025/3/11 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信开发3之php模板信息推送 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

模板信息推送:需要在后臺開通了模板消息推送接口

?

?

PHP代碼如下:

<?php $appid="wxxxxxxxxxxxxxxxxxx"; //填寫微信后臺的appid $appsecret="xxxxxxxxxxxxxxxxxxxxxxxxx"; //填寫微信后臺的appsecret $TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret; $json=file_get_contents($TOKEN_URL); $result=json_decode($json,true); $ACCESS_TOKEN=$result['access_token']; #獲取ACCESS_TOKEN,在expire_time字段可以看到過期時間,7200=兩個小時,以秒為單位 $times=date("Y-m-d H:i:s",time()); $name='test';//標(biāo)題 $zu='test1';//正文 //測試機賬號 $openid='oxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $template=array( 'touser'=>$openid, 'template_id'=>"xxxxxxxxxxxxxxxxxxxxxxxxxxx", //模板的id 'url'=>"http://weixin.qq.com/download", 'topcolor'=>"#FF0000", 'data'=>array( 'test'=>array('value'=>urlencode($name),'color'=>"#00008B"), //函數(shù)傳參過來的name 'test1'=>array('value'=>urlencode($zu),'color'=>'#00008B'), //函數(shù)傳參過來的zu ) ); $json_template=json_encode($template); $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$ACCESS_TOKEN; $ch = curl_init(); $data=urldecode($json_template); 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); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); $arr = json_decode($output, true); echo $arr['errcode']; ?>

訪問php文件網(wǎng)址,則得到:

任何程序錯誤,以及技術(shù)疑問或需要解答的,請掃碼添加作者VX

?

總結(jié)

以上是生活随笔為你收集整理的微信开发3之php模板信息推送的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。