放弃短信验证了

This commit is contained in:
2025-05-07 17:21:49 +08:00
parent 8039a3571d
commit 9570fb4524
7 changed files with 369 additions and 4 deletions

View File

@@ -1,4 +1,8 @@
import { Module } from '@nestjs/common';
import { NotificationService } from './notification.service';
@Module({})
@Module({
providers: [NotificationService],
exports: [NotificationService],
})
export class NotificationModule {}

View File

@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { NotificationService } from './notification.service';
describe('NotificationService', () => {
let service: NotificationService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [NotificationService],
}).compile();
service = module.get<NotificationService>(NotificationService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class NotificationService {
sendEmail(email: string, subject: string, content: string) {
}
/**
* @deprecated 短信签名暂未通过
*/
async sendSMS(phone: string, type: 'login', code: string) {
// const config = new $OpenApi.Config({
// accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
// accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
// })
// config.endpoint = 'dysmsapi.aliyuncs.com';
// const client = new Client(config);
// const request = new $dysmsapi.SendSmsRequest({});
// request.phoneNumbers = phone;
// request.signName = (() => {
// switch (type) {
// case 'login':
// return process.env.ALIYUN_SMS_LOGIN_SIGN_NAME;
// default:
// throw new Error('Unknown SMS type');
// }
// })();
// request.templateCode = code;
// await client.sendSms(request).then(a => {
// console.log(a)
// }).catch(err => {
// console.error(err);
// })
}
}

View File

@@ -1,10 +1,12 @@
import { Module } from '@nestjs/common';
import { VerificationController } from './verification.controller';
import { VerificationService } from './verification.service';
import { NotificationModule } from 'src/notification/notification.module';
@Module({
controllers: [VerificationController],
providers: [VerificationService],
exports: [VerificationService],
imports: [NotificationModule],
})
export class VerificationModule {}
export class VerificationModule { }

View File

@@ -1,8 +1,13 @@
import { Injectable } from '@nestjs/common';
import { NotificationService } from 'src/notification/notification.service';
@Injectable()
export class VerificationService {
constructor(
private readonly notificationService: NotificationService,
) { }
private pool: Map<string, {
code: string;
createdAt: number;
@@ -19,8 +24,7 @@ export class VerificationService {
// 生成验证码
const code = this.generateCode();
// 发送验证码
// TODO
// await this.notificationService.sendSMS(phone, type, code);
// 存储验证码
this.saveCode(key, code);
}