1.在源码视图 "oauth",添加appsecret秘钥“”,
2.
// app端 微信登录
wxClick() {
let that = this
uni.getProvider({
service: 'oauth',
success:function(res){
if (~res.provider.indexOf('weixin')) {
//支持微信、qq和微博等
uni.login({
provider: 'weixin',
success: function(loginRes) {
console.log(loginRes)
// 获取用户信息
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
let params = {
avatarUrl: infoRes.userInfo.avatarUrl,
gender: infoRes.userInfo.gender,
nickName: infoRes.userInfo.nickName,
openid: infoRes.userInfo.openId,
type: 1
}
that.$api.wxLogin(params).then(res => {
that.$until.error(res);
uni.setStorageSync('token', res
.data.token);
if (res.data.type == true) {
uni.navigateTo({
url: '/subpackage/login/chef?openid=' +
res.data
.openid,
})
} else {
uni.switchTab({
url: '/pages/index/index'
})
}
uni.switchTab({
url: '/pages/index/index'
})
})
},
fail(err) {
console.log(err, '2')
}
});
},
fail(err) {
console.log(err, '1')
}
})
}
}
})
},