import { CUSTOMER_SERVICE_PHONE, CUSTOMER_SERVICE_WECOM_URL } from '@dukang/shared-types'; import { fetchClientConfig } from './pay-wechat'; import { isWechatEnv } from './weixin'; let cachedPhone = CUSTOMER_SERVICE_PHONE; /** 企微客服链接:优先 Vite env,否则 shared-types 默认 */ export function getCustomerServiceWecomUrl(): string { const fromEnv = import.meta.env.VITE_CS_WECOM_URL?.trim(); return fromEnv || CUSTOMER_SERVICE_WECOM_URL; } export function getCustomerServicePhone(): string { return cachedPhone; } /** 从系统设置拉取客服电话(失败则保持默认常量) */ export async function loadCustomerServicePhone(): Promise { try { const cfg = await fetchClientConfig(); const phone = cfg.customerServicePhone?.trim(); if (phone) cachedPhone = phone; } catch { /* keep fallback */ } return cachedPhone; } /** * 打开企业微信客服会话(须在微信内;需用户点击手势)。 * @returns true 已跳转;false 非微信环境已提示 */ export function openWecomCustomerService(): boolean { if (!isWechatEnv()) { window.alert('请在微信中打开以联系在线客服'); return false; } window.location.href = getCustomerServiceWecomUrl(); return true; } /** @deprecated 请用 getCustomerServicePhone(),保留兼容旧引用 */ export { CUSTOMER_SERVICE_PHONE };