如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
通过小程序登录获取小程序openID
1 2 3 |
<button hidden="{{is_login}}" class='bottom' type='primary' open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo" style='width:100px'> 登录</button> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
bindGetUserInfo: function (e) { if (e.detail.userInfo) { //用户按了允许授权按钮 var that = this; //插入登录的用户的相关信息到数据库 var openid = getApp().globalData.openid; var session = getApp().globalData.session getApp().globalData.userInfo = e.detail.userInfo; //通过wx.login获取code 想要获取用户信息,必须登录 wx.login({ success: function(res){ if(res.code){ var code = res.code; // 获取 encryptedData iv wx.getUserInfo({ withCredentials: true, success: function(res2){ //请求自己的登录接口 wx.request({ url: config.api_base_url + 'login', data: { userinfo: e.detail.userInfo, openid: openid, encryptedData:res2.encryptedData, iv:res2.iv, session:session }, header: { 'content-type': 'application/json' // 默认值 }, method: 'post', success(res) { if (res.data.result == 1) { wx.setStorageSync('user', res.data.msg); that.onLoad(); that.setData({ is_login:true }) } else { console.log("写入失败") } } }) } }) }else{ console.log('获取用户登录态失败!'+res.errMsg); } } }) return ; //授权成功后,跳转进入小程序首页 } else { //用户按了拒绝按钮 wx.showModal({ title: '警告', content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!', showCancel: false, confirmText: '返回授权', success: function (res) { if (res.confirm) { console.log('用户点击了“返回授权”') } } }) } }, |
小程序客服自定义回复设置
开发->开发设置->找到消息推送,并设置
小程序点击打开客服消息
通过发送消息,生成关注公众号带参数二维码
然后发送给用户
用户通过扫描二维码关注公众号,从而实现小程序和公众号的绑定