UNIAPP微信小程序获取手机号码

 onLoad() {
    // 提前调用一次,授权的时候会刷新code,不然会使解密的对不上
    uni.login({
      success: (res) => {},
    });
  },
  methods: {
    getPhoneNumber(e) {
      console.log(e);
      if (!this.agree) {
        return uni.showToast({
          title: "请阅读并勾选用户协议",
          icon: "none",
        });
      }

      var that = this;
      if (e.detail.errMsg != "getPhoneNumber:ok") {
        uni.showToast({
          title: "您拒绝了用户授权",
          icon: "none",
        });
      } else {
        uni.login({
          // provider: 'weixin',
          success: (res) => {
            console.log(res);
            var encryptedData = encodeURIComponent(e.detail.encryptedData);
            //用 code 换取 session 和 openId
            that.$http
              .post("index.php?m=Index&a=get_phone", {
                code: res.code,
                encryptedData: encryptedData,
                iv: e.detail.iv,
              })
              .then((res) => {
                console.log(res);

                uni.showToast({
                  title: res.msg,
                  icon: "none",
                });

                if (res.code == 200) {
                  that.member = res.data;
                  uni.setStorageSync("member", JSON.stringify(res.data));
                }
              });
          },
        });
      }
    },
}

免责申明:

1. 本站所有教程、文章或资源分享目的仅供大家学习和交流!
2. 如有无法查看或链接失效,麻烦请报告联系管理员处理!
3. 本站无法保证资源或其时效性,恕不接受任何提问。
4. 在本站下载的源码严禁杜绝任何形式的正式商业用途,请去程序官方购买。 所有资料均来自于网络,版权归原创者所有!本站不提供任何保证,并不承担任何法律责任,如果对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以删除。

学习交流联系

立即查看 了解详情