国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php中CURL模擬進行微信接口的GET與POST例子

2024-05-04 21:49:38
字體:
來源:轉載
供稿:網友

php CURL函數可以模仿用戶進行一些操作,如我們可以模仿用戶提交數據也可以模仿用戶進行網站訪問了,下面我們來介紹利用CURL模擬進行微信接口的GET與POST例子,例子非常的簡單就兩個大家一起看看.

Get提交獲取數據

  1. /**  
  2.  * @desc 獲取access_token  
  3.  * @return String access_token  
  4.  */   
  5. function getAccessToken(){   
  6.     $AppId = '1232assad13213123';   
  7.     $AppSecret = '2312312321adss3123213';   
  8.     $getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppId.'&secret='.$AppSecret;   
  9.     $ch = curl_init();   
  10.     curl_setopt($ch, CURLOPT_URL, $getUrl);   
  11.     curl_setopt($ch, CURLOPT_HEADER, 0);   
  12.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
  13.     curl_setopt($ch, CURL_SSLVERSION_SSL, 2);   
  14.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);   
  15.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);   
  16.     $data = curl_exec($ch);   
  17.     $response = json_decode($data);   
  18.     return $response->access_token;   

post提交獲取數據

  1.   /**  
  2.    * @desc 實現天氣內容回復  
  3.    */   
  4. public function testWeixin(){   
  5. $access_token = $this->getAccessToken();   
  6. $customMessageSendUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;   
  7. $description = '今天天氣的詳細信息(從第三方獲取)。';   
  8. $url = 'http://weather.com/';   
  9. $picurl = 'http://weather.com/';   
  10. $postDataArr = array(   
  11. 'touser'=>'OPENID',   
  12. 'msgtype'=>'news',   
  13. 'news'=>array(   
  14.     'articles'=>array(   
  15.   'title'=>'當天天氣',   
  16.   'description'=>$description,   
  17.   'url'=>$url,   
  18.   'picurl'=>$picurl,   
  19.     ),   
  20. ),   
  21. );   //開源軟件:Vevb.com 
  22. $postJosnData = json_encode($postDataArr);   
  23. $ch = curl_init($customMessageSendUrl); 
  24. curl_setopt($ch, CURLOPT_HEADER, 0); 
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  26. curl_setopt($ch, CURLOPT_POST, 1); 
  27. curl_setopt($ch, CURLOPT_POSTFIELDS, $postJosnData);     
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);   
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);   
  30. $data = curl_exec($ch); 
  31. var_dump($data);   

例子相對來說比較簡單也沒有什么好詳細分析的了,大家照抄就可以實現我們想要的功能了.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博罗县| 呼伦贝尔市| 金沙县| 永吉县| 沾益县| 巨鹿县| 漠河县| 临湘市| 桐梓县| 汝阳县| 邵武市| 朝阳区| 邓州市| 黄大仙区| 盐源县| 和顺县| 英山县| 龙里县| 广灵县| 栖霞市| 沙洋县| 金沙县| 米脂县| 天祝| 伊宁县| 盐池县| 西乡县| 舞阳县| 砀山县| 突泉县| 南和县| 繁昌县| 青铜峡市| 石首市| 新竹县| 七台河市| 彭州市| 通州市| 莱州市| 广宗县| 农安县|