npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@notadd/addon-sms

v3.0.0

Published

The sms addon for notadd application.

Downloads

53

Readme

notadd 短信验证码插件

功能

  1. 短信插件管理
  2. 短信模板管理
  3. 短信发送记录管理
  4. 使用腾讯云短信服务发送短信验证码
  5. 校验验证码合法性

安装

# install
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
    ) { }

    // SmsRequest example:(2 , { appId: "1234567890", templateId: 123456, templateParam: ["xxxxx", "xxxxx"], "mobile": ["13512345678"] })
    async sendSms(type: number, smsRequest: SmsRequest) {
        // 短信类型 0为通知短信,1为验证码短信,2为自定义参数短信
        // 成功时返回 { code: 200, message: "发送短信成功" };
        //
        // 失败时会抛出以下几种异常:
        // HttpException (`指定短信插件'appId=xxxxx'不存在`, 404);
        // HttpException (`指定短信模板'templateId=xxxxx'不存在`, 404);
        // HttpException (`发送失败,原因:xxxxx`, xxxxx);
        await this.smsService.sendMessageByQCloud(type, smsRequest);
    }

    async smsValidator(mobile: string, validationCode: number) {
        // 校验验证码合法性,成功时没有返回值,失败时抛出 HttpException { code: number, message: string }
        //
        // 校验顺序:
        // step 1,判断手机号是否和接收短信手机号一致,失败时: HttpException ("输入的手机号码与接收短信的手机号码不一致", 404);
        // step 2,判断验证码是否正确,失败时: HttpException ("验证码错误", 406);
        // step 3,判断验证码是否超时,失败时: HttpException ("验证超时,请重新获取验证码", 408);
        await this.smsService.smsValidator(mobile, validationCode);
    }
}