<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                1.在根目錄下的/Application/Home/Controller文件夾中的SdkController.class.php文件展示: ~~~ <?php namespace Home\Controller; use Think\Controller; use Com\Wechat; use Com\WechatAuth; class SdkController extends Controller { private $appid="wx165112bf167af76c"; private $appSecret="c65b22bfcf03fdd98504eac299701b03"; private $WechatAuth="";//初始化WechatAuth類 private $access_token="";//緩存token private $jsapi_ticket="11";//緩存jsapi_ticket /** * 微信api根路徑 * @var string */ private $apiURL = 'https://api.weixin.qq.com/cgi-bin'; public function __construct(){ parent::__construct();//可能內部已經有這個構造方法了,因此加上這個 if(!session('token')){ $this->WechatAuth=new WechatAuth($this->appid,$this->appSecret);//初始化WechatAuth類 $WechatAuth=$this->WechatAuth; $token=$WechatAuth->getAccessToken(); session(array('expire'=>$token['expires_in']));//設置過期時間 session('token',$token['access_token']);//緩存token $this->access_token=$token; }else{ $token=session('token'); $this->WechatAuth=new WechatAuth($this->appid,$this->appSecret,$token);//初始化WechatAuth類 $this->access_token=$token;//緩存token } // jsapi_ticket 應該全局存儲與更新,以下代碼以寫入到文件中做示例 if (!session('jsapi_ticket')) { $accessToken=$this->access_token; // 如果是企業號用以下 URL 獲取 ticket // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken"; $res = json_decode($this->httpGet($url)); //$this->jsapi_ticket ="555"; $this->jsapi_ticket = $res->ticket; session(array('expire'=>7200));//設置過期時間,實際設置7200秒,現在設為5秒方便測試 session('jsapi_ticket', $this->jsapi_ticket); } else { $this->jsapi_ticket = session('jsapi_ticket'); } } public function sss() { session_destroy(); } public function index() { // $this->getSignPackage(); $data=$this->getSignPackage(); $this->assign('data',$data); $this->display(); } public function getSignPackage(){ /* echo $this->jsapi_ticket; exit;*/ $jsapiTicket = $this->jsapi_ticket; // echo $jsapiTicket;exit; // 注意 URL 一定要動態獲取,不能 hardcode. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $timestamp = time(); $nonceStr = $this->createNonceStr(); // 這里參數的順序要按照 key 值 ASCII 碼升序排序 $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url"; $signature = sha1($string); $signPackage = array( "appId" => $this->appid, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string ); return $signPackage; } private function createNonceStr($length = 16) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $str = ""; for ($i = 0; $i < $length; $i++) { $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); } return $str; } private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); // 為保證第三方服務器與微信服務器之間數據傳輸的安全性,所有微信接口采用https方式調用,必須使用下面2行代碼打開ssl安全校驗。 // 如果在部署過程中代碼在此處驗證失敗,請到 http://curl.haxx.se/ca/cacert.pem 下載新的證書判別文件。 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return $res; } } ~~~ 2.在根目錄下的/Application/Home/View/Sdk文件夾中的index.html文件展示: ~~~ <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script> /* * 注意: * 1. 所有的JS接口只能在公眾號綁定的域名下調用,公眾號開發者需要先登錄微信公眾平臺進入“公眾號設置”的“功能設置”里填寫“JS接口安全域名”。 * 2. 如果發現在 Android 不能分享自定義內容,請到官網下載最新的包覆蓋安裝,Android 自定義分享接口需升級至 6.0.2.58 版本及以上。 * 3. 常見問題及完整 JS-SDK 文檔地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html * * 開發中遇到問題詳見文檔“附錄5-常見錯誤及解決辦法”解決,如仍未能解決可通過以下渠道反饋: * 郵箱地址:weixin-open@qq.com * 郵件主題:【微信JS-SDK反饋】具體問題 * 郵件內容說明:用簡明的語言描述問題所在,并交代清楚遇到該問題的場景,可附上截屏圖片,微信團隊會盡快處理你的反饋。 */ wx.config({ debug: true, appId: '<?php echo $data["appId"];?>', timestamp: <?php echo $data["timestamp"];?>, nonceStr: '<?php echo $data["nonceStr"];?>', signature: '<?php echo $data["signature"];?>', jsApiList: [ // 所有要調用的 API 都要加到這個列表中 'checkJsApi' ] }); wx.ready(function () { // 在這里調用 API wx.checkJsApi({ jsApiList: ['chooseImage'], // 需要檢測的JS接口列表,所有JS接口列表見附錄2, success: function(res) { // 以鍵值對的形式返回,可用的api值true,不可用為false // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"} } }); }); </script> </html> ~~~ 結果截圖: ![](https://box.kancloud.cn/0924ccfce3e8654894e935c5adb9a0cb_1080x1920.png) ![](https://box.kancloud.cn/887642e465b18cd076d3e281f7c941c6_427x623.png) 注意點: 若是第一個結果出現“config:invalid signature”,大概率是access_token過期,解決辦法是![](https://box.kancloud.cn/63da5862b66df0c62a24d9b8d0a04a22_374x84.png)運行這個方法清除session重新生成access_token(多試幾次?) 本節源碼下載(下載密碼:65zb) [源碼下載](https://pan.baidu.com/s/1G0OpL0pUZakIr7uChaiXyw)
                  <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>

                              哎呀哎呀视频在线观看