小程序获取微信信息-登录
<button open-type="getUserInfo" bindgetuserinfo="getUserInfo" lang="zh_CN">微信一键登录</button>
getUserInfo: function (infoRes) { //点击登录运行此方法 let that = this; wx.login({ //小程序提供的登录方法 success: function (loginRes) { if (loginRes) { infoRes = infoRes.detail; //获取微信授权信息 //请求服务端的登录接口 wx.request({ url: app.globalData.baseUrl + 'rest/app/getWeUser', //后台提供接口 获取app.js里的globaldata方法里的baseUrl值 data: { code: loginRes.code,//临时登录凭证code通过wx:login获取 rawData: infoRes.rawData,//用户非敏感信息 signature: infoRes.signature,//签名 encryptedData: infoRes.encryptedData,//用户敏感信息 iv: infoRes.iv//解密算法的向量 }, success: function (res) { if (res.data.code == '0') { wx.setStorageSync('customerUuid', res.data.data.uuid); //缓存数据 wx.setStorageSync('customerNickName', res.data.data.nickname); wx.setStorageSync('headImgUrl', res.data.data.headImgUrl); res = res.data; wx.switchTab({ //跳转页面到nav的页面 url: '/pages/index/index' }); } }, fail: function (error) { //调用服务端登录接口失败 } }); } } }); }, //wx.getUserInfo(OBJECT) 注意:此接口有调整,使用该接口将不再出现授权弹窗,请使用 //<button open-type="getUserInfo"></button>