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) => {
             
              }
            },
          });
        },
      });

這樣就能拿到用戶信息了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM