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