notadd 短信验证码插件
功能
- 短信插件管理
- 短信模板管理
- 短信发送记录管理
- 使用腾讯云短信服务发送短信验证码
- 校验验证码合法性
安装
yarn add @notadd/addon-sms
使用说明
第一步,导入短信插件
import { SmsAddon } from "@notadd/addon-sms";
@Module({
imports: [SmsAddon]
})
export class AppModule { }
第二步,创建短信插件
import { SmsService } from "@notadd/addon-sms";
@Injectable()
export class ExampleService {
constructor(
@Inject(SmsService) private readonly smsService: SmsService
) { }
async test() {
await this.smsService.createSms({
appId: '123456789',
appKey: 'zbcdefg123',
signName: '签名',
templates: [
{
templateId: 122334,
name: '短信测试',
remark: '您的验证码是{1},请于{2}分钟内填写。如非本人操作,请忽略本短信。'
}
]
});
}
}
第三步,调用发送/验证短信方法
import { SmsService } from "@notadd/addon-sms";
@Injectable()
export class ExampleService {
constructor(
@Inject(SmsService) private readonly smsService: SmsService
) { }
async sendSms(type: number, smsRequest: SmsRequest) {
await this.smsService.sendMessageByQCloud(type, smsRequest);
}
async smsValidator(mobile: string, validationCode: number) {
await this.smsService.smsValidator(mobile, validationCode);
}
}