1.0.0 • Published 10 years ago

yunpian-sdk v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
10 years ago

YunPian SDK For Node.js

npm npm npm

云片注册地址: https://www.yunpian.com/component/reg?inviteCode=atevkh

Minimum, Flexible, Scalable.

支持Lazy Require。

Table of Contents generated with DocToc

安装和使用

国际惯例:

npm install yunpian-sdk --save

公共参数:

var options = {
  apikey: 'xxxxxxx'
};

ES7:

import {USER} from 'yunpian-sdk';
const user = new USER({
  apikey: 'xxxx'
});
// Within Async Func
(async() => {
  const result = await user.set({
    emergency_contact: 'Willin',
    emergency_mobile: '1xxxxxxxxxx'
  });
  // xxxx
});

ES5:

var YUNPIAN = require('yunpian-sdk');
// 加载全部方法
var user = new YUNPIAN.USER({
  apikey: 'xxxx'
});
// 或加载某些方法
var user = new YUNPIAN.USER({
  apikey: 'xxxx'
}, ['get', 'set']);
// 或加载某个方法
var user = new YUNPIAN.USER({
  apikey: 'xxxx'
}, 'get');
user.set({
  emergency_contact: 'Willin',
  emergency_mobile: '1xxxxxxxxxx'
}).then(function(result){
  // xxxx
});

手机号合法性校验

ES7 示例代码:

import {phone} from 'yunpian-sdk';

// 加区号匹配国际各国号码格式
phone('+8613312345678'); // true
phone('+85265698900'); // true
phone('+112345678'); // false

// 不加区号按中国号码匹配
phone('13312341234'); // true
phone('112345678'); // false

// 按地区匹配
// 地区码使用3位缩写国家代码(大写)
phone('+18175698900', 'USA'); // true
phone('13212345678', 'CHN'); // true
phone('+18175698900', 'CHN'); // false
phone('13212345678', 'HKG'); // false

ES5 示例代码:

var phone = require('yunpian-sdk').phone;

phone('+8613312345678'); // true
phone('13312341234'); // true
phone('13212345678', 'CHN'); // true

已支持的接口

USER - 账户API

API文档参考: https://www.yunpian.com/api2.0/user.html

ES7 示例:

import {USER} from 'yunpian-sdk';

const user = new USER({
  apikey: 'xxxx'
});

(async() => {
  const user = await user.get();
  // xxxx

  const result = await user.set({
    emergency_contact: 'Willin',
    emergency_mobile: '1xxxxxxxxxx'
  });
  // xxxx
})();

TPL - 模板API

API文档参考: https://www.yunpian.com/api2.0/tpl.html

SMS - 短信API

API文档参考: https://www.yunpian.com/api2.0/sms.html

ES7 示例:

import {SMS} from 'yunpian-sdk';

const sms = new SMS({
  apikey: 'xxxx'
});

(async() => {
  console.log(await sms.singleSend({
    mobile: 'xxxx',
    text: '【xxxx】您的验证码是:123456 (验证码10分钟内有效),请勿将验证码泄露给其他人。如非本人操作,请忽略本短信。'
  }));
})();

VOICE - 语音API

API文档参考: https://www.yunpian.com/api2.0/voice.html

FLOW - 流量API

API文档参考: https://www.yunpian.com/api2.0/flow.html

License

MIT

通过支付宝捐赠:

qr

1.0.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.3

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago