<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國際加速解決方案。 廣告
                ``` https://www.imooc.com/wenda/detail/518810 借鑒該講解 ``` ``` 偶爾失敗的情況,很大可能是wx.getUserInfo和wx.login的順序弄錯了。 正常的流程,wx.login拿到code =》 wx.getUserInfo拿到iv和encryptedData =》 發送給服務器解密 很容易錯寫成在wx.getUserInfo的回調里再調wx.login拿code再發送給服務器,這樣,getUserInfo里的data加密用的session\_key就有可能跟解密的時候的session\_key不一致,因為wx.login有可能會刷新了session\_key 解決: 保證userinfo總是在最后的一次login之后發起 ``` ``` bindGetUserInfo: function(n) { console.log(n) wx.showLoading({ title: "加載中" }), wx.login({ success: function(i) { console.log(i) app.network.request1({ url: "wxapp/login", method: "POST", data: { code: i.code, }, success: function(i) { console.log(i) if (i.data.error == 0) { wx.getUserInfo({ success: (ress) => { app.network.request1({ url: "wxapp/auth", method: "GET", data: { data: ress.encryptedData, iv: ress.iv, sessionKey: i.data.session_key }, success: function(res) { console.log(res) if (res.data.error == 0) { wx.setStorageSync('userinfo_openid', i.data.openid); wx.setStorageSync('login_session_key', i.data.session_key); wx.setStorageSync('userinfo_id', res.data.id) wx.navigateBack({ delta: 0, }) } else { wx.showToast({ icon: "none", title: res.data.message, }) } } }) } }) } else { wx.showToast({ icon: "none", title: "獲取用戶登錄態失敗", }) } } }) }, fail: function() { o.alert("獲取用戶信息失敗!"); }, complete: function() { wx.hideLoading(); } }); }, ``` ![](https://img.kancloud.cn/fb/5f/fb5fdfc23dca8b566a9693b2bd7a44e5_500x413.jpg) 后端就使用官方的解密就行 ``` <?php require_once EWEI_SHOPV2_PLUGIN . "app/core/wxapp/pkcs7Encoder.php"; /** * 對微信小程序用戶加密數據的解密示例代碼. * * @copyright Copyright (c) 1998-2014 Tencent Inc. */ class WXBizDataCrypt { private $appid = NULL; private $sessionKey = NULL; /** * 構造函數 * @param $sessionKey string 用戶在小程序登錄后獲取的會話密鑰 * @param $appid string 小程序的appid */ public function WXBizDataCrypt($appid, $sessionKey) { $this->sessionKey = $sessionKey; $this->appid = $appid; } /** * 解密處理 * @param $encryptedData * @param $iv * @param $data * @return int|string */ public function decryptData( $encryptedData, $iv, &$data ) { if (strlen($this->sessionKey) != 24) { return ErrorCode::$IllegalAesKey; } $aesKey = base64_decode($this->sessionKey); if (strlen($iv) != 24) { return ErrorCode::$IllegalIv; } $aesIV = base64_decode($iv); $aesCipher = base64_decode($encryptedData); $result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV); $dataObj=json_decode($result); if ($dataObj == NULL) { return ErrorCode::$IllegalBuffer; } if ($dataObj->watermark->appid != $this->appid) { return ErrorCode::$IllegalBuffer; } $data = $result; return ErrorCode::$OK; } } ?> ```
                  <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>

                              哎呀哎呀视频在线观看