网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網(wǎng)

小程序生成帶參數(shù)二維碼(PHP)

發(fā)布時間:2017-12-01 15:14 所屬欄目:小程序開發(fā)教程

官方獲取小程序頁面API 由于小程序參數(shù)二維碼API提供的幫助有限,以下是我對該功能的一些理解 我主要是通過thinkphp后臺接口實現(xiàn),代碼如下: 1、先獲取ACCESS_TOKEN: 純文本查看 復制代碼$tokenUrl=https: ...

 
 
 

官方獲取小程序頁面API 
QQ圖片20170217192918.png

由于小程序參數(shù)二維碼API提供的幫助有限,以下是我對該功能的一些理解

我主要是通過thinkphp后臺接口實現(xiàn),代碼如下: 
1、先獲取ACCESS_TOKEN:

 

		
  1. $tokenUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->secret;
  2.  
  3. $getArr=array();
  4.  
  5. $tokenArr=json_decode($this->send_post($tokenUrl,$getArr,"GET"));
  6.  
  7.  
  8.  
  9. $access_token=$tokenArr->access_token;

send_post:

 

		
  1. function send_post($url, $post_data,$method='POST') {
  2.  
  3. $postdata = http_build_query($post_data);
  4.  
  5. $options = array(
  6.  
  7. 'http' => array(
  8.  
  9. 'method' => $method, //or GET
  10.  
  11. 'header' => 'Content-type:application/x-www-form-urlencoded',
  12.  
  13. 'content' => $postdata,
  14.  
  15. 'timeout' => 15 * 60 // 超時時間(單位:s)
  16.  
  17. )
  18.  
  19. );
  20.  
  21. $context = stream_context_create($options);
  22.  
  23. $result = file_get_contents($url, false, $context);
  24.  
  25.  
  26.  
  27.  
  28.  
  29. return $result;
  30.  
  31. }

2、生成二維碼:

 

		
  1. $path="pages/index?query=1";
  2.  
  3. $width=430;
  4.  
  5. $post_data='{"path":"'.$path.'","width":'.$width.'}';
  6.  
  7.  
  8.  
  9. $url="https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=".$access_token;
  10.  
  11.  
  12.  
  13.  
  14.  
  15. $result=$this->api_notice_increment($url,$post_data);

api_notice_increment:

 

		
  1. function api_notice_increment($url, $data){
  2.  
  3. $ch = curl_init();
  4.  
  5. $header = "Accept-Charset: utf-8";
  6.  
  7. curl_setopt($ch, CURLOPT_URL, $url);
  8.  
  9. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  10.  
  11. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  12.  
  13. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  14.  
  15. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  16.  
  17. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  18.  
  19. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  20.  
  21. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  22.  
  23. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  24.  
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26.  
  27. $tmpInfo = curl_exec($ch);
  28.  
  29. // var_dump($tmpInfo);
  30.  
  31. // exit;
  32.  
  33. if (curl_errno($ch)) {
  34.  
  35. return false;
  36.  
  37. }else{
  38.  
  39. // var_dump($tmpInfo);
  40.  
  41. return $tmpInfo;
  42.  
  43. }
  44.  
  45. }

3、根據(jù)返回的二進制數(shù)據(jù)生成圖片并上傳到自己的服務器

主要代碼:

 

		
  1. file_put_contents($filepath, $result)

我的是上傳到阿里云服務器、就不貼上傳部分的代碼了



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/18002.html 復制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×