联系官方销售客服

1835022288

028-61286886

二次开发 版主:官方研发技术组
小程序新版接口wx.getUserProfile方法的登录注册实例吗
类型:迅睿CMS 更新时间:2022-11-06 00:57:27 微信小程序 小程序

有大佬能提供个微信小程序新版接口wx.getUserProfile方法的登录注册实例吗?

回帖
  • 鑫同学
    #1楼    鑫同学
    2022-07-21 10:55:36
    Chrome 1
    我自己用的,可以成功
    getUserProfile: function (e) {  
        var self=this;  
        wx.getUserProfile({
          desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
          success: (file) => {  
          if (file.userInfo) {     
            console.log(file.userInfo)
            wx.login({
              success: (res) => {
                console.log(file);
                console.log(file.encryptedData);
                wx.request({
                  url: app.globalData.http_api + "s=weixin&c=member&m=xcx",
                  method: 'post',
                  header: {
                  'Content-Type': 'application/x-www-form-urlencoded',
                   },
                  data: {
                    nickname:file.userInfo.nickName,
                    avatar:file.userInfo.avatarUrl,
                    js_code: res.code,
                    json:file.rawData
                  },
                  success: (open) => {
                    console.log(open.data);          
                        if (open.data.code) {
                          if (open.data.msg == 'login') {
                            // 登录成功
                            console.log("登录成功了");
                            wx.setStorageSync('member_uid', open.data.data.member.id);
                            wx.setStorageSync('member_auth', open.data.data.auth);
                            wx.setStorageSync('member', open.data.data.member);
                            wx.setStorageSync('member_oauth', file.userInfo);                        
                            
                            console.log(open.data.data.avatar);
                            wx.showToast({
                              title: "登录成功",
                              icon: 'success',
                              success: function () {  
                                wx.reLaunch({ url: "/pages/member/index" });                   
                                                        
                              }
                            })
          
                          } else {
                            // 绑定账号注册
                            wx.setStorageSync('oauth', ress.data.data);
                            wx.showActionSheet({
                              itemList: ['绑定已有账号', '注册新账号'],
                              success: function (res) {
                                if (res.tapIndex == 1) {
                                  wx.navigateTo({ url: "../login/register" });
                                } else {
                                  wx.navigateTo({ url: "../login/bang" });
                                }
                              },
                              fail: function (res) {
                                console.log(res.errMsg)
                              }
                            })
          
                            //
                          }
                        } else {
                          // 失败了
                          wx.showModal({
                            showCancel: false,
                            content: open.data.msg
                          })
                        }
                      }
             })
          } 
        })
      }
    }
        })
      },
    满意答案
  • 匿名者
    #2楼    匿名者
    2022-11-06 00:57:27
    Chrome 0
    @鑫同学:问题已解决。完结