1.0.6 • Published 3 years ago

ali-sms-authenticate v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

ali-sms-authenticate

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

Installation

Install it and write into package.json .

$ npm install ali-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("ali-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>",
  //endpoint
  endpoint: "<endpoint>",
  //redis配置,单机或集群
  redisConfig: {
    redis_host: "127.0.0.1",
    redis_port: "6379",
    redis_auth: undefined,
    db: 1,
  },
  //短信最大填错数 默认5
  smsErrorNum: 5,
  //是否真实发送短信
  isSms: true,
  //短信默认值 (不真实发送短信情况下,默认值)
  smsDefultValue: "1234",
  //人机超时时间
  timeout: 3000,
  //验证码失效时间
  expireTime:300
});

// => returns Promise
aliAuthenticateSig.sendMessage({
  // 手机号码
  mobile: "<mobile>",
  //短信签名 - 可在短信控制台中找到
  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 : 阿里云验证失败
1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago