26 lines
857 B
TypeScript
26 lines
857 B
TypeScript
import { resolveAdminApiPath } from '@/utils/adminApi';
|
|
|
|
/**
|
|
* 将微信 mp.weixin.qq.com/showqrcode 转为同源代理地址。
|
|
* 微信内长按跨域图常需多次才识别成功;同源 img 可明显提高一次识别率。
|
|
*/
|
|
export function resolveWechatShowQrDisplayUrl(url: string): string {
|
|
const raw = String(url || '').trim();
|
|
if (!raw) return '';
|
|
|
|
try {
|
|
const parsed = new URL(raw, typeof window !== 'undefined' ? window.location.origin : 'https://local');
|
|
const isWechatShow =
|
|
parsed.hostname.includes('mp.weixin.qq.com') &&
|
|
parsed.pathname.includes('showqrcode');
|
|
if (!isWechatShow) return raw;
|
|
|
|
const ticket = parsed.searchParams.get('ticket');
|
|
if (!ticket) return raw;
|
|
|
|
return resolveAdminApiPath(`/wechat/mp/showqrcode?ticket=${encodeURIComponent(ticket)}`);
|
|
} catch {
|
|
return raw;
|
|
}
|
|
}
|