alipay-sms-authenticate

1.0.4 • Public • Published

alipay-sms-authenticate

#通过阿里或极光 sdk 发送短信,并且进行人机校验

Installation

Install it and write into package.json .

$ npm install alipay-sms-authenticate -S

Prerequisite

Node.js >= 8.x

Notes

You must know your AK(accessKeyId/accessKeySecret), and the cloud product's endpoint and apiVersion.

For example, The ECS OpenAPI(https://help.aliyun.com/document_detail/25490.html), the API version is 2014-05-26.

And the endpoint list can be found at here, the center endpoint is ecs.aliyuncs.com. Add http protocol http or https, should be http://ecs.aliyuncs.com/.

Usage

let AliAuthenticateSig = require("alipay-sms-authenticate");

let aliAuthenticateSig = new AliAuthenticateSig({
  //使用场景标识。在统计报表中将根据该字段的内容进行分类展示。及缓存前缀
  SCENE: "sms_h5_scene",
  //客户端IP
  REMOTE_IP: "127.0.0.1",
  //阿里人机验证配置对应的appkey。
  APP_KEY: "<APP_KEY>",
  //accessKeyId 阿里(短信+人机)
  accessKeyId: "<accessKeyId>",
  //secretAccessKey (短信+人机)
  secretAccessKey: "<secretAccessKey>",
  //极光短信appkey  极光短信时使用
  jg_appKey: "<accessKeyId>", 
  //极光短信secret  极光短信时使用
  jg_masterSecret: "<secretAccessKey>", 
  //endpoint
  endpoint: "<endpoint>",
  //redis配置,单机或集群
  redisConfig: {
    redis_host: "127.0.0.1",
    redis_port: "6379",
    redis_auth: undefined,
    db: 1,
  },
  //短信最大填错数 默认5
  smsErrorNum: 5,
  //是否真实发送短信
  isSms: true,
  //第三方短信使用平台 JG:极光,ALI:阿里
  SMS_TYPE:"JG",
  //短信默认值 (不真实发送短信情况下,默认值)
  smsDefultValue: "1234",
  //人机超时时间
  timeout: 3000,
  //验证码失效时间
  expireTime:300
});

// => returns Promise
aliAuthenticateSig.sendMessage({
  // 手机号码
  mobile: "<mobile>",
  //smsType 短信第三方 JG 、ALI(极光、阿里)
  smsType:"<smsType>",
  //短信签名 - 可在短信控制台中找到
  signName: "<sinName>",
  //必填: 短信模板
  templateCode: "<templateCode>",
  //前端上传sessionId
  sessionId:"<sessionId>",
  //前端上传token
  token: "<token>",
  //前端上传sig
  sig:"<sig>",
});

// => returns Promise
aliAuthenticateSig.checkedMessage(
  //手机号
  "mobile",
  //验证码
  "code"
)
## 错误码
{
  //错误码
  code:0,
  //消息
  msg:""
}
0 :成功

1000 : 参数错误

1001 : 验证码发送失败

1002 : 验证码发送次数超限,请在${1}分钟后重新发送。

1003 : 验证码发送次数超限,请稍后再试

1004 : 今日验证码发送次数超限,请明日再试

1005 : 验证码错误

1006 : 阿里云验证失败

Readme

Keywords

none

Package Sidebar

Install

npm i alipay-sms-authenticate

Weekly Downloads

5

Version

1.0.4

License

ISC

Unpacked Size

24.7 kB

Total Files

10

Last publish

Collaborators

  • lionzhu