Compare commits

...

1 Commits

Author SHA1 Message Date
kk 925ebe9bb9 post请求用户授权信息
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 42s
2026-07-11 11:59:09 +08:00
2 changed files with 31 additions and 6 deletions
+19 -4
View File
@@ -105,8 +105,14 @@ export default {
let authUrl = data.data.auth_url;
if (this.deviceId) {
const stateVal = encodeURIComponent(JSON.stringify({ device_id: this.deviceId }));
try {
const urlObj = new URL(authUrl);
urlObj.searchParams.set('state', stateVal);
authUrl = urlObj.toString();
} catch (_) {
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
}
}
// 跳转微信授权页(静默,不弹窗)
window.location.href = authUrl;
} else {
@@ -233,8 +239,15 @@ export default {
if (this.deviceId) {
stateObj.device_id = this.deviceId;
}
const stateVal = encodeURIComponent(JSON.stringify(stateObj));
let authUrl = data.data.auth_url;
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + encodeURIComponent(JSON.stringify(stateObj));
try {
const urlObj = new URL(authUrl);
urlObj.searchParams.set('state', stateVal);
authUrl = urlObj.toString();
} catch (_) {
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
}
// 跳转微信授权页(弹窗确认)
window.location.href = authUrl;
} else {
@@ -269,14 +282,16 @@ export default {
url.searchParams.delete('action');
window.history.replaceState({}, '', url.toString());
// 用 code 调用 /api/v1/user/info 获取用户信息
const res = await gatewayGet('/api/v1/user/info', {
// 用 code 调用 POST /api/v1/user/info 获取用户信息(必须用 POST,GET 是另一个端点)
console.log('[loading] 请求 POST user/info, app_no:', appNo, 'code:', code);
const res = await gatewayPost('/api/v1/user/info', {
app_no: appNo,
code: code,
});
const data = res.data || {};
console.log('[loading] user info response:', JSON.stringify(data, null, 2));
console.log('[loading] user/info response:', JSON.stringify(data, null, 2));
console.log('[loading] user/info statusCode:', res.statusCode);
if (data.code === 0 && data.data) {
const userInfo = data.data;
+11 -1
View File
@@ -344,8 +344,18 @@ export default {
if (this.deviceId) {
stateObj.device_id = this.deviceId;
}
const stateVal = encodeURIComponent(JSON.stringify(stateObj));
// 解析 auth_url,安全地设置 state 参数(避免重复)
let authUrl = data.data.auth_url;
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + encodeURIComponent(JSON.stringify(stateObj));
try {
const urlObj = new URL(authUrl);
urlObj.searchParams.set('state', stateVal);
authUrl = urlObj.toString();
} catch (_) {
// URL 解析失败时直接拼接
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
}
console.log('[index] 跳转授权页:', authUrl);
// 跳转微信授权页(弹窗确认)
window.location.href = authUrl;
} else {