This commit is contained in:
@@ -325,14 +325,10 @@ export default {
|
||||
}
|
||||
|
||||
try {
|
||||
// 回调地址:基础地址 + action + device_id 参数(回调时保留)
|
||||
let redirectUri = config.authRedirectUri || (
|
||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||
const redirectUri = config.authRedirectUri || (
|
||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||
);
|
||||
redirectUri += (redirectUri.includes('?') ? '&' : '?') + 'action=userinfo';
|
||||
if (this.deviceId) {
|
||||
redirectUri += '&device_id=' + encodeURIComponent(this.deviceId);
|
||||
}
|
||||
|
||||
// 获取非静默授权链接(会弹窗确认)
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
@@ -343,8 +339,15 @@ export default {
|
||||
|
||||
const data = res.data || {};
|
||||
if (data.code === 0 && data.data && data.data.auth_url) {
|
||||
// 通过 state 传递 action 和 device_id(OAuth 标准保证 state 原样回传)
|
||||
const stateObj = { action: 'userinfo' };
|
||||
if (this.deviceId) {
|
||||
stateObj.device_id = this.deviceId;
|
||||
}
|
||||
let authUrl = data.data.auth_url;
|
||||
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + encodeURIComponent(JSON.stringify(stateObj));
|
||||
// 跳转微信授权页(弹窗确认)
|
||||
window.location.href = data.data.auth_url;
|
||||
window.location.href = authUrl;
|
||||
} else {
|
||||
console.warn('[index] 获取授权链接失败:', data.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user