微信最新登录按钮更新

uniapp开发小程序对于新的获取用户名和手机号方式

  

                       <!-- 旧版本方式 -->
                        <!-- #ifdef MP-WEIXIN -->
                        <block v-if="canIUseProfile==false">
                            <button class="cu-btn bg-green margin-left bottom" type="primary" @getuserinfo='getuserinfo'
                                open-type="getUserInfo" v-show="!uname"
                                style="position: absolute; top: -10rpx;left: 50%;">立即登录</button>
                        </block>

                        <!-- 新版本方式 -->
                        <block v-else>
                            <button class="cu-btn bg-green margin-left bottom" type="primary" @tap='getuserinfo'
                                v-show="!uname" style="position: absolute; top: -10rpx;left: 50%;">立即登录</button>
                        </block>
                        <!-- #endif -->

            export default {
                  data() {
                        return {
                // 用户小程序获取用户信息新旧修改
                canIUseProfile: false;

          },

methods:{

//#ifdef MP-WEIXIN
            getuserinfo(e) {
                if (this.canIUseProfile == false) {
                    console.log(e)
                    this.modalName = null;
                    let _this = this;
                    _this.uname = e.detail.userInfo.nickName;
                    _this.avatarUrl = e.detail.userInfo.avatarUrl
                    uni.setStorageSync('nickname', e.detail.userInfo.nickName);
                    uni.setStorageSync('avatarUrl', e.detail.userInfo.avatarUrl);
                } else {
                    var that = this;
                    wx.getUserProfile({
                        desc: '用于完善用户资料',
                        lang: 'zh_CN',
                        success: function(res) {
                            console.log(res.userInfo)
                            that.uname = res.userInfo.nickName;
                            that.avatarUrl = res.userInfo.avatarUrl
                            uni.setStorageSync('nickname', res.userInfo.nickName);
                            uni.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
                            /* 以下是网友说的,我还没来得及测试:  
                            按新方案的意思,encryptedData,iv,rawData,signature这几个属性用不上了。  
                            小程序端wx.getUserProfile()获取到userInfo,wx.login()获取到code,  
                            这两个传给后端,code通过code2session接口获取到unionid,openid,session_key等;  
                            原有的拿session_key解密encryptedData的逻辑不需要了,毕竟encryptedData也只是比userInfo多了openid和unionid。  
                            */

                        },
                        fail: function(res) {
                            console.log('wx.getUserProfile=>用户拒绝了授权');
                            console.log(res);

                        },
                    });

                }
            },
            // #endif

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值