fix(miniapp): point API client at portal domain

This commit is contained in:
john
2026-07-11 09:32:33 +08:00
parent 0fd34a5644
commit b17b2f18cb
2 changed files with 16 additions and 2 deletions
+15 -1
View File
@@ -7,6 +7,14 @@ function setApiBaseUrl(value) {
apiBaseUrl = String(value || '').replace(/\/$/, '');
}
function getMiniProgramAppId() {
try {
return wx.getAccountInfoSync?.()?.miniProgram?.appId || '';
} catch {
return '';
}
}
function getStoredSession() {
const session = wx.getStorageSync(SESSION_KEY);
if (session && typeof session === 'object') {
@@ -70,7 +78,9 @@ function request(path, options = {}) {
const message =
res.data?.message ||
res.data?.error?.message ||
`请求失败 (${status || 'network'})`;
(status === 405
? `接口不支持当前请求方法,请检查 API_BASE_URL 是否指向 Portal 服务:${url}`
: `请求失败 (${status || 'network'})`);
const error = new Error(message);
error.status = status;
error.body = res.data;
@@ -123,6 +133,10 @@ function wxLogin() {
}
async function loginWithWechatCode(loginPath) {
const appId = getMiniProgramAppId();
if (!appId || appId === 'touristappid') {
throw new Error('当前是游客模式,微信一键登录需要在 project.config.json 配置真实小程序 AppID。');
}
const code = await wxLogin();
const result = await portalRequest(loginPath, {
method: 'POST',
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = {
API_BASE_URL: 'https://h5.tkmind.cn',
API_BASE_URL: 'https://m.tkmind.cn',
MINIAPP_LOGIN_PATH: '/auth/wechat-miniapp/login',
SELECTED_SESSION_KEY: 'tkmind_selected_session_id',
AGENT_RUN_POLL_MS: 1200,