设为首页 加入收藏

TOP

扫小程序码实现网站登陆,提供源代码(二)
2019-09-03 02:42:09 】 浏览:93
Tags:程序 实现 网站 登陆 提供 源代码
ot;scene":clientId}).then(res=>{ if(res.code==200){ $("#qrcode").attr("src",res.data) }else{ alert(res.msg) } intiwebsocket() },res=>{ alert(res.msg) }) }

小程序处理关键点

采用好的框架

我们编程过程才用了uniapp,这个框架不错,完全是vue的语法,
一套代码可以生成H5/小程序/android/ios
我们采用了vue的watch特性,通过监听userid来确定是否发送信息

watch:{
     userid:function(a,b){
            
            if(a==0){
                return 
            }
            
            this.loaddata()
            //如果clientid是空的说明不是扫码进来的    
            if(!this.clientid){
                return 
            }
//如果是扫码进来的,那么我们还需要推送消息到服务器后端
server.PublishMsg(this.clientid,this.userid,this.role,this.avatarUrl,this.nickName).then(res=>{
                tip.error(res.msg)
            },res=>{
                tip.error(res.msg)
            })
            
     }
  }

获取sceneid

我们通过onload方法获得sceneid

onLoad(arg) {
        if(!!arg && !!arg.scene){
                    this.clientid = decodeURIComponent(arg.scene)
        }
                
    },

核心代码如下

通过gotUserInfo获得用户头像、昵称等,通过uni.login获得code

gotUserInfo :function(e) {
             //获得用户头像、昵称、
              uni.login(
              {
                  success:(res) =>{
                            //通过wx.login获得code
                            userInfo.code = res.code
                                                //统一传递到后端      
                        this.authwithcode(userInfo)
                  }
              }
              )
            }
          },
        authwithcode:function(userInfo){
                        //code获得openid在后端做,做了后继续去查User表
            server.AuthWithCode(userInfo).then(res=>{
                    //如果这个openid绑定了用户                                                                   
                    if(res.data.id>0){
                        //这里res.data 就是user对象,可以继续操作
                        return ;
                    }
                    //如果没有那么注册
                    server.RegisterWithOpenId(res.data.mini_openid,userInfo.avatarUrl,userInfo.nickName)#.then(res=>{
                        //注册成功则返回
                        //这里res.data 就是user对象可以继续操作
                        
                    },res=>{
                        tip.error(res.msg)
                    })
                },res=>{
                    tip.error(res.msg||"");
                })
            }
        },  

体验地址

本文所有应用体验地址如下
互联网行业解决方案吧https://idea.techidea8.com/open/idea.shtml?id=5

关于代码

代码获得地址

小程序码登陆

代码配置

请认真阅读readme.md

推荐阅读

扫微信二维码实现网站登陆提供体验地址和源代码

开源项目golang go语言后台管理框架restgo-admin

支持手势触摸,可左右滑动的日历插件

你必须知道的18个互联网业务模型

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇写给新手的 Go 开发指南 下一篇go-micro 入门教程1.搭建 go-micr..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目