本文为您介绍了Node.js调用SendMessageToGlobe发送短信。

请求参数

名称 类型 是否必选 示例值 描述
To String 45***0121 每次只支持一个号码调用发送,号码格式为:Country Code+ Phone Number。
From String abc12345 支持SenderId的发送,只允许支持数字+字母,含有字母数字的最长11位,纯数字支持15位。
Message String 你好 短信的完整内容。

返回数据

名称 类型 示例值 描述
MessageId String 10080***003003 发送回执ID,可根据该ID查询具体的发送状态。
To String 653***7810 发送号码。
From String Alicloud 目前支持SenderId,返回传入的SenderId。
ResponseCode String OK 状态码-返回OK代表请求成功,其他错误码详见错误码列表。
ResponseDescription String The SMS Send Request was accepted 状态码的描述。
Segments String 1 短信的计费条数。
NumberDetail String 号码的详细属性。
Country String Hongkong, China 号码所属国家。
Region String HongKong Number Region。
Carrier String CMI 号码所属的运营商网络。

引入阿里云核心包

  • 方法1:通过npm/yarn安装。
    npm install @alicloud/pop-core
                        
  • 方法2:core-sdk下载地址:Node.js API SDK

调用示例

注意事项如下:

  • RegionId必须为ap-southeast-1,请勿修改。
  • endpoint必须为https://dysmsapi.ap-southeast-1.aliyuncs.com, 请勿修改。
  • apiVersion必须为2018-05-01,请勿修改。
const Core = require('@alicloud/pop-core');

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

var params = {
  "RegionId": "ap-southeast-1",
  "To": "6212345678901",
  "From": "1234",
  "Message": "Have a test."
}

var requestOption = {
  method: 'POST'
};

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