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

腾讯云信息查看

登录 - 腾讯云

相关推荐
烟雨空灵21 小时前
25 天做了个独立开发者作品橱窗,收录 340+ 件作品,代码全开源
前端·node.js
用户216076340831 天前
1200 个任务里,97 个还开着,0 个我能做
node.js
不要试图纠正别人1 天前
1055 个文件,共享 0 字节:pnpm 硬链接的静默降级
前端·node.js
吴名氏.2 天前
从零手写一个 AI Agent 框架(TypeScript 完整实现):Function Calling 循环、流式输出与错误恢复
人工智能·typescript·node.js·大模型·ai agent·functioncalling·llm 应用开发
关键词安全3 天前
PHP / Node.js / Go / Rust 全部中招(CVE-2026-109618、109619、111497、111943)完整排查与修复清单
golang·rust·node.js
zhensherlock4 天前
Protocol Launcher 系列:CodeHub 移动端 GitHub 协作利器
前端·javascript·typescript·node.js·自动化·github·js
jaysee-sjc4 天前
【黑马点评】Day02:优惠券秒杀与分布式锁
java·分布式·nginx·spring·node.js·tomcat·maven
ZhengEnCi5 天前
Express 企业级项目结构怎么组织:五层骨架、单向依赖和一份能跑的边界检查脚本
javascript·node.js·express
Dumbness5 天前
搜 platform 却给出 Form 表单:离线文档检索把短关键词当成了子串
javascript·node.js
用户216076340836 天前
一个 2 MB 的 .zst 文件,解压出来只有十几 KB
node.js