uniapp手机号授权登录-现在只能通过手机号授权登录,后台来获取用户信息了效果demo(整理)

简介: uniapp手机号授权登录-现在只能通过手机号授权登录,后台来获取用户信息了效果demo(整理)
<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="login-but">
  <view class="column-me column-center row-center">
    <view class="font-size24 color222">微信登录</view>
  </view>
</button>
.login-but {
  width: 180rpx;
  // height: 1rpx;
  // padding: 0;
  background-color: none !important;
  background: none !important;
  border: none !important;
  &::after {  //通过伪元素去除按钮边框
    border: none;
  }
}
// 点击微信授权登录
getPhoneNumber(e) {
  // return false;
  // if (this.pitchOn == 0) {
  //  this.$.toast('请先阅读并同意协议');
  //  return false;
  // }
  if (e.detail.errMsg == "getPhoneNumber:ok") {
    let that = this;
    uni.login({
      provider: 'weixin',
      success: function(loginRes) {
        // 获取用户信息       
        console.log(loginRes, 'login授权code');
        that.$.ajax("POST", "/api/login/weChatLoginTry", {
          code: loginRes.code,
          ajax_type: 'form'
        }, (res) => {
          if (res.code == 1000) {
            if (res.data.status == 2) {
              // 2:微信未绑定手机
              return false
            } else if (res.data.status == 1) { //登录结果 1:成功 2:微信未绑定手机
              that.$.show();
              that.$.set_data("token", res.data.token);
              that.$.set_data("userForm", res.data.user);
              that.$.open_tab('/pages/index/index');
              that.$.hide();
            }
          } else if (res.code == 8001) { //没有授权
            console.log(e.detail.code,'手机号授权code')
            // -----------------------
            that.$.ajax("POST", "/api/login/wxLoginCreateUserCode", {
              code: loginRes.code,  //login授权code
              phoneCode: e.detail.code, //手机号授权code
              ajax_type: 'form'
            }, (res1) => {
              if (res1.code == 1000) {
                // that.$.show();
                that.$.set_data("token", res.data.token);
                that.$.set_data("userForm", res.data.user);
                that.$.open_tab('/pages/index/index');
                // that.$.hide();
              } else {
                that.$.toast(res.message);
              }
            });
            // -----------------------
          } else {
            that.$.toast(res.message);
          }
        });
      }
    });
  } else {
    //拒绝授权
    this.$.toast('已拒绝授权,无法登录');
  }
},

相关文章
|
6天前
|
存储 JavaScript 开发工具
uniapp-实现微信授权登录
uniapp-实现微信授权登录
926 0
|
6天前
|
前端开发
uniapp 实现退出登录 清除Token
uniapp 实现退出登录 清除Token
71 0
|
6天前
|
API
uniapp怎么实现授权登录
uniapp怎么实现授权登录
59 2
|
6天前
|
JSON Java 数据库
基于uniapp原生组件uni-ui 做一个登录注册与个人中心(后端篇)
基于uniapp原生组件uni-ui 做一个登录注册与个人中心(后端篇)
129 2
|
6天前
|
前端开发 数据安全/隐私保护
uniapp-含有后端的登录注册页面编写(二)
uniapp-含有后端的登录注册页面编写(二)
99 0
|
6天前
|
存储 SQL 安全
uniapp-含有后端的登录注册页面编写(一)
uniapp-含有后端的登录注册页面编写
166 0
|
6天前
|
小程序
uniapp 微信小程序登录 新手专用 引入即可
uniapp 微信小程序登录 新手专用 引入即可
35 0
|
6天前
|
开发者
uniapp-微信授权登录
uniapp-微信授权登录
158 0
|
6天前
uniapp获取微信用户信息登录
uniapp获取微信用户信息登录
|
6天前
|
小程序
uniapp麦克风授权窗口
uniapp麦克风授权窗口
93 0

热门文章

最新文章