您的位置:首页 > 移动开发 > 微信开发

微信h5页面授权登录的code拼接问题以及解决方案

2020-07-14 05:53 323 查看

利用中间页面去解析和跳转

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<script src="./axios.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.title {
color: #555;
font-size: 14px;
}
</style>
</head>
<body>
<span class="title">正在授权中...</span>
<script>
function qs (search) {
var obj = {}
var query = search.slice(1)
query.split('&').forEach(function (value) {
var arr = value.split('=')
obj[arr[0]] = arr[1]
})
return obj
}

var query = qs(location.search)
var localUrl = location.href
var route = query.route
var code = query.code

if (route) {
if (code) {
var decodedRoute = decodeURIComponent(route)
var href = ''
if (decodedRoute.indexOf('?') === -1) {
href = decodedRoute + '?code=' + code + '&state=' + query.state
} else {
href = decodedRoute + '&code=' + code + '&state=' + query.state
}
window.location.replace(href)
} else {
axios({
// auth/getLoginUrl
url: '',
method: '',
params: {
redirectUri: localUrl
}
}).then(function (res) {
window.location.href = res.data.data
})
}
}
</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: