商铺端核销,调用相机报无效签名修复

This commit is contained in:
2026-07-07 17:55:12 +08:00
parent 5fef6ae2b1
commit 67eed11276
4 changed files with 54 additions and 5 deletions
@@ -75,13 +75,27 @@ export class WechatController {
@Get('jssdk-config')
async jssdkConfig(@Query('url') url: string, @Req() req: Request) {
if (!url) throw new BadRequestException('url 参数必填');
const pageUrl = decodeURIComponent(url).split('#')[0];
const decoded = decodeURIComponent(url).split('#')[0];
const pageUrl = this.normalizeJssdkUrl(decoded);
const user = (req as Request & { user?: AuthUser }).user;
const actorRef =
user?.actorType === 'USER' ? { refType: 'USER', refId: user.actorId } : undefined;
return this.wechat.createJssdkConfig(pageUrl, actorRef);
}
private normalizeJssdkUrl(rawUrl: string): string {
try {
const parsed = new URL(rawUrl);
parsed.hash = '';
parsed.searchParams.delete('code');
parsed.searchParams.delete('state');
const query = parsed.searchParams.toString();
return `${parsed.origin}${parsed.pathname}${query ? `?${query}` : ''}`;
} catch {
return rawUrl;
}
}
@Get('oauth-url')
oauthUrl(
@Query('redirectUri') redirectUri: string,