diff --git a/backend/services/identity-service/src/application/services/user-application.service.ts b/backend/services/identity-service/src/application/services/user-application.service.ts index 60e4b06a..1c417bec 100644 --- a/backend/services/identity-service/src/application/services/user-application.service.ts +++ b/backend/services/identity-service/src/application/services/user-application.service.ts @@ -483,7 +483,7 @@ export class UserApplicationService { // 发布用户资料更新事件 const event = new UserProfileUpdatedEvent({ - userId: account.id.value.toString(), + userId: account.userId.toString(), accountSequence: account.accountSequence.value, nickname: account.nickname, avatarUrl: account.avatarUrl, @@ -1296,17 +1296,17 @@ export class UserApplicationService { const phoneNumber = PhoneNumber.create(command.phoneNumber); - // 验证验证码 - const isValid = await this.smsService.verifySmsCode( - phoneNumber.value, - command.smsCode, - command.type, - ); + // 从 Redis 获取验证码进行验证 + const cacheKey = `sms:${command.type.toLowerCase()}:${phoneNumber.value}`; + const cachedCode = await this.redisService.get(cacheKey); - if (!isValid) { + if (!cachedCode || cachedCode !== command.smsCode) { throw new ApplicationError('验证码错误或已过期'); } + // 验证成功后删除验证码 + await this.redisService.delete(cacheKey); + this.logger.log(`SMS code verified successfully for phone: ${this.maskPhoneNumber(command.phoneNumber)}`); }