• 一些问题(1)登陆时连续授权


    获取电话授权的时候没有办法同时获取Nickname跟头像

    尝试了先获取userinfo,成功后接着获取电话授权,

    然后再在电话授权中将信息传回后端

    getUserInfo: function (e) {
        wx.setStorageSync("userInfo", e);
        this.setData({
          lianxushouquan: 'true'
            //授权完user info让按钮消失,换成授权手机号的按钮
        })
      },
    

    获取电话,之前是别人写的,我决定不改直接往上加

    getPhoneNumber: function(e) {
        wx.setStorageSync("phoneNumber", e);
        var _this = this;
        var msg = e.detail.errMsg;
        var code = app.globalData.loginCode;
        var encryptedData = e.detail.encryptedData;
        var iv = e.detail.iv;
        var myinfos =wx.getStorageSync("userInfo");
        var nickname = myinfos.detail.userInfo.nickName
        console.log("encryptedData: " + encryptedData + "  iv:" + iv);
        if (msg == 'getPhoneNumber:ok') {
          wx.checkSession({
            success: function(res) {
              wx.request({
                url: app.globalData.baseUrl + "/api/wx/login",
                method: 'POST',
                data: {
                  code: code,
                  encryptedData: encryptedData,
                  iv: iv,
                  sessionid: sessionid, //会话id header中
                  nickName: nickname,//昵称
                   gender: myinfos.detail.userInfo.gender,// 性别 1 男 其他女
                   avatarUrl: myinfos.detail.userInfo.avatarUrl,//用户头像
                   country: myinfos.detail.userInfo.country,// 国家
                   province: myinfos.detail.userInfo.province,// 省份
                   city: myinfos.detail.userInfo.city,//城市
                },
                header: {
                  'content-type': 'application/json;charset=utf-8',
                },
                success: function(res) {
                  wx.setStorageSync("userId", res.data.data.id);
                  wx.setStorageSync("sessionid", res.data.data.sessionid);
                  wx.setStorageSync("isShowHead", true);
                  wx.setStorageSync("isShowMobile", true);
                  wx.setStorageSync("mobile", res.data.data.mobile);
                  console.log("设置成功!");
                  wx.navigateBack({
                    delta: 2,
                    success: function(e) {
                      var page = getCurrentPages().pop();
                      if (page == undefined || page == null) return;
                      page.onLoad();
                    }
                  })
                },
                fail: function(res) {
                  console.log(res);
                }
              })
              console.log(res);
              console.log("checkSession成功!");
            },
            fail: function(e) {
              console.log(e);
            }
          })
        } else {
          //用户按了拒绝按钮
          wx.showModal({
            title: '警告',
            content: '您点击了拒绝授权,将获取您的手机号,请授权之后再进入!!!',
            showCancel: false,
            confirmText: '返回授权',
            success: function(res) {
              // 用户没有授权成功,不需要改变 isHide 的值
              if (res.confirm) {
                console.log('用户点击了“返回授权”');
              }
            }
          });
        }
    
      },
    
  • 相关阅读:
    C
    B
    A
    G
    BZOJ_1208_&_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
    Codevs_1230_元素查找_(set/Hash)
    POJ_2503_Babelfish_(Trie/map)
    POJ_2001_Shortest_Prefixes_(Trie)
    BZOJ_3670_[NOI2014]_动物园_(kmp)
    BZOJ_3196_二逼平衡树_(树套树,线段树+Treap)
  • 原文地址:https://www.cnblogs.com/dudududadada/p/13551995.html
Copyright © 2020-2023  润新知