FILEEM

POWER OF DREAM

阿里云短信服务Node.js调用

安装

cnpm install @alicloud/pop-core -S --save

发送短信

const Core = require('@alicloud/pop-core');

var client = new Core({
  accessKeyId: '<accessKeyId>',
  accessKeySecret: '<accessSecret>',
  endpoint: 'https://dysmsapi.aliyuncs.com',
  apiVersion: '2017-05-25'
});

var params = {
  "PhoneNumbers": "1503871****",
  "SignName": "测试专用",
  "TemplateCode": "SMS_209335004",
  "TemplateParam": "{\"code\":\"1111\"}"
}

var requestOption = {
  method: 'POST'
};

client.request('SendSms', params, requestOption).then((result) => {
  console.log(JSON.stringify(result));
}, (ex) => {
  console.log(ex);
})

结果:

{  "RequestId": "614048FB-0619-4439-A1D5-AA8B218A****",  "Message": "OK",  "BizId": "386715418801811068^0",  "Code": "OK"}

点赞