编程语言
首页 > 编程语言> > uniapp 微信小程序 授权获取个人信息

uniapp 微信小程序 授权获取个人信息

作者:互联网

主要用 uni.login 和  uni.getUserProfile  两个方法。

特别注意 uni.getUserProfile 里会重置code

 

 

 let code = "";
      uni.login({
        provider: "weixin",
        success: function (loginRes) {
          console.log("getUserProfile", loginRes);
          code = loginRes.code;
        },
      });
      uni.getUserProfile({
        lang: "zh_CN",
        desc: "登录",
        success: (res) => {
          console.log("user", res);
          this.userInfo = res.userInfo;
          let data = {
            channelId: this.channelId,
            token: code,
            signature: res.encryptedData,
            iv: res.iv,
          };
          uni.request({
            url: baseUrl + "/login", //仅为示例,并非真实接口地址。
            data: {
              ...data,
            },
            method: "POST",
            success: (res) => {
             
              }
            },
          });
        },
      });

这样就能拿到用户信息了。

 

标签:uniapp,code,res,个人信息,loginRes,微信,uni,data,getUserProfile
来源: https://www.cnblogs.com/lq2333/p/15573814.html