課程
/后端開發(fā)
/PHP
/PHP微信公眾平臺開發(fā)高級篇—群發(fā)接口
中文顯示成了ASCII,怎么回事啊
2017-10-05
源自:PHP微信公眾平臺開發(fā)高級篇—群發(fā)接口 1-3
正在回答
我的http_curl函數(shù)參數(shù)順序和老師的有點不一樣。
protected function http_curl($url, $arr = '', $type = 'get', $res = 'json')??? {??????? $ch = curl_init();??????? curl_setopt($ch, CURLOPT_URL, $url);??????? curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);??????? if ($type == 'post') {??????????? curl_setopt($ch, CURLOPT_POST, 1);??????????? curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);??????? }??????? $output = curl_exec($ch);??????? if ($res == 'json') {??????????? if ($err = curl_errno($ch)) {??????????????? //要在關(guān)閉之前獲得curl_errno??????????????? curl_close($ch);??????????????? return $err;??????????? } else {??????????????? return json_decode($output, true);??????????? }??????? }??? }
這個問題很簡單,你不需要完全按照視頻的來。
//2.組裝群發(fā)接口數(shù)據(jù)array??????? // 下列數(shù)組用于測試打印json格式群發(fā)消息??????? /*??????? {??????? "touser":"OPENID",??????? "mpnews":{??????? "media_id":"123dsdajkasd231jhksad"??????? },??????? "msgtype":"mpnews"??????? }???????? */??????? // $arr=array(??????? //???? 'touser'=>'oW_5b1Tmhp6kpzuuffe9a1AFn7cE',??????? //???? 'text'=>array('content'=>'歡迎關(guān)注,有事沒事常聯(lián)系。'),??????? //???? 'msgtype'=>'text'??????? // );??????? // //3.將array->轉(zhuǎn)json??????? // $postJson=json_encode($arr);??????? $postJson = '{??????????? "touser":"oW_5b1Tmhp6kpzuuffe9a1AFn7cE",??????????? "text":{"content":"歡迎關(guān)注,有事沒事常聯(lián)系。"},??????????? "msgtype":"text"??????? }';??????? //4.調(diào)用curl??????? $res = $this->http_curl($url, $postJson, 'post');
$postJson只需要是json就可以,里面的字符可以是中文的。
舉報
不群發(fā),無微信,通過本教程學習實現(xiàn)更靈活的群發(fā)能力
1 回答老師能說下根據(jù) media_id 在視圖頁面中顯示圖片嗎?
1 回答視1-3視頻最后一個media_id 顯示不合法,老師的也輸出不回來,老師是怎么測試成功de 呢
2 回答提示40152錯誤怎么辦
1 回答每天向關(guān)注用戶自動群發(fā)圖文消息
1 回答返回了錯誤碼40003
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-05-08
我的http_curl函數(shù)參數(shù)順序和老師的有點不一樣。
protected function http_curl($url, $arr = '', $type = 'get', $res = 'json')
??? {
??????? $ch = curl_init();
??????? curl_setopt($ch, CURLOPT_URL, $url);
??????? curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
??????? if ($type == 'post') {
??????????? curl_setopt($ch, CURLOPT_POST, 1);
??????????? curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
??????? }
??????? $output = curl_exec($ch);
??????? if ($res == 'json') {
??????????? if ($err = curl_errno($ch)) {
??????????????? //要在關(guān)閉之前獲得curl_errno
??????????????? curl_close($ch);
??????????????? return $err;
??????????? } else {
??????????????? return json_decode($output, true);
??????????? }
??????? }
??? }
2018-05-08
這個問題很簡單,你不需要完全按照視頻的來。
//2.組裝群發(fā)接口數(shù)據(jù)array
??????? // 下列數(shù)組用于測試打印json格式群發(fā)消息
??????? /*
??????? {
??????? "touser":"OPENID",
??????? "mpnews":{
??????? "media_id":"123dsdajkasd231jhksad"
??????? },
??????? "msgtype":"mpnews"
??????? }
???????? */
??????? // $arr=array(
??????? //???? 'touser'=>'oW_5b1Tmhp6kpzuuffe9a1AFn7cE',
??????? //???? 'text'=>array('content'=>'歡迎關(guān)注,有事沒事常聯(lián)系。'),
??????? //???? 'msgtype'=>'text'
??????? // );
??????? // //3.將array->轉(zhuǎn)json
??????? // $postJson=json_encode($arr);
??????? $postJson = '{
??????????? "touser":"oW_5b1Tmhp6kpzuuffe9a1AFn7cE",
??????????? "text":{"content":"歡迎關(guān)注,有事沒事常聯(lián)系。"},
??????????? "msgtype":"text"
??????? }';
??????? //4.調(diào)用curl
??????? $res = $this->http_curl($url, $postJson, 'post');
$postJson只需要是json就可以,里面的字符可以是中文的。