小言_互联网的博客

uniapp实现APP微信登录流程

745人阅读  评论(0)

1、注册微信开放平台

 

1、注册账号

https://open.weixin.qq.com/

 

2、企业认证 (微信登录必须认证)

 

3、创建应用填写信息

 

 

4、等待审核

 

5、获取appid和秘钥(开通APP支付绑定商户即可)

 

 

2、用户端代码中进入manifest.json设置

 

3、登录界面代码实现

写一个登录按钮

<button  class="confirm-btn" @click="weixinLo">微信登录</button>

实现点击登录方法代码以及说明


  
  1. weixinLo() {
  2. let that = this;
  3. uni.login({
  4. provider: 'weixin',
  5. success: function(loginRes) {
  6. that.$queue.showLoading( '正在登录中...');
  7. console.error(loginRes.authResult);
  8. //获取登录的token
  9. that.$queue.setData( 'weixinToken',loginRes.authResult.access_token);
  10. //获取登录的unionid 这个还是在开放平台做了 公众号 小程序 微信登录app关联才会有
  11. that.$queue.setData( 'unionid', loginRes.authResult.unionid);
  12. //获取openid
  13. that.$queue.setData( 'weixinOpenid', loginRes.authResult.openid);
  14. //这里吧数据全部提交给后台核验,有没有注册 注册了 后台代码会请求接口String s = HttpClient.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + loginInfo.getToken() + "&openid=" + loginInfo.getOpenid()); 获取头像和昵称
  15. that.$Request
  16. .postJson( '/user/loginApp', {
  17. token: loginRes.authResult.access_token,
  18. unionid: loginRes.authResult.unionid,
  19. openid: loginRes.authResult.openid
  20. })
  21. .then( res => {
  22. if (res.status === 0) {
  23. //绑定手机号直接登录
  24. that.getUserInfo(res.data.userId, res.data.uuid);
  25. } else {
  26. //没有绑定手机号让绑定手机号
  27. uni.navigateTo({
  28. url: '/pages/public/wxmobile'
  29. });
  30. }
  31. });
  32. }
  33. });
  34. },

 


转载:https://blog.csdn.net/weixin_39706415/article/details/111588710
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场