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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM