请求接口code换取openid信息:
wxlogin() {
let that = this
let token = uni.getStorageSync('weToken')
console.log(token)
if (token) {
wx.reLaunch({
url: "/pages/tarbar"
})
} else {
uni.login({
provider: 'weixin', //使用微信登录
success: function(res) {
const code = res.code
//获取默认微信信息
uni.request({
url: '', //换取key。
data: {
code: code,
},
method: "POST",
success: (res) => {
console.log(res.data.data)
uni.setStorageSync('session_key', res.data.data)
const openid=res.data.data.openid;
that.registration(openid)
}
});
}
});
}
},
存储用户到数据库:
registration(data) {
console.log(data)
uni.getUserInfo({
success(res) {