小程式資訊授權sessionKey失效問題

2022-04-11 11:56:15 字數 1112 閱讀 5941

廢話不說,直接上萬無一失的辦法。

wxml:

<

button

class

="btn"

open-type

="getuserinfo"

bindgetuserinfo

="getuserinfo"

style

="margin-top: 40rpx"

>}

button

>

js:常見的錯誤,

① 使用者點選按鈕:此時獲取到了 加密資訊: iv,encrypteddata

② 獲取code

③ 利用code解密,點選按鈕獲取的 iv,encrypteddata ,但是 此時的iv,encrypteddata 是上乙個code的加密資訊。

解決方法: 在獲取code之後,再用 wx.getuserinfo獲取新的 iv和encrypteddata 然後再解密,就不會出問題了。

注意:一定要拋棄點選按鈕拿到的 iv和encrypteddata

getuserinfo(e)  =userinfo

//解密 start

request(, method: 'post'})

.then(result=> =result.data.data

wx.setstoragesync('openid', openid)

wx.hideloading()

wx.showtoast()

},})

resolve(openid)}})

//解密 end

}).catch(res=>);

});},

const wxgetuserinfo = function(),

fail(res)

})});

}const getcodelogin = function

(successfn)

})}

小程式授權

一 小程式在使用使用者的個人資訊的時候需要授權方法如下 1 wxml 獲取使用者資訊 2 js 獲取應用例項 page 判斷當前版本button.open type.getuserinfo方法是否可用 caniuse wx.caniuse button.open type.getuserinfo o...

小程式 授權相關

小程式授權流程 1.首次小程式,將需要的授權呼叫一遍 uni.authorize wx.authorize 2.進入到應用模組,呼叫某個需要授權的api之前,先檢測使用者是否授權該功能 uni.getsetting 如果未授權,就開啟授權設定頁 uni.opensetting 注意此api需要使用者...

小程式的授權

自從小程式文件更新後,自動授權已不存在啦 目前的授權都是通過button來實現的,具體知識點可參考小程式的官方文件,以下是我做的乙個小demo 進入首頁,跳出乙個登入彈出框,彈出框是自己寫的乙個ui元件 廢話不多說,直接上 view class modal mask wx if bindtap cl...