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个互联网业务模型