diff --git a/backend/services/identity-service/src/application/services/kyc-application.service.ts b/backend/services/identity-service/src/application/services/kyc-application.service.ts index 0714bfd6..e4312205 100644 --- a/backend/services/identity-service/src/application/services/kyc-application.service.ts +++ b/backend/services/identity-service/src/application/services/kyc-application.service.ts @@ -9,6 +9,8 @@ import { SmsService } from '@/infrastructure/external/sms/sms.service'; import { StorageService } from '@/infrastructure/external/storage/storage.service'; import { AliyunKycProvider } from '@/infrastructure/external/kyc/aliyun-kyc.provider'; import { ApplicationError } from '@/shared/exceptions/domain.exception'; +import { EventPublisherService } from '@/infrastructure/kafka/event-publisher.service'; +import { KYCVerifiedEvent } from '@/domain/events'; // KYC 综合状态枚举 export enum KycStatus { @@ -39,6 +41,7 @@ export class KycApplicationService { private readonly smsService: SmsService, private readonly storageService: StorageService, private readonly aliyunKycProvider: AliyunKycProvider, + private readonly eventPublisher: EventPublisherService, ) {} /** @@ -233,6 +236,7 @@ export class KycApplicationService { realNameVerified: true, kycStatus: true, phoneNumber: true, + accountSequence: true, }, }); @@ -303,6 +307,21 @@ export class KycApplicationService { this.logger.log(`[KYC] [Level1] Verification SUCCESS for user: ${userId}`); + // 发布 KYCVerified 事件,通知其他服务(如 planting-service) + try { + const verifiedAt = new Date(); + const event = new KYCVerifiedEvent({ + userId, + accountSequence: user.accountSequence, + verifiedAt, + }); + await this.eventPublisher.publish(event); + this.logger.log(`[KYC] [Level1] Published KYCVerified event for user: ${userId}, accountSequence: ${user.accountSequence}`); + } catch (eventError) { + // 事件发布失败不影响 KYC 结果,只记录日志 + this.logger.error(`[KYC] [Level1] Failed to publish KYCVerified event for user: ${userId}`, eventError); + } + return { success: true, level: 1,