wx.getUserProfile更新後怎麼請問獲取unionId?

1.背景:https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801?highLine=getUserProfile%2520unionId
 

請注意下面畫紅線的部分!!!

 

 

2.坑是這樣的:

以前: wx.getUserInfo與<button open-type="getUserInfo"/> 除了可以獲取到用戶的【頭像暱稱】, 還可以獲取到【encryptedData和iv】(encryptedData和iv是用來解析openID、unionID的)
就是說通過getUserInfo基本就可以獲取【用戶暱稱頭像】及【openID、unionID】

 

現在:現在: wx.getUserProfile 雖然也可以獲取到encryptedData和iv, 但是從這裏是【解析不出來openIDunionID】的。

 

關鍵的是官方沒有指出這一點!!!讓你看到和以前一樣的【encryptedData和iv】,但是不能和以前一樣解析出【openID、unionID】

 

3.解決

<button v-if="canIUseGetUserProfile" @click="getUserProfile" class='button get-user-profile-btn'>授權</button>
<button v-else open-type="getUserInfo" class='button' @getuserinfo='getuserinfo'>授權</button>

 

getUserProfile(e: any) {
            (wx as any).getUserProfile({
                desc: '用於完善會員資料',
                success: (res: any) => {
                    wx.getUserInfo({  // 走一次getUserInfo
                        success: (res) => {
                            // todo...舊流程,拿【encryptedData和iv】去換【openID、unionID】
                        }
                    })
                }
            })
        }

        created() {
            if ((wx as any).getUserProfile) {
                this.canIUseGetUserProfile = false;
            }
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章