1.在微信开放平台申请应用将appid与appsecret填写到uiapp===微信开放平台https://open.weixin.qq.com/
2.代码
var that = this
uni.getProvider({
service: 'oauth',
success: function(res) {
// console.log(res.provider);
//支持微信、qq和微博等
if (~res.provider.indexOf('weixin')) {
uni.login({
provider: 'weixin',
success: function(loginRes) {
// 获取用户信息
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
uni.request({
method: "POST",
url: that.httpUrl + '5ef',
header: {
'content-type': "application/x-www-form-urlencoded"
},
data: {
wx_openid: infoRes.userInfo.openId, //微信code
nickname: infoRes.userInfo.nickName, //微信昵称
avatars: infoRes.userInfo.avatarUrl // 微信头像地址
},
success: res => {
// console.log("openid======" + JSON.stringify(res))
var data = res.data
if (data.code == 1) {
} else {
uni.showToast({
title: data.msg,
icon: 'none'
})
}
},
});
}
});
}
});
}
}
});