{"id":20101620,"url":"https://github.com/sothx/egg-tencent-cloud-with-sms","last_synced_at":"2025-05-06T06:33:37.663Z","repository":{"id":57701081,"uuid":"496308380","full_name":"sothx/egg-tencent-cloud-with-sms","owner":"sothx","description":"Egg.js 腾讯云验证码插件","archived":false,"fork":false,"pushed_at":"2022-05-26T16:48:12.000Z","size":144,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T22:17:08.378Z","etag":null,"topics":["egg","egg-plugin","eggjs","plugins","sms"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sothx.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":"2022-05-25T16:25:35.000Z","updated_at":"2023-01-05T04:51:33.000Z","dependencies_parsed_at":"2022-08-29T05:30:33.282Z","dependency_job_id":null,"html_url":"https://github.com/sothx/egg-tencent-cloud-with-sms","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sothx%2Fegg-tencent-cloud-with-sms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sothx%2Fegg-tencent-cloud-with-sms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sothx%2Fegg-tencent-cloud-with-sms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sothx%2Fegg-tencent-cloud-with-sms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sothx","download_url":"https://codeload.github.com/sothx/egg-tencent-cloud-with-sms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252633921,"owners_count":21779945,"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":["egg","egg-plugin","eggjs","plugins","sms"],"created_at":"2024-11-13T17:26:00.259Z","updated_at":"2025-05-06T06:33:37.374Z","avatar_url":"https://github.com/sothx.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egg-tencent-cloud-with-sms\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-tencent-cloud-with-sms.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-tencent-cloud-with-sms\n[travis-image]: https://img.shields.io/travis/eggjs/egg-tencent-cloud-with-sms.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-tencent-cloud-with-sms\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-tencent-cloud-with-sms.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-tencent-cloud-with-sms?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-tencent-cloud-with-sms.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-tencent-cloud-with-sms\n[snyk-image]: https://snyk.io/test/npm/egg-tencent-cloud-with-sms/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-tencent-cloud-with-sms\n[download-image]: https://img.shields.io/npm/dm/egg-tencent-cloud-with-sms.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-tencent-cloud-with-sms\n\n\u003c!--\nDescription here.\n--\u003e\n\n## 依赖说明\n\n### 依赖的 egg 版本\n\negg-tencent-cloud-with-sms 版本 | egg 1.x\n--- | ---\n1.x | 😁\n0.x | ❌\n\n\n## 安装插件\n\n```bash\n# use npm\n$ npm i egg-tencent-cloud-with-sms --save\n# use yarn\n$ yarn add egg-tencent-cloud-with-sms\n```\n\n## 开启插件\n\n```js\n// {app_root}/config/plugin.js\nexports.tencentCloudSms = {\n  enable: true,\n  package: 'egg-tencent-cloud-with-sms',\n};\n```\n\n## 使用场景\n\n- 可以使 Egg.js 快速集成腾讯云短信\n\n- 使用更现代的 Promise 或 Async/Await 的方式来调用\n\n\n## 详细配置\n\n### 插件配置\n\n```js\n// {app_root}/config/config.default.js\nexports.tencentCloudSms = {\n    client: {\n      // 短信应用AppID,SmsSdkAppId的简写，实例方法没传入AppID的情况下会取全局的AppID作为SmsSdkAppId的值。\n      AppID: '1234567890',\n      /* 必填：腾讯云账户密钥对secretId，secretKey。\n      * 这里采用的是从环境变量读取的方式，需要在环境变量中先设置这两个值。\n      * 你也可以直接在代码中写死密钥对，但是小心不要将代码复制、上传或者分享给他人，\n      * 以免泄露密钥对危及你的财产安全。\n      * SecretId、SecretKey 查询: https://console.cloud.tencent.com/cam/capi */\n      credential: {\n        secretId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',\n        secretKey: 'yyyyyyyyyyyyyyyyyyyyyyyy',\n      },\n  }\n};\n```\n\n### 插件方法\n\n```js\n// 发送短信\nthis.app.tencentCloudSms.SendSms({\n          /* 短信签名内容: 使用 UTF-8 编码，必须填写已审核通过的签名 */\n        // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看\n        SignName: 'xxxxx', // 必填\n        /* 短信应用ID: 短信SmsSdkAppId在 [短信控制台] 添加应用后生成的实际SmsSdkAppId，示例如1400006666 */\n        // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看\n        AppID: '1234567890', //(可选) SmsSdkAppId的值，不配置则取默认配置的AppID作为值\n         /* 模板 ID: 必须填写已审核通过的模板 ID */\n        // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看\n        TemplateId: '1234567',  // 必填\n        /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致，若无模板参数，则设置为空 */\n        TemplateParamSet: ['2223','5'], // 必填\n        /* 下发手机号码，采用 e.164 标准，+[国家或地区码][手机号]\n        * 示例如：+8613711112222， 其中前面有一个+号 ，86为国家码，13711112222为手机号，最多不要超过200个手机号*/\n        PhoneNumberSet: ['+86159123456789'] // 必填，需要发送的短信的手机号集合\n})\n```\n\n```js\n  // 拉取回执状态\nthis.app.tencentCloudSms.PullSmsSendStatus({\n  // 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId，示例如1400006666\n  AppID: \"1234567890\",\n  // 拉取最大条数，最多100条\n  Limit: 10,\n})\n```\n\n```js\n  // 统计短信发送数据\nthis.app.tencentCloudSms.SendStatusStatistics({\n    // 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId，示例如1400006666\n    AppID: \"1234567890\",\n    // 拉取最大条数，最多100条\n    Limit: 10,\n    // 偏移量 注：目前固定设置为0\n    Offset: 0,\n    // 开始时间，yyyymmddhh 需要拉取的起始时间，精确到小时\n    BeginTime: \"2019122400\",\n    // 结束时间，yyyymmddhh 需要拉取的截止时间，精确到小时\n    // 注：EndTime 必须大于 BeginTime\n    EndTime: \"2019122523\",\n})\n\n```\n\n```js\n  // 申请短信模板\nthis.app.tencentCloudSms.AddSmsTemplate({\n  /* 模板名称 */\n  TemplateName: \"腾讯云\",\n  /* 模板内容 */\n  TemplateContent: \"{1}为您的登录验证码，请于{2}分钟内填写，如非本人操作，请忽略本短信。\",\n  /* 短信类型：0表示普通短信, 1表示营销短信 */\n  SmsType: 0,\n  /* 是否国际/港澳台短信：0：表示国内短信; 1：表示国际/港澳台短信 */\n  International: 0,\n  /* 模板备注：例如申请原因，使用场景等 */\n  Remark: \"xxx\",\n})\n```\n\n请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。\n\n## 代码示例\n\n```js\n// 向用户发送短信\n  async sendSMS() {\n    const ctx = this.ctx;\n    let sendSmsResponse\n    try {\n      sendSmsResponse = await this.app.tencentCloudSms.SendSms({\n        /* 短信签名内容: 使用 UTF-8 编码，必须填写已审核通过的签名 */\n        // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看\n        SignName: 'xxxxx', // 必填\n        /* 短信应用ID: 短信SmsSdkAppId在 [短信控制台] 添加应用后生成的实际SmsSdkAppId，示例如1400006666 */\n        // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看\n        AppID: '1234567890', //(可选) SmsSdkAppId的值，不配置则取默认配置的AppID作为值\n         /* 模板 ID: 必须填写已审核通过的模板 ID */\n        // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看\n        TemplateId: '1234567',  // 必填\n        /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致，若无模板参数，则设置为空 */\n        TemplateParamSet: ['2223','5'], // 必填\n        /* 下发手机号码，采用 e.164 标准，+[国家或地区码][手机号]\n        * 示例如：+8613711112222， 其中前面有一个+号 ，86为国家码，13711112222为手机号，最多不要超过200个手机号*/\n        PhoneNumberSet: ['+8615912345678'] // 必填，需要发送的短信的手机号集合\n      })\n    } catch (err) {\n      sendSmsResponse = err\n      console.log(err, 'err')\n    }\n    ctx.status = 200;\n    ctx.body = sendSmS;\n  }\n```\n\n## 提问 \u0026 支持\n\nPlease open an issue [here](https://github.com/sothx/egg-tencent-cloud-with-sms/issues).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsothx%2Fegg-tencent-cloud-with-sms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsothx%2Fegg-tencent-cloud-with-sms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsothx%2Fegg-tencent-cloud-with-sms/lists"}