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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 簡介 OAuth2.0鑒權 ![](https://box.kancloud.cn/cfbbe40456de29136d9a421b5fc1d7df_1242x692.png) # 設置微信授權域名 ![](https://box.kancloud.cn/050ff0e8dc2da3cd07f44203d012d639_1092x211.png) ![](https://box.kancloud.cn/378121699fdf992af413650b3e2696a3_558x455.png) # 網頁授權開發工具 為了幫助開發者簡單和高效地開發和調試微信公眾號,推出了全新的 微信開發者工具,集成了公眾號網頁調試和小程序調試兩種開發模式 下載地址: https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html ![](https://box.kancloud.cn/598a6874766b42a99a2bd237ca5ade22_542x255.png) ![](https://box.kancloud.cn/9fb7eab432fcee6b9b42ea90888a545c_362x448.png) ![](https://box.kancloud.cn/d7daf9bc99e459b43158aeccbf1da25b_1217x568.png) # 微信授權代碼實現 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842 ![](https://box.kancloud.cn/7e77f6917a59171a7220c780e77bf440_1061x187.png) base此權限只能獲取用戶的openid而得不到用戶的基本信息,授權是無感,不需要用戶確認就可以完成授權,靜默方式。 userinfo 可能獲取openid和用戶的基本信息,需要用戶確認 ![](https://box.kancloud.cn/93f9162624f8debb6c2b39e95cf42024_514x216.png) # 步驟 [https://mp.weixin.qq.com/wiki?t=resource/res\_main&id=mp1421140842](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842) ## 獲取code值 ![](https://box.kancloud.cn/06177807884e3c7feaeb2f227b73f5d5_915x552.png) ![](https://box.kancloud.cn/39a1f71f819740d00492ae024aeac4c0_900x436.png) 在服務器中編寫生成跳轉地址url程序 ~~~ <?php $appid = 'wx77c5845xx9abaf8ad6'; //我寫個假的防止別人使用 $secret = '8074c29bdfa71fdbex9debc19060275dc'; //我寫個假的防止別人使用 // 授權成功后回調地址 請使用 urlEncode 對鏈接進行處理 $redirect_uri = urlencode('http://ns9aum.natappfree.cc/auth/shop.php'); //引導關注者打開如下頁面 $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo&state=100#wechat_redirect'; $url = sprintf($url, $appid, $redirect_uri); //我們把輸出的url放到微信開發者工具中,然后把這個url放到地址欄那,他會授權,然后跳轉到$redirect_uri那 //echo $url; //跳轉 header('location:' . $url); ~~~ 跳轉的url的代碼,這是授權成功后跳轉的頁面 `http://ns9aum.natappfree.cc/auth/shop.php` ~~~ <!doctype html> <html lang="zh-Hans"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <pre> <?php var_dump($_GET); ?> </pre> </body> </html> ~~~ 輸出 ![](https://box.kancloud.cn/f3b6676cc56ae3bd6f6b5aecafaeed36_744x220.png) **注意: code有效期是5分鐘** ## 得到openid完成授權 ![](https://box.kancloud.cn/01b75ee0428ca40d1d44f511f927920d_799x568.png) ![](https://box.kancloud.cn/605f3efb6e95350071ae9af8f4df47c0_795x708.png) openid重要 ![](https://box.kancloud.cn/343fc54326f7340a20bf002f00e3f159_841x269.png) ![](https://box.kancloud.cn/1dfffe9c6fcda0db12b59502d14928e1_845x348.png) ## 拉取用戶信息 ![](https://box.kancloud.cn/c28320a5fdee976372d614e0b0dad61b_833x579.png) ![](https://box.kancloud.cn/0d0be59aeb7e0c9145a4b32d97cdc96d_903x390.png) shop.php ~~~ <?php //appid公眾號 $appid = 'wx77c58459abaf8ad6'; $secret = '8074c29bdfa71fdbe9debc19060275dc'; //得到code $code = $_GET['code']; $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code'; $url = sprintf($url,$appid,$secret,$code); // 發起get請求, http_request是封裝的curl方法 $json = http_request($url); # json 轉為 array $arr = json_decode($json,true); $access_token = $arr['access_token']; $openid = $arr['openid']; // 拉取用戶信息 $url = 'https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN'; $url = sprintf($url,$access_token,$openid); // 發起get請求 $json = http_request($url); # json 轉為 array $userinfo = json_decode($json,true); //var_dump($userinfo); function http_request($url,$ret='',$file=''){ if (!empty($file)) { // 有文件上傳 # php5.5之前 '@'.$file;就可以進地文件上傳 # $ret['pic'] = '@'.$file; # php5.6之后用此方法 $ret['media'] = new CURLFile($file); } // 初始化 $ch = curl_init(); // 相關設置 # 設置請求的URL地址 curl_setopt($ch,CURLOPT_URL,$url); # 請求頭關閉 curl_setopt($ch,CURLOPT_HEADER,0); # 請求的得到的結果不直接輸出,而是以字符串結果返回 必寫 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); # 設置請求的超時時間 單位秒 curl_setopt($ch,CURLOPT_TIMEOUT,30); # 設置瀏覽器型號 curl_setopt($ch,CURLOPT_USERAGENT,'MSIE001'); # 證書不檢查 curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); # 設置為post請求 if($ret){ # 如果 $ret不為假則是post提交 # 開啟post請求 curl_setopt($ch,CURLOPT_POST,1); # post請求的數據 curl_setopt($ch,CURLOPT_POSTFIELDS,$ret); } // 發起請求 $data = curl_exec($ch); // 有沒有發生異常 if(curl_errno($ch) > 0){ // 把錯誤發送給客戶端 echo curl_error($ch); $data = ''; } // 關閉請求 curl_close($ch); return $data; } ?> <!doctype html> <html lang="zh-Hans"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="user"> <p>openid:<?php echo $openid;?></p> <p>昵稱:<?php echo $userinfo['nickname'];?></p> <p>性別:<?php echo $userinfo['sex']==1 ? '先生' : '靚妹';?></p> <p> 頭像: <img src="<?php echo $userinfo['headimgurl'] ?>" style="width: 300px;"> </p> <p>還有省市</p> </div> </body> </html> ~~~ 小結: * 生成跳轉的url地址,得到了code * 用code換取access_token和openid,完成授權 * 非必須的,如果是userinfo授權,則可以獲取用戶的基本信息
                  <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>

                              哎呀哎呀视频在线观看