uniapp开发App调用微信授权登陆
作者:互联网
一键授权登陆在 微信开放平台 中创建移动应用,其中安卓应用签名为DCloud应用证书详情中的MD5密文(密文需要去除冒号并转小写)
wxLogin() {
let _this = this;
uni.getProvider({
service: 'oauth',
success: function(res) {
if (~res.provider.indexOf('weixin')) {
uni.showLoading({
title: '微信授权中'
});
uni.login({
provider: 'weixin',
success: function(loginRes) {
// // 获取用户信息
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
console.log('infoRes', infoRes)
const clientInfo = plus.push.getClientInfo()
_this.$Net.postAction(_this.$api.login, {
account: infoRes.userInfo.openId,
type: 2,
clientId: clientInfo.clientid
}).then((res) => {
// console.log(res)
uni.hideLoading();
if (res.result.status != 1) {
_this.$Jump.Open(`/pages/login/bind/bind_phone?loginType=2&account=${infoRes.userInfo.openId}`)
} else {
_this.$DataStore.localSet("userinfo", res.result.userInfo);
_this.$DataStore.localSet("loginInfo", res.result.userInfo);
_this.$DataStore.localSet("token", res.result.userInfo.token);
_this.$Jump.reLaunch('/pages/index/index');
// 签到
this.$Net.get(this.$api.signQueryByUserId).then(res => {
console.log(res);
if (res.result.status == 0) {
this.$Net.post(this.$api.signAdd).then(res => {
this.$Toast.message('签到成功!');
})
}
})
//#ifdef APP-PLUS
// 极光推送
/* jyJPush.setJYJPushAlias({
userAlias: res.result.userInfo.userId + ''
}, result => {});
jyJPush.addJYJPushReceiveNotificationListener(result => {
// 监听成功后,若收到推送,会在result返回对应的数据;数据格式保持极光返回的安卓/iOS数据一致
console.log('收到推送', JSON.stringify(result))
});
var clientid = plus.push.getClientInfo().clientid;
this.$Net.postAction(this.$api.bindAlias, {
cid: clientid
}).then(res2 => {}) */
//#endif
}
}).catch((er) => {
console.log(er)
uni.hideLoading();
_this.$Toast.message(er);
})
}
});
},
fail: function(er) {
uni.hideLoading();
_this.$Toast.message(er);
}
});
}
},
fail: function(er) {
_this.$Toast.message(er);
}
});
},
标签:uniapp,userInfo,console,res,App,result,微信,uni,er 来源: https://blog.csdn.net/qq_58946831/article/details/122622441