cool框架 node.js 实现 腾讯云短信

1.现在想实现node 后端 实现腾讯云验证码的功能

去腾讯云上下载了node.js sdk 下载了以后 发现不能使用 问了问客服 说是 sdk有问题

2.qcloudsms_js 插件的使用 腾讯短信

(1). 安装

复制代码
npm i qcloudsms_js -save

(2)主题代码使用

复制代码
import { Config, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import * as request from 'request';
const QCloudSms = require('qcloudsms_js');
/**
 * 抖音接口封装
 */
@Provide()
export class SendSesService extends BaseService {
  @Config('module.business')
  businessConfig;

  //发送验证码
  sendVerificationCode(query) {
    // 1323418546;
    const config = {
      appid: 'xxxxx', //sdk app 应用ID
      appkey: 'xxxx', // sdk 
    };
    const smsSign = 'xxx'; // 短信签名
    const templateId = 'xxxx'; // 短信模板ID
    const phoneNumber = [query.phone]; // 手机号数组
    var qcloudsms = QCloudSms(config.appid, config.appkey);

    const params = [];

    params[0] = Math.floor(Math.random() * 900000 + 100000).toString(); // 生成4位随机验证码
    // params[1]=

    // const paramsQuery = `您的动态验证码为:${params},为保障帐户安全,请勿向任何人提供此验证码。`;
    const ssender = qcloudsms.SmsSingleSender();
    return new Promise(function (resolve, reject) {
      // // 签名参数未提供或者为空时,会使用默认签名发送短信
      ssender.sendWithParam(
        '86',
        phoneNumber,
        templateId,
        params,
        smsSign,
        '',
        '',
        function (err, res, resData) {
          if (err) {
            reject(err); //发送失败
          } else {
            //所有短信全部认定发送成功
            // console.log('request data: ', res.req);
            console.log('response data: ', resData);
            //这里再把信息响应给客户端,方便逻辑判断
            resolve(resData);
          }
        }
      );
    });

    // return smsProvider.multiSend(
    //   params,
    //   phoneNumber,
    //   templateId,
    //   '',
    //   '',
    //   smsSign
    // );
  }
}

大概就是这个代码了

  1. 扩展

如果 不太清楚这个插件

qcloudsms_js - npm

腾讯云信息查看

登录 - 腾讯云

相关推荐
木头左19 小时前
【浏览器自动化】用 CDP 接管本机 Chrome:从一个宿主迁到另一个宿主的设计与踩坑
node.js·浏览器自动化·cdp·技能化·踩坑实践
cpolar技术支持1 天前
把 agent-autoloop 装在 Mac 上:用本机 Node 实跑一次「接活—提问—拍板—接着干」,再用 cpolar 把它的状态页开给不在工位的自己
node.js·内网穿透·cpolar·ai agent·agent-autoloop
SEO_juper2 天前
Node.js 全站 SEO 体检报告生成器:一次查完标题、描述、canonical、H1、图片
开发语言·前端·node.js·html·bash
66IT662 天前
Veeam ONE v13.1 发布:全新 HTML5 Web 客户端与 PostgreSQL 报告库
云计算·虚拟化·监控·数据保护·veeam
2601_967980113 天前
Python 与云计算:AWS、GCP、Azure 实践
python·云计算·azure·aws·gcp
木头左3 天前
【Node.js】Markdown 转带图片 Word 文档实战:docx 库转换器设计与 5 个踩坑
node.js·word·markdown·文档自动化
思特奇时空智能3 天前
大规模点要素地图渲染性能优化实践
vue.js·arcgis·性能优化·node.js·html·gis·webgl
cc5725026533 天前
云计算技术应用专业大学期间考证怎么安排?
云计算
xbzb5 天前
镜像推上云:华为云 SWR 与阿里云 ACR 的建组织、加速器、上传与公开
阿里云·华为云·云计算·镜像·acr·swr