<!-- 获取用户登陆信息按钮 --> <button open-type="getUserInfo" @getuserinfo="getWXUserInfo">login</button>
//微信获取openid getwxOpenid() { let _this = this let url = 'https://api.weixin.qq.com/sns/jscode2session?'; wx.login({ success(resu) { wx.request({ url: url + 'appid=' + _this.appId + '&secret=' + _this.secret + '&js_code=' + resu.code + '&grant_type=authorization_code', success(suce) { if (suce.statusCode == 200) { _this.openid = suce.data.openid _this.sessionkey = suce.data.session_key } }, fail(fail) { console.log('fail', fail) } }) } }) },
//获取用户信息 getWXUserInfo() { wx.getSetting({ success(succ) { console.log('succ', succ) wx.getUserInfo({ success(option) { console.log('op', option) }, fail(fail) { uni.showToast({ title:'获取用户信息失败', icon:'none' }) } }) }, fail(err) { console.log('err', err) } }) },