• 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;
                }
            }
  • 相关阅读:
    phpcms 任意位置获取用户头像
    php微信公众帐号发送红包
    nginx解决502错误
    phpcms v9 万能字段使用
    0转换为万
    温故而知新(三)
    温故而知新(一)
    基础积累,来自其他网站的链接
    GCD多线程 在子线程中获取网络图片 在主线程更新
    iOS9 中的一些适配问题
  • 原文地址:https://www.cnblogs.com/cynthia-wuqian/p/14681712.html
Copyright © 2020-2023  润新知