<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之旅 廣告
                ![](https://img.kancloud.cn/14/6c/146cf0bb23eed34980fcf510febc2812_710x720.png) 1. 調用[wx.login()](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html)獲取**臨時登錄憑證code**,并回傳到開發者服務器。 2. 調用[auth.code2Session](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html)接口,換取**用戶唯一標識 OpenID**和**會話密鑰 session\_key**。 之后開發者服務器可以根據用戶標識來生成自定義登錄態,用于后續業務邏輯中前后端交互時識別用戶身份。 **注意:** 1. 會話密鑰`session_key`是對用戶數據進行[加密簽名](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html)的密鑰。為了應用自身的數據安全,開發者服務器**不應該把會話密鑰下發到小程序,也不應該對外提供這個密鑰**。 2. 臨時登錄憑證 code 只能使用一次 # auth.code2Session > 本接口應在服務器端調用,詳細說明參見[服務端API](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html)。 登錄憑證校驗。通過[wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html)接口獲得臨時登錄憑證 code 后傳到開發者服務器調用此接口完成登錄流程。更多使用方法詳見[小程序登錄](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html)。 ### [](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html#%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80)請求地址 ~~~ GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code ~~~ ### [](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html#%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0)請求參數 | 屬性 | 類型 | 默認值 | 必填 | 說明 | | --- | --- | --- | --- | --- | | appid | string | | 是 | 小程序 appId | | secret | string | | 是 | 小程序 appSecret | | js\_code | string | | 是 | 登錄時獲取的 code | | grant\_type | string | | 是 | 授權類型,此處只需填寫 authorization\_code | ### [](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html#%E8%BF%94%E5%9B%9E%E5%80%BC)返回值 ### [](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html#Object)Object 返回的 JSON 數據包 | 屬性 | 類型 | 說明 | | --- | --- | --- | | openid | string | 用戶唯一標識 | | session\_key | string | 會話密鑰 | | unionid | string | 用戶在開放平臺的唯一標識符,在滿足 UnionID 下發條件的情況下會返回,詳見[UnionID 機制說明](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html)。 | | errcode | number | 錯誤碼 | | errmsg | string | 錯誤信息 | **errcode 的合法值** | 值 | 說明 | 最低版本 | | --- | --- | --- | | \-1 | 系統繁忙,此時請開發者稍候再試 | | | 0 | 請求成功 | | | 40029 | code 無效 | | | 45011 | 頻率限制,每個用戶每分鐘100次 | 小程序獲取手機號 前端代碼 ``` <button?open-type="getPhoneNumber"?bindgetphonenumber="getPhoneNumber">獲取手機號</button> getPhoneNumber: function (n) { wx.showLoading({ title: "加載中" }), wx.login({ success: function (i) { o.post("wxapp/login", { code: i.code }, function (i) { console.log([2, i]), i.error ? o.alert("獲取用戶登錄態失敗:" + i.message) : o.get( "api/getMobile", { data: n.detail.encryptedData, iv: n.detail.iv, sessionKey: i.session_key }, function (s) { console.log(s) }); }); }, fail: function () { o.alert("獲取用戶信息失敗!"); }, complete: function () { wx.hideLoading(); } }); }, ``` 獲取實例 ``` "data":?{ "phoneNumber":?"18123119755", "purePhoneNumber":?"18123119755", "countryCode":?"86", "watermark":?{ "timestamp":?1597762273, "appid":?"wx05ddsdsd62a06ab03" } } ``` php 代碼 ``` ~~~ /** * 微信小程序登錄 */ public function getMobile() { global $_GPC; global $_W; $encryptedData = trim($_GPC['data']); $iv = trim($_GPC['iv']); $sessionKey = trim($_GPC['sessionKey']); if (empty($encryptedData) || empty($iv)) { return app_error(AppError::$ParamsError); } $aesKey = base64_decode($sessionKey); $aesIV = base64_decode($iv); $aesCipher = base64_decode($encryptedData); $result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV); $result = json_decode($result,true); if($result){ return app_json(['data'=>$result['phoneNumber']]); } return app_error(AppError::$RequestError); } ~~~ ```
                  <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>

                              哎呀哎呀视频在线观看