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('已拒绝授权,无法登录');
  }
},

相关文章
|
3月前
|
存储 JSON JavaScript
前后端分离项目知识汇总(微信扫码登录,手机验证码登录,JWT)-1
前后端分离项目知识汇总(微信扫码登录,手机验证码登录,JWT)
66 0
|
8天前
|
前端开发
uniapp 实现退出登录 清除Token
uniapp 实现退出登录 清除Token
13 0
|
1月前
|
安全 Linux 网络安全
购了轻服务器,手机登录服务器用root和administrator做登录名,都提示别名已存在,请修改
【2月更文挑战第16天】购了轻服务器,手机登录服务器用root和administrator做登录名,都提示别名已存在,请修改
13 1
|
2月前
|
安全 Linux 网络安全
手机登录服务器用root和administrator做登录名,都提示别名已存在
【2月更文挑战第5天】手机登录服务器用root和administrator做登录名,都提示别名已存在
30 8
|
2月前
|
API
uniapp怎么实现授权登录
uniapp怎么实现授权登录
44 2
|
3月前
|
JSON 前端开发 安全
前后端分离项目知识汇总(微信扫码登录,手机验证码登录,JWT)-2
前后端分离项目知识汇总(微信扫码登录,手机验证码登录,JWT)
58 0
|
3月前
|
JSON Java 数据库
基于uniapp原生组件uni-ui 做一个登录注册与个人中心(后端篇)
基于uniapp原生组件uni-ui 做一个登录注册与个人中心(后端篇)
110 2
|
2月前
|
监控 安全 Android开发
【新手必读】Airtest测试Android手机常见的设置问题
【新手必读】Airtest测试Android手机常见的设置问题
|
4月前
|
XML Java Android开发
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
96 0
|
3月前
|
安全 网络协议 Linux
【公网远程手机Android服务器】安卓Termux搭建Web服务器
【公网远程手机Android服务器】安卓Termux搭建Web服务器
67 0

热门文章

最新文章