diff --git a/utils/api-base-config.js b/utils/api-base-config.js index e8af668..18d7e80 100644 --- a/utils/api-base-config.js +++ b/utils/api-base-config.js @@ -6,6 +6,10 @@ export const CORP_API_BASE_URL_MAP = { wwa54dfba0b5441ef1: "https://crm.gykqyy.com/ykt/", }; +export const CORP_ID_ALIAS_MAP = { + "wpLgjyawAAeRkCPQMp9-z5q-xEzK64nA": "wwa54dfba0b5441ef1", +}; + function normalizeBaseUrl(url) { return String(url || "").replace(/\/+$/, ""); } @@ -14,6 +18,11 @@ function getDefaultBaseUrl() { return normalizeBaseUrl(env.MP_API_BASE_URL); } +export function normalizeCorpId(corpId) { + const normalizedCorpId = String(corpId || "").trim(); + return CORP_ID_ALIAS_MAP[normalizedCorpId] || normalizedCorpId; +} + function readCachedContext() { if (typeof uni === "undefined" || typeof uni.getStorageSync !== "function") { return null; @@ -75,12 +84,12 @@ function parseQueryString(queryString) { export function getCorpIdFromAppOptions(options = {}) { const query = options.query || options || {}; const corpId = query.corpId || query.corpid || query.corp_id; - if (corpId) return String(corpId).trim(); + if (corpId) return normalizeCorpId(corpId); if (typeof query.q === "string") { const qParams = parseQueryString(safeDecode(query.q)); const qCorpId = qParams.corpId || qParams.corpid || qParams.corp_id; - if (qCorpId) return String(qCorpId).trim(); + if (qCorpId) return normalizeCorpId(qCorpId); } return ""; @@ -93,7 +102,7 @@ export function initApiContextFromAppOptions(options = {}) { } export function resolveApiContext(corpId) { - const normalizedCorpId = String(corpId || "").trim(); + const normalizedCorpId = normalizeCorpId(corpId); if (normalizedCorpId) { const configuredBaseUrl = CORP_API_BASE_URL_MAP[normalizedCorpId]; diff --git a/utils/http.js b/utils/http.js index 6b2281a..7dcde85 100644 --- a/utils/http.js +++ b/utils/http.js @@ -1,5 +1,5 @@ import { loading, hideLoading } from "./widget"; -import { buildApiUrl, getDefaultUploadUrl } from "./api-base-config"; +import { buildApiUrl, getDefaultUploadUrl, normalizeCorpId } from "./api-base-config"; const defaultOptions = { header: { @@ -96,6 +96,12 @@ async function refreshAccessToken() { const request = async (options = {}, showLoading = true) => { // 合并用户传入的配置和默认配置 if (!options.data) options.data = {}; + if (options.data.corpId) { + options.data = { + ...options.data, + corpId: normalizeCorpId(options.data.corpId), + }; + } const config = { ...defaultOptions, @@ -201,12 +207,13 @@ export default request; export const uploadUrl = getDefaultUploadUrl(); export function getFullPath(path, corpId) { - return buildApiUrl(path, corpId); + return buildApiUrl(path, normalizeCorpId(corpId)); } export function upload(path, corpId) { - const currentUploadUrl = buildApiUrl("/upload", corpId); + const normalizedCorpId = normalizeCorpId(corpId); + const currentUploadUrl = buildApiUrl("/upload", normalizedCorpId); return new Promise((resolve) => { uni.uploadFile({ url: currentUploadUrl, @@ -216,7 +223,7 @@ export function upload(path, corpId) { success: (res) => { try { const url = JSON.parse(res.data).filePath; - resolve(url ? getFullPath(url, corpId) : '') + resolve(url ? getFullPath(url, normalizedCorpId) : '') } catch (e) { resolve() }