<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ``` //生成二維碼 ????public?function?poster(){ ????????$path?=?$_REQUEST['path'];????//跳轉路徑 $pid?=?intval($_REQUEST['pid']);//參數 $scene?=?$pid; ????????$this->getAccessToken(); ????????$result?=?$this->getXcxCode($scene,$path); if(!$result){ echo?json_encode(array('status'=>0,'err'=>'生成失敗!')); exit(); } $info?=?array( ???? ????'code'=>__DATAURL__.'UploadFiles/code/'.$result ); echo?json_encode(array('status'=>1,'info'=>$info)); exit(); } ????//獲取token緩存起來 ????public?function?getAccessToken(){ ????????$appId?=?C('weixin.appid');//小程序appid ????????$secret?=?C('weixin.secret');//小程序secret ????????//創建請求數據 ????????$url_token="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$secret}"; ????????$data_result?=?$this->curl_post_https($url_token); ????????$data?=?json_decode($data_result,TRUE); ????????$token?=?$data['access_token']; ????????session('expires_in',time()?+?$data['expires_in']); ????????session('token',$token); ????} ????//拿到token獲取二維碼 ????public?function?getXcxCode($scene,$path){ ????????$token?=?session('token'); ????????if?($token)?{ $expires_in?=?session('expires_in'); if($expires_in?&&?$expires_in?>?time()){ ????$accessToken=?$token; }else{ ????$accessToken?=?$this->getAccessToken(); } ????????}else{ ????????????$accessToken?=?$this->getAccessToken(); ????????} ????????$url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken}"; ????????$data=[ ????????????'scene'=>$scene, ????????????'page'=>$path, ????????????'width'=>430, ????????????'auto_color'=>false, ????????]; ????????$data=json_encode($data); ????????//拿到二維碼 ????????$result?=?$this->curl_post_https($url,$data); //var_dump($result); if(!$result?||?$this->is_json($result)){ return?false; } ????????//把二維碼存到服務器端 ????????$res?=?$this->UploadImageQrCode($result); ????????return?$res; ????} public?function?is_json($string)?{ json_decode($string); return?(json_last_error()?==?JSON_ERROR_NONE); } ????//?圖片上傳 ????public?function?UploadImageQrCode($img){ ????????$saveimgfile_1?=?'./Data/UploadFiles/code/'; ????????$fileimgname?=?time()."-".rand(1000,9999).".png"; ????????$filecachs?=?$saveimgfile_1.$fileimgname; ????????$fanhuistr?=?file_put_contents(?$filecachs,$img); ????????return?$fileimgname; ????} ????//?模擬post進行url請求 ????public?function?curl_post_https($url,$data){ ????????$ch?=?curl_init(); ????????$header?=?"Accept-Charset:?utf-8"; ????????curl_setopt($ch,?CURLOPT_URL,?$url); ????????curl_setopt($ch,?CURLOPT_CUSTOMREQUEST,?"POST"); ????????curl_setopt($ch,?CURLOPT_SSL_VERIFYPEER,?FALSE); ????????curl_setopt($ch,?CURLOPT_SSL_VERIFYHOST,?FALSE); ????????curl_setopt($ch,?CURLOPT_HTTPHEADER,?$header); ????????curl_setopt($ch,?CURLOPT_USERAGENT,?'Mozilla/5.0?(compatible;?MSIE?5.01;?Windows?NT?5.0)'); ????????curl_setopt($ch,?CURLOPT_FOLLOWLOCATION,?1); ????????curl_setopt($ch,?CURLOPT_AUTOREFERER,?1); ????????curl_setopt($ch,?CURLOPT_POSTFIELDS,?$data); ????????curl_setopt($ch,?CURLOPT_RETURNTRANSFER,true); ????????$tmpInfo?=?curl_exec($ch); ????????if?(curl_errno($ch))?{ ????????????return?false; ????????}else{ ????????????return?$tmpInfo; ????????} ????} ``` 要注意生成二維碼的兩個參數scene和path(新手必看、必踩的坑) ????page:必須是已經發布的小程序存在的頁面(否則報錯),例如 pages/index/index, 根路徑前不要填加 /,不能攜帶參數(參數請放在scene字段里),如果不填寫這個字段,默認跳主頁面 ????scene:最大32個可見字符,只支持數字,大小寫英文以及部分特殊字符:!#$&'()\*+,/:;=?@-.\_~,其它字符請自行編碼為合法字符(因不支持%,中文無法使用 urlencode 處理,請使用其他編碼方式) ????而且在小程序onLoad 的時候 需要使用 decodeURIComponent 才能獲取到生成二維碼時傳入的 scene ``` Page({ ??onLoad?(query)?{ ????//?scene?需要使用?decodeURIComponent?才能獲取到生成二維碼時傳入的?scene ????const?scene?=?decodeURIComponent(query.scene) ??}}) ``` 有個麻煩的地方是,如果你傳遞的scene 參數是“a=1&b=1”,那么在encodeURIComponent出來后的結果也是“a=1&b=1”,獲取a、b對應的值就需要自己對字符串去做處理了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看