diff --git a/miniapp/utils/api.js b/miniapp/utils/api.js index a1adc82..4bf1a61 100644 --- a/miniapp/utils/api.js +++ b/miniapp/utils/api.js @@ -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', diff --git a/miniapp/utils/config.js b/miniapp/utils/config.js index 061f535..c0d7032 100644 --- a/miniapp/utils/config.js +++ b/miniapp/utils/config.js @@ -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,