<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • ThinkPHP生成微信小程序帶參數(shù)二維碼附詳細(xì)代碼解析

            2023-03-07    分類(lèi): 微信小程序

            生成微信小程序二維碼
            生成帶參數(shù)的微信小程序二維碼用的還是比較多的,雖然微信小程序開(kāi)發(fā)文檔接口寫(xiě)的很清楚,如下圖,但實(shí)際開(kāi)發(fā)中總有人不知道如何操作或者經(jīng)常出錯(cuò),下面創(chuàng)新互聯(lián)根據(jù)微信小程序定制開(kāi)發(fā)經(jīng)驗(yàn),分享使用ThinkPHP生成微信小程序帶參數(shù)二維碼的整個(gè)過(guò)程。
            第一步、需要獲取ACCESS_TOKEN,需要小程序的APPID和APPSECRET,這兩個(gè)只要到微信小程序管理后臺(tái)即可獲得。
            第二步、使用微信小程序開(kāi)發(fā)接口生成二維碼并保存到服務(wù)器。代碼如下,其中sendCmd是遠(yuǎn)程請(qǐng)求的函數(shù),file_put_contents是PHP自帶函數(shù),用于保存圖片,【APPID】和【APPSECRET】請(qǐng)換成你自己的實(shí)際參數(shù)值。
            $url_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=【APPID】&secret=【APPSECRET】;
            $json_access_token = sendCmd($url_access_token,array());
            $arr_access_token = json_decode($json_access_token,true);
            $access_token = $arr_access_token['access_token'];
            if(!empty($access_token)) {
            $url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token='.$access_token;
            $data = '{"path": "pages/index/index?shop_id='.$shop_id.'&no_id='.$no_id.'", "width": 430}';
            $result = sendCmd($url,$data);
            file_put_contents('Public/code/code-'.$shop_id.'-'.$no_id.'.jpg',$result);
            return 'success';
            } else {
            return 'ACCESS TOKEN為空!';
            }
            /**
            * 發(fā)起請(qǐng)求
            * @param string $url 請(qǐng)求地址
            * @param string $data 請(qǐng)求數(shù)據(jù)包
            * @return string 請(qǐng)求返回?cái)?shù)據(jù)
            */
            function sendCmd($url,$data)
            {
            $curl = curl_init(); // 啟動(dòng)一個(gè)CURL會(huì)話
            curl_setopt($curl, CURLOPT_URL, $url); // 要訪問(wèn)的地址
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 對(duì)認(rèn)證證書(shū)來(lái)源的檢測(cè)
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 從證書(shū)中檢查SSL加密算法是否存在
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); //解決數(shù)據(jù)包大不能提交
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自動(dòng)跳轉(zhuǎn)
            curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自動(dòng)設(shè)置Referer
            curl_setopt($curl, CURLOPT_POST, 1); // 發(fā)送一個(gè)常規(guī)的Post請(qǐng)求
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的數(shù)據(jù)包
            curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 設(shè)置超時(shí)限制防止死循
            curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區(qū)域內(nèi)容
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回
            $tmpInfo = curl_exec($curl); // 執(zhí)行操作
            if (curl_errno($curl)) {
            echo 'Errno'.curl_error($curl);
            }
            curl_close($curl); // 關(guān)鍵CURL會(huì)話
            return $tmpInfo; // 返回?cái)?shù)據(jù)
            }

            當(dāng)前文章:ThinkPHP生成微信小程序帶參數(shù)二維碼附詳細(xì)代碼解析
            URL鏈接:http://www.jbt999.com/news41/242291.html

            網(wǎng)站建設(shè)、網(wǎng)絡(luò)推廣公司-創(chuàng)新互聯(lián),是專(zhuān)注品牌與效果的網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷(xiāo)seo公司;服務(wù)項(xiàng)目有微信小程序

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

            成都網(wǎng)站建設(shè)

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 123艹逼网| 国产精品无码久久久久成人app | 人妻无码日韩 | 精品中文字幕97A片免费视频 | 九色视频在线观看 |