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);
		}
	});
},
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值