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

egg-tencent-cloud-with-sms

v1.0.1

Published

[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down

Downloads

4

Readme

egg-tencent-cloud-with-sms

NPM version build status Test coverage David deps Known Vulnerabilities npm download

依赖说明

依赖的 egg 版本

egg-tencent-cloud-with-sms 版本 | egg 1.x --- | --- 1.x | 😁 0.x | ❌

安装插件

# use npm
$ npm i egg-tencent-cloud-with-sms --save
# use yarn
$ yarn add egg-tencent-cloud-with-sms

开启插件

// {app_root}/config/plugin.js
exports.tencentCloudSms = {
  enable: true,
  package: 'egg-tencent-cloud-with-sms',
};

使用场景

  • 可以使 Egg.js 快速集成腾讯云短信

  • 使用更现代的 Promise 或 Async/Await 的方式来调用

详细配置

插件配置

// {app_root}/config/config.default.js
exports.tencentCloudSms = {
    client: {
      // 短信应用AppID,SmsSdkAppId的简写,实例方法没传入AppID的情况下会取全局的AppID作为SmsSdkAppId的值。
      AppID: '1234567890',
      /* 必填:腾讯云账户密钥对secretId,secretKey。
      * 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。
      * 你也可以直接在代码中写死密钥对,但是小心不要将代码复制、上传或者分享给他人,
      * 以免泄露密钥对危及你的财产安全。
      * SecretId、SecretKey 查询: https://console.cloud.tencent.com/cam/capi */
      credential: {
        secretId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
        secretKey: 'yyyyyyyyyyyyyyyyyyyyyyyy',
      },
  }
};

插件方法

// 发送短信
this.app.tencentCloudSms.SendSms({
          /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
        // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
        SignName: 'xxxxx', // 必填
        /* 短信应用ID: 短信SmsSdkAppId在 [短信控制台] 添加应用后生成的实际SmsSdkAppId,示例如1400006666 */
        // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
        AppID: '1234567890', //(可选) SmsSdkAppId的值,不配置则取默认配置的AppID作为值
         /* 模板 ID: 必须填写已审核通过的模板 ID */
        // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
        TemplateId: '1234567',  // 必填
        /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
        TemplateParamSet: ['2223','5'], // 必填
        /* 下发手机号码,采用 e.164 标准,+[国家或地区码][手机号]
        * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
        PhoneNumberSet: ['+86159123456789'] // 必填,需要发送的短信的手机号集合
})
  // 拉取回执状态
this.app.tencentCloudSms.PullSmsSendStatus({
  // 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666
  AppID: "1234567890",
  // 拉取最大条数,最多100条
  Limit: 10,
})
  // 统计短信发送数据
this.app.tencentCloudSms.SendStatusStatistics({
    // 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666
    AppID: "1234567890",
    // 拉取最大条数,最多100条
    Limit: 10,
    // 偏移量 注:目前固定设置为0
    Offset: 0,
    // 开始时间,yyyymmddhh 需要拉取的起始时间,精确到小时
    BeginTime: "2019122400",
    // 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时
    // 注:EndTime 必须大于 BeginTime
    EndTime: "2019122523",
})
  // 申请短信模板
this.app.tencentCloudSms.AddSmsTemplate({
  /* 模板名称 */
  TemplateName: "腾讯云",
  /* 模板内容 */
  TemplateContent: "{1}为您的登录验证码,请于{2}分钟内填写,如非本人操作,请忽略本短信。",
  /* 短信类型:0表示普通短信, 1表示营销短信 */
  SmsType: 0,
  /* 是否国际/港澳台短信:0:表示国内短信; 1:表示国际/港澳台短信 */
  International: 0,
  /* 模板备注:例如申请原因,使用场景等 */
  Remark: "xxx",
})

请到 config/config.default.js 查看详细配置项说明。

代码示例

// 向用户发送短信
  async sendSMS() {
    const ctx = this.ctx;
    let sendSmsResponse
    try {
      sendSmsResponse = await this.app.tencentCloudSms.SendSms({
        /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
        // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
        SignName: 'xxxxx', // 必填
        /* 短信应用ID: 短信SmsSdkAppId在 [短信控制台] 添加应用后生成的实际SmsSdkAppId,示例如1400006666 */
        // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
        AppID: '1234567890', //(可选) SmsSdkAppId的值,不配置则取默认配置的AppID作为值
         /* 模板 ID: 必须填写已审核通过的模板 ID */
        // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
        TemplateId: '1234567',  // 必填
        /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
        TemplateParamSet: ['2223','5'], // 必填
        /* 下发手机号码,采用 e.164 标准,+[国家或地区码][手机号]
        * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
        PhoneNumberSet: ['+8615912345678'] // 必填,需要发送的短信的手机号集合
      })
    } catch (err) {
      sendSmsResponse = err
      console.log(err, 'err')
    }
    ctx.status = 200;
    ctx.body = sendSmS;
  }

提问 & 支持

Please open an issue here.

License

MIT