微信公众号授权登陆

wxLogin() {
			if (process.env.NODE_ENV == 'development') return
			// #ifdef H5
			let url = window.location.href //当前页面地址
			if (url.indexOf('?code=') != -1) { //授权回来 获取地址蓝code
				let code = url.split('?code=')[1].split('&')[0] //获取code
				let data = {
					code,
					// url: window.location.href,
					// recode: uni.getStorageSync('recode')
				}
				this.$api.AuthByCode(data).then(res => { //传给后端  
					uni.setStorageSync("yhToken", res.data.token.access_token);
					uni.setStorageSync("expires_in", res.data.token.expires_in);
					uni.setStorageSync("refresh_expires_in", res.data.token.refresh_expires_in);
					setTimeout(() => { //刷新页面
						window.location.href = this.$baseUrl + '/h5/'
						// window.location.href = 'http://www.duofangshuzishequ.com'+ '/h5/'
					}, 800)
				})
				return
			}
			let yhToken = uni.getStorageSync('yhToken')
			if (yhToken) return //如果当前有token 则不去请求
			let ua = window.navigator.userAgent.toLowerCase(); //判断的登录环境
			if (ua.indexOf('micromessenger') != -1) { //如果是微信
				console.log('微信公众号登录');
				let dataurl = {
					redirect_url: this.$baseUrl + '/h5/',
					// redirect_url: 'http://www.duofangshuzishequ.com' + '/h5/',
				}
				this.$api.GetAuthUrl(dataurl).then(res => { //向后端请求跳转地址
					window.location.href = res.data.url
				})
			}
			// #endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值