{"id":22125424,"url":"https://github.com/notadd/nt-addon-sms","last_synced_at":"2025-07-25T15:32:26.528Z","repository":{"id":57131980,"uuid":"134594313","full_name":"notadd/nt-addon-sms","owner":"notadd","description":"Notadd 短信服务插件，目前仅支持腾讯云","archived":false,"fork":false,"pushed_at":"2019-05-17T21:21:00.000Z","size":391,"stargazers_count":3,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-24T14:30:10.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/notadd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-23T16:02:34.000Z","updated_at":"2019-05-16T01:15:42.000Z","dependencies_parsed_at":"2022-09-03T07:03:15.392Z","dependency_job_id":null,"html_url":"https://github.com/notadd/nt-addon-sms","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notadd%2Fnt-addon-sms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notadd%2Fnt-addon-sms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notadd%2Fnt-addon-sms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notadd%2Fnt-addon-sms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notadd","download_url":"https://codeload.github.com/notadd/nt-addon-sms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227590941,"owners_count":17790560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T16:20:51.190Z","updated_at":"2024-12-01T16:20:51.842Z","avatar_url":"https://github.com/notadd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# notadd 短信验证码插件\n\n## 功能\n\n1. 短信插件管理\n2. 短信模板管理\n3. 短信发送记录管理\n4. 使用腾讯云短信服务发送短信验证码\n5. 校验验证码合法性\n\n## 安装\n\n```bash\n# install\nyarn add @notadd/addon-sms\n```\n\n## 使用说明\n\n\u003e 第一步，导入短信插件\n\n```typescript\nimport { SmsAddon } from \"@notadd/addon-sms\";\n\n@Module({\n    imports: [SmsAddon]\n})\nexport class AppModule { }\n```\n\n\u003e 第二步，创建短信插件\n\n```typescript\nimport { SmsService } from \"@notadd/addon-sms\";\n\n@Injectable()\nexport class ExampleService {\n    constructor(\n        @Inject(SmsService) private readonly smsService: SmsService\n    ) { }\n\n    // 创建/配置短信插件\n    async test() {\n        await this.smsService.createSms({\n            appId: '123456789',\n            appKey: 'zbcdefg123',\n            signName: '签名',\n            templates: [\n                {\n                    templateId: 122334,\n                    name: '短信测试',\n                    remark: '您的验证码是{1}，请于{2}分钟内填写。如非本人操作，请忽略本短信。'\n                }\n            ]\n        });\n    }\n}\n```\n\n\u003e 第三步，调用发送/验证短信方法\n\n```typescript\nimport { SmsService } from \"@notadd/addon-sms\";\n\n@Injectable()\nexport class ExampleService {\n    constructor(\n        @Inject(SmsService) private readonly smsService: SmsService\n    ) { }\n\n    // SmsRequest example：(2 , { appId: \"1234567890\", templateId: 123456, templateParam: [\"xxxxx\", \"xxxxx\"], \"mobile\": [\"13512345678\"] })\n    async sendSms(type: number, smsRequest: SmsRequest) {\n        // 短信类型 0为通知短信，1为验证码短信，2为自定义参数短信\n        // 成功时返回 { code: 200, message: \"发送短信成功\" };\n        //\n        // 失败时会抛出以下几种异常：\n        // HttpException (`指定短信插件'appId=xxxxx'不存在`, 404);\n        // HttpException (`指定短信模板'templateId=xxxxx'不存在`, 404);\n        // HttpException (`发送失败，原因：xxxxx`, xxxxx);\n        await this.smsService.sendMessageByQCloud(type, smsRequest);\n    }\n\n    async smsValidator(mobile: string, validationCode: number) {\n        // 校验验证码合法性，成功时没有返回值，失败时抛出 HttpException { code: number, message: string }\n        //\n        // 校验顺序：\n        // step 1，判断手机号是否和接收短信手机号一致，失败时： HttpException (\"输入的手机号码与接收短信的手机号码不一致\", 404);\n        // step 2，判断验证码是否正确，失败时： HttpException (\"验证码错误\", 406);\n        // step 3，判断验证码是否超时，失败时： HttpException (\"验证超时，请重新获取验证码\", 408);\n        await this.smsService.smsValidator(mobile, validationCode);\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotadd%2Fnt-addon-sms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotadd%2Fnt-addon-sms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotadd%2Fnt-addon-sms/lists"}