2023-06-25 15:30:18 +08:00
|
|
|
import { Rule, RuleType } from '@midwayjs/validate';
|
2023-01-29 15:26:58 +08:00
|
|
|
import { ALL, Inject } from '@midwayjs/decorator';
|
|
|
|
|
import { Body } from '@midwayjs/decorator';
|
|
|
|
|
import { Controller, Post, Provide } from '@midwayjs/decorator';
|
|
|
|
|
import { BaseController } from '../../../basic/base-controller';
|
|
|
|
|
import { CodeService } from '../service/code-service';
|
2023-06-25 15:30:18 +08:00
|
|
|
import { EmailService } from '../service/email-service';
|
2023-01-29 15:26:58 +08:00
|
|
|
export class SmsCodeReq {
|
|
|
|
|
@Rule(RuleType.number().required())
|
|
|
|
|
phoneCode: number;
|
|
|
|
|
|
|
|
|
|
@Rule(RuleType.string().required())
|
|
|
|
|
mobile: string;
|
|
|
|
|
|
|
|
|
|
@Rule(RuleType.string().required().max(10))
|
|
|
|
|
randomStr: string;
|
|
|
|
|
|
|
|
|
|
@Rule(RuleType.number().required().max(4))
|
|
|
|
|
imgCode: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
2023-06-25 15:30:18 +08:00
|
|
|
@Controller('/api/basic/code')
|
2023-01-29 15:26:58 +08:00
|
|
|
export class BasicController extends BaseController {
|
|
|
|
|
@Inject()
|
|
|
|
|
codeService: CodeService;
|
2023-06-25 15:30:18 +08:00
|
|
|
|
|
|
|
|
@Inject()
|
|
|
|
|
emailService: EmailService;
|
|
|
|
|
|
2023-01-29 15:26:58 +08:00
|
|
|
@Post('/sendSmsCode')
|
|
|
|
|
public sendSmsCode(
|
|
|
|
|
@Body(ALL)
|
|
|
|
|
body: SmsCodeReq
|
|
|
|
|
) {
|
|
|
|
|
// 设置缓存内容
|
|
|
|
|
return this.ok(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/captcha')
|
|
|
|
|
public async getCaptcha(
|
|
|
|
|
@Body()
|
|
|
|
|
randomStr
|
|
|
|
|
) {
|
|
|
|
|
console.assert(randomStr < 10, 'randomStr 过长');
|
|
|
|
|
const captcha = await this.codeService.generateCaptcha(randomStr);
|
|
|
|
|
return this.ok(captcha.data);
|
|
|
|
|
}
|
|
|
|
|
}
|