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
微信公众号授权登陆
最新推荐文章于 2024-06-23 10:41:54 发布