課程
/后端開發(fā)
/PHP
/PHP微信公眾平臺(tái)開發(fā)高級(jí)篇—模板消息接口
從第一講進(jìn)入第二講,有一個(gè)代碼實(shí)現(xiàn)部份,怎么過(guò)渡到代碼實(shí)現(xiàn)?
2019-06-24
源自:PHP微信公眾平臺(tái)開發(fā)高級(jí)篇—模板消息接口 1-2
正在回答
????public?function?pushWxMsg(){????????//1.獲取到access_token????????$access_token?=?'獲取到access_token';????????$url?=?"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="?.?$access_token;????????$array?=?array(????????????'touser'?=>?"用戶openid",?//用戶openid????????????'template_id'?=>?"在公眾號(hào)下配置的模板id",?//在公眾號(hào)下配置的模板id????????????'url'?=>?"http://idcbgp.cn/course/qa/id/618/t/0?page=1",?//點(diǎn)擊模板消息會(huì)跳轉(zhuǎn)的鏈接????????????'data'?=>?array(????????????????'first'?=>?array('value'?=>?"兼職平臺(tái)簽到測(cè)試開始",?'color'?=>?"#FF0000"),????????????????'keyword1'?=>?array('value'?=>?'兼職崗位小區(qū)門口賣西瓜',?'color'?=>?'#FF0000'),?//keyword需要與配置的模板消息對(duì)應(yīng)????????????????'keyword2'?=>?array('value'?=>?time(),?'color'?=>?'#FF0000'),?//keyword需要與配置的模板消息對(duì)應(yīng)????????????????'remark'?=>?array('value'?=>?"兼職平臺(tái)簽到測(cè)試結(jié)束,收到請(qǐng)釘釘回復(fù)一下",?'color'?=>?"#FF0000"),????????????),????????);????????$json_template?=?json_encode($array);????????//?$res?=?$this->http_curl($url,?'post',?'json',?$json_template);????????$res?=?$this->curl_post($url,?$json_template);????????dump($res);????}????/**?????*?@param?$url?????*?@param?array?$data?????*?@return?mixed?????*?curl請(qǐng)求?????*/????function?curl_post($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;????}
????public?function?pushWxMsg(){
????????//1.獲取到access_token
????????$access_token?=?'獲取到access_token';
????????$url?=?"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="?.?$access_token;
????????$array?=?array(
????????????'touser'?=>?"用戶openid",?//用戶openid
????????????'template_id'?=>?"在公眾號(hào)下配置的模板id",?//在公眾號(hào)下配置的模板id
????????????'url'?=>?"http://idcbgp.cn/course/qa/id/618/t/0?page=1",?//點(diǎn)擊模板消息會(huì)跳轉(zhuǎn)的鏈接
????????????'data'?=>?array(
????????????????'first'?=>?array('value'?=>?"兼職平臺(tái)簽到測(cè)試開始",?'color'?=>?"#FF0000"),
????????????????'keyword1'?=>?array('value'?=>?'兼職崗位小區(qū)門口賣西瓜',?'color'?=>?'#FF0000'),?//keyword需要與配置的模板消息對(duì)應(yīng)
????????????????'keyword2'?=>?array('value'?=>?time(),?'color'?=>?'#FF0000'),?//keyword需要與配置的模板消息對(duì)應(yīng)
????????????????'remark'?=>?array('value'?=>?"兼職平臺(tái)簽到測(cè)試結(jié)束,收到請(qǐng)釘釘回復(fù)一下",?'color'?=>?"#FF0000"),
????????????),
????????);
????????$json_template?=?json_encode($array);
????????//?$res?=?$this->http_curl($url,?'post',?'json',?$json_template);
????????$res?=?$this->curl_post($url,?$json_template);
????????dump($res);
????}
????/**
?????*?@param?$url
?????*?@param?array?$data
?????*?@return?mixed
?????*?curl請(qǐng)求
?????*/
????function?curl_post($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;
舉報(bào)
模板消息,快到碗里來(lái),可以應(yīng)用于刷卡通知,商品購(gòu)買成功通知
1 回答發(fā)送模板消息的代碼運(yùn)行后,怎么頁(yè)面顯示是空白的?
1 回答怎么群發(fā)模板消息啊
2 回答出現(xiàn)小問(wèn)題
2 回答Call to undefined function getWxAccessToken 這個(gè)問(wèn)題怎么解決??
1 回答我的公眾號(hào)怎么沒有新增模板呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-07-30