微信小程序上传

This commit is contained in:
2026-07-12 14:45:57 +08:00
parent d271ac5b13
commit becf91da52
45 changed files with 1815 additions and 23 deletions
@@ -18,18 +18,24 @@ import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { AuthUser } from '../../common/guards/jwt-auth.guard';
import { ClientApp } from '@dukang/shared-types';
function resolveUserClientApp(req: Request): ClientApp {
const header = String(req.headers['x-client-app'] || '').trim();
if (header === ClientApp.USER_MINI) return ClientApp.USER_MINI;
return ClientApp.USER_H5;
}
@Controller()
export class UserAuthController {
constructor(private readonly authService: AuthService) {}
@Post('auth/session/bootstrap')
bootstrap(@Body() dto: BootstrapSessionDto) {
return this.authService.bootstrapSession(dto.deviceKey, ClientApp.USER_H5);
bootstrap(@Req() req: Request, @Body() dto: BootstrapSessionDto) {
return this.authService.bootstrapSession(dto.deviceKey, resolveUserClientApp(req));
}
@Post('auth/token/refresh')
refresh(@Body() dto: RefreshTokenDto) {
return this.authService.refreshAccessToken(dto.refreshToken, ClientApp.USER_H5);
refresh(@Req() req: Request, @Body() dto: RefreshTokenDto) {
return this.authService.refreshAccessToken(dto.refreshToken, resolveUserClientApp(req));
}
@Post('auth/sms/send')
@@ -39,7 +45,7 @@ export class UserAuthController {
const guestId = guest?.actorType === 'USER' ? guest.actorId : undefined;
return this.authService.sendSms(dto.phone, dto.scene, {
guestUserId: guestId,
clientApp: ClientApp.USER_H5,
clientApp: resolveUserClientApp(req),
});
}
@@ -48,13 +54,13 @@ export class UserAuthController {
login(@Req() req: Request, @Body() dto: LoginSmsDto) {
const guest = (req as Request & { user?: AuthUser }).user;
const guestId = guest?.actorType === 'USER' ? guest.actorId : undefined;
return this.authService.loginUser(dto.phone, dto.code, ClientApp.USER_H5, guestId);
return this.authService.loginUser(dto.phone, dto.code, resolveUserClientApp(req), guestId);
}
@Post('auth/phone/bind')
@UseGuards(JwtAuthGuard)
bindPhone(@CurrentUser() user: AuthUser, @Body() dto: BindPhoneDto) {
return this.authService.bindPhone(user.actorId, dto.phone, dto.code, ClientApp.USER_H5);
bindPhone(@Req() req: Request, @CurrentUser() user: AuthUser, @Body() dto: BindPhoneDto) {
return this.authService.bindPhone(user.actorId, dto.phone, dto.code, resolveUserClientApp(req));
}
@Post('auth/login/wechat')
@@ -62,32 +68,31 @@ export class UserAuthController {
wechatLogin(@Req() req: Request, @Body() dto: LoginWechatDto) {
const guest = (req as Request & { user?: AuthUser }).user;
const guestId = guest?.actorType === 'USER' ? guest.actorId : undefined;
return this.authService.loginUserWechat(
dto.code,
ClientApp.USER_H5,
dto.platform ?? 'h5',
guestId,
);
const clientApp = resolveUserClientApp(req);
const platform = dto.platform ?? (clientApp === ClientApp.USER_MINI ? 'mini' : 'h5');
return this.authService.loginUserWechat(dto.code, clientApp, platform, guestId);
}
@Post('auth/wechat/bind-phone')
bindPhoneLegacy(@Body() dto: BindWechatPhoneDto) {
bindPhoneLegacy(@Req() req: Request, @Body() dto: BindWechatPhoneDto) {
return this.authService.bindWechatPhone(
dto.wxSessionKey,
dto.phone,
dto.code,
ClientApp.USER_H5,
resolveUserClientApp(req),
);
}
@Post('auth/wechat/bind')
@UseGuards(JwtAuthGuard)
bindWechat(@CurrentUser() user: AuthUser, @Body() dto: BindWechatDto) {
bindWechat(@Req() req: Request, @CurrentUser() user: AuthUser, @Body() dto: BindWechatDto) {
const clientApp = resolveUserClientApp(req);
const platform = dto.platform ?? (clientApp === ClientApp.USER_MINI ? 'mini' : 'h5');
return this.authService.bindUserWechat(
user.actorId,
{ code: dto.code, wxSessionKey: dto.wxSessionKey },
ClientApp.USER_H5,
dto.platform ?? 'h5',
clientApp,
platform,
);
}