Node.js SDK
安装
Uni Node.js SDK 使用 npm 托管,可从公共 npm 仓库 中获得。
在项目中添加 unisms 作为依赖:
npm i unisms
或使用 Yarn:
yarn add unisms
使用示例
以下示例展示如何使用 Uni Node.js SDK 快速调用服务。
发送短信
import UniSMS from 'unisms' // 初始化 const client = new UniSMS ( { accessKeyId : 'your access key id' , accessKeySecret : 'your access key secret' , // 若使用简易验签模式请删除此行 } ) // 发送短信 client . send ( { to : 'your phone number' , signature : 'UniSMS' , templateId : 'login_tmpl' , templateData : { code : 8888 , } , } ) . then ( ret => { console . info ( 'Result:' , ret ) } ) . catch ( e => { console . error ( e ) } )
如若遇到以下报错:
SyntaxError: Cannot use import statement outside a module
或报错:
TypeError: UniSMS is not a constructor
可以调整引用的方式为:
// import UniSMS from 'unisms' const UniSMS = require ( 'unisms' ) . default