项目作者: pkuvr

项目描述 :
rc-aliyun-sms is a nodejs sdk for aliyun sms service.
高级语言: JavaScript
项目地址: git://github.com/pkuvr/rc-aliyun-sms.git
创建时间: 2018-06-18T18:01:09Z
项目社区:https://github.com/pkuvr/rc-aliyun-sms

开源协议:

下载


Build Status

rc-aliyun-sms

rc-aliyun-sms 是阿里云短信服务SDK,使用redis过期机制验证短信验证码有效性。

支持功能

  • 发送短信验证码
  • 验证短信验证码有效性
  • 区分不同使用场景

安装

  1. npm i rc-aliyun-sms --save

接口

  • sendSmsCode 发送验证码
  • validateSmsCode 验证smscode有效性

使用方法

发送验证码

  1. const RcAliyunSms = require('rc-aliyun-sms');
  2. let sms = new RcAliyunSms(
  3. accessKeyID,
  4. accessKeySecret,
  5. {
  6. expire: 1800, //验证码有效时间(秒)
  7. redis: { //redis配置
  8. host: '127.0.0.1',
  9. port: 63790
  10. }
  11. }
  12. );
  13. let tplParams = JSON.stringify({code:"1234"});
  14. sms.sendSmsCode('手机号', '签名', '短信模板ID', tplParams, 场景ID)
  15. .then(res => {
  16. let o = JSON.parse(res);
  17. if (o.Code === 'OK' ) {
  18. //发送成功
  19. } else {
  20. //发送失败
  21. }
  22. })
  23. .catch(err => console.log(err));

验证有效性

  1. sms.validateSmsCode('手机号', '验证码', 场景ID)
  2. .then(res => {
  3. if (res) {
  4. //验证码合法
  5. }
  6. })
  7. .catch(err => console.log(err));