首页 SendMessageToGlobe

SendMessageToGlobe

更新时间: 2025-04-14 14:24:16

调用SendMessageToGlobe接口发送短信到美国、加拿大和新加坡,Sender ID需要注册。

接口说明

QPS限制

本接口的单用户QPS限制为1000次/秒。超过限制,API调用会被限流,这可能会影响您的业务,请合理调用。

请求参数

名称

类型

是否必选

示例值

描述

Action

String

SendMessageToGlobe

操作接口名,系统规定参数。取值:SendMessageToGlobe

Message

String

Hello

短信的完整内容。

说明

美国、加拿大需要填写报备的内容。

To

String

"6212345****01"

接收短信号码。号码格式为:国际区号+号码。例如:"6212345****01"。

From

String

Alicloud

发送方标识。支持Sender ID的发送,只允许数字+字母,含有字母标识最长11位,纯数字标识支持15位。

说明
  • 美国、加拿大需要填写10 DLC注册后运营商提供的Sender ID。

  • 新加坡需填写在IMDA完成SSIR注册的Sender ID。

Type

String

OTP

短信类型,取值:

  • OTP:验证码

  • NOTIFY:短信通知

  • MKT:推广短信

返回数据

名称

类型

示例值

描述

From

String

Alicloud

发送方标识,返回传入的Sender ID。

MessageId

String

1008030xxx3003

短信发送ID。

NumberDetail

Struct

Country:Hongkong, China

Region:Hongkong

Carrier:CMI

号码明细。

Carrier

String

CMI

号码所属的运营商网络。

Country

String

Hongkong, China

号码所属国家。

Region

String

HongKong

号码所属地区。

Segments

String

1

短信计费条数。

To

String

"6212345****01"

接收号码。

示例

请求示例

http(s)://dysmsapi.aliyuncs.com/?Action=SendMessageToGlobe
&Message=xxxx
&To="6212345****01"
&Type=OTP
&From=Alicloud
&<公共请求参数>

正常返回示例

XML 格式

<SendMessageToGlobeResponse>
      <From>Alicloud</From>
      <MessageId>1008030xxx3003</MessageId>
      <NumberDetail>
            <Carrier>CMI</Carrier>
            <Country>Hongkong,China</Country>
            <Region>HongKong</Region>
      </NumberDetail>
      <RequestId>F655A8D5-B967-440B-8683-DAD6FF8DE990</RequestId>
      <Segments>1</Segments>
      <To>6212345****01</To>
</SendMessageToGlobeResponse>

JSON 格式

{
    "From": "Alicloud",
    "MessageId": "1008030xxx3003",
    "NumberDetail": {
        "Carrier": "CMI",
        "Country": "Hongkong,China",
        "Region": "HongKong"
        },
    "RequestId": "F655A8D5-B967-440B-8683-DAD6FF8DE990",
    "Segments": "1",
    "To": "6212345****01"
}

调用示例Demo

Java Demo

注意事项

参考Java示例您需要注意以下几点:

  • 构造DefaultProfile时,第一个参数(regionId)必须为cn-hangzhou,请勿修改。

  • domain必须为dysmsapi.aliyuncs.com,请勿修改。

  • version必须为2017-05-25,请勿修改。

编写样例程序

package com.alicom.dysms.api;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <!-- 请将 'the-latest-version' 替换为最新版本号:https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
  <version>the-latest-version</version>
</dependency>
*/public class CommonRpc {
/**
     * 此处通过从环境变量中读取AccessKey,初始化Client
     * @return Client
     * @throws Exception
     */
    public static IAcsClient createSCAClient() throws Exception {
        // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户
        // 此处以把AccessKey 和 AccessKeySecret 保存在环境变量为例说明。您也可以根据业务需要,保存到配置文件里
        // 强烈建议不要把 AccessKey 和 AccessKeySecret 保存到代码里,会存在密钥泄漏风险
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", System.getenv("SMS_ACCESS_KEY_ENV"), System.getenv("SMS_ACCESS_KEY_SECRET_ENV"));
        //指定服务接入地址,以下值为固定
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Qualitycheck", "qualitycheck.cn-hangzhou.aliyuncs.com");

        return new DefaultAcsClient(profile);
    }
    public static void main(String[] args) {
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        //域名,请勿修改
        request.setSysDomain("dysmsapi.aliyuncs.com");
        //API版本号,请勿修改
        request.setSysVersion("2017-05-25");
        //API名称
        request.setSysAction("SendMessageToGlobe");
        //接收号码,格式为:国际码+号码,必填
        request.putQueryParameter("To", "62123****8901");
        //发送方senderId,选填
        //request.putQueryParameter("From", "1234****90");
        //短信内容,必填
        request.putQueryParameter("Type", "OTP");
        request.putQueryParameter("Message", "have a test.");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
            

PHP Demo

注意事项

参考PHP示例您需要注意以下几点:

  • regionId必须为cn-hangzhou,请勿修改。

  • product必须为Dysmsapi,请勿修改。

  • host必须为dysmsapi.aliyuncs.com,请勿修改。

  • version必须为2017-05-25,请勿修改。

编写样例程序

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

// Download:https://github.com/aliyun/openapi-sdk-php
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md

// 阿里云账号AccessKey ID拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户
// 此处以把AccessKey ID和 AccessKey Secret 保存在环境变量为例说明。 您也可以根据业务需要,保存到配置文件里
// 强烈建议不要把 AccessKey ID和 AccessKey Secret 保存到代码里,会存在密钥泄漏风险
AlibabaCloud::accessKeyClient(getenv("SMS_ACCESS_KEY_ENV"), getenv("SMS_ACCESS_KEY_SECRET_ENV"))
    ->regionId('cn-hangzhou')
    ->asDefaultClient()->options([

    ]);

try {
    $result = AlibabaCloud::rpc()
        ->product('Dysmsapi')
        // ->scheme('https') // https | http
        ->version('2017-05-25')
        ->action('SendMessageToGlobe')
        ->method('POST')
        ->host('dysmsapi.aliyuncs.com')
        ->options([
            'query' => [
                'To' => "62123****8901", //接收短信号码。号码格式为:国际区号+号码
                'From' => "1234****90", //发送方标识。支持SenderID的发送,只允许数字+字母,含有字母标识最长11位,纯数字标识支持15位
                'Message' => "have a test", //短信的完整内容
                'Type' => "OTP", //短信类型
            ],
        ])
        ->request();
    print_r($result->toArray());
} catch (ClientException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
}

Python Demo

注意事项

参考Python示例您需要注意以下几点:

  • 构造AcsClient时,第三个参数(regionId)必须为cn-hangzhou,请勿修改。

  • domain必须为dysmsapi.aliyuncs.com,请勿修改。

  • version必须为2017-05-25,请勿修改。

编写样例程序

Python Demo代码示例详情,请参见SDK示例

#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential

credentials = AccessKeyCredential(os.environ['SMS_ACCESS_KEY_ENV'], os.environ['SMS_ACCESS_KEY_SECRET_ENV'])
# use STS Token
# credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
client = AcsClient(region_id='cn-hangzhou', credential=credentials)

request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dysmsapi.aliyuncs.com')
request.set_method('POST')
request.set_protocol_type('https') # https | http
request.set_version('2017-05-25')
request.set_action_name('SendMessageToGlobe')

request.add_query_param('To', "62123****8901")//接收短信号码。号码格式为:国际区号+号码。
request.add_query_param('From', "1234****90")//发送方标识。支持SenderID的发送,只允许数字+字母,含有字母标识最长11位,纯数字标识支持15位
request.add_query_param('Message', "have a test")//短信的完整内容
request.add_query_param('Type', "OTP")//短信类型

response = client.do_action(request)
# python2:  print(response) 
print(str(response, encoding = 'utf-8'))

Node.js Demo

注意事项

参考这个示例您需要注意以下几点:

  • RegionId必须为cn-hangzhou,请勿修改。

  • endpoint必须为“https://dysmsapi.aliyuncs.com”,请勿修改。

  • apiVersion必须为2017-05-25,请勿修改。

编写样例程序

说明

调用接口前需配置环境变量,以便通过环境变量读取访问凭证。AccessKey ID和AccessKey Secret的环境变量名:SMS_ACCESS_KEY_ENV 、SMS_ACCESS_KEY_SECRET_ENV。配置详情请参见在Linux、macOS和Windows系统配置环境变量

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

// 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以把AccessKey ID和AccessKey Secret保存在环境变量为例说明,来实现API访问的身份验证。
var client = new Core({
  accessKeyId: process.env['SMS_ACCESS_KEY_ENV'],
  accessKeySecret: process.env['SMS_ACCESS_KEY_SECRET_ENV'],
  // securityToken: '<your-sts-token>', // use STS Token
  endpoint: 'https://dysmsapi.aliyuncs.com',
  apiVersion: '2017-05-25'
});

const params = {
  "To": "62123****8901",//接收短信号码。号码格式为:国际区号+号码
  "From": "1234****90",//发送方标识。支持SenderID的发送,只允许数字+字母,含有字母标识最长11位,纯数字标识支持15位
  "Message": "have a test",//短信的完整内容
  "Type": "OTP" //短信类型
};

var requestOption = {
  method: "POST",
  formatParams: false,

};

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

C# Demo

注意事项

参考这个示例您需要注意以下几点:

  • 初始化IClientProfile时,第一个参数(RegionId)必须为cn-hangzhou,请勿修改。

  • Domain必须为dysmsapi.aliyuncs.com,请勿修改。

  • Version必须为2017-05-25,请勿修改。

编写样例程序

说明

调用接口前需配置环境变量,以便通过环境变量读取访问凭证。AccessKey ID和AccessKey Secret的环境变量名:SMS_ACCESS_KEY_ENV 、SMS_ACCESS_KEY_SECRET_ENV。配置详情请参见在Linux、macOS和Windows系统配置环境变量

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;
namespace CommonRpc
{
class Program
{
/**
     * 此处通过从环境变量中读取AccessKey,初始化Client
     * @return Client
     * @throws Exception
     */
    static IAcsClient createSCAClient() throws Exception {
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例以把AccessKey ID和AccessKey Secret保存在环境变量为例说明,来实现API访问的身份验证。
    IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", Environment.GetEnvironmentVariable("SMS_ACCESS_KEY_ENV"), Environment.GetEnvironmentVariable("SMS_ACCESS_KEY_SECRET_ENV"));
    //指定服务接入地址,以下值为固定
    DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Qualitycheck", "qualitycheck.cn-hangzhou.aliyuncs.com");

    return new DefaultAcsClient(profile);
    }
static void Main(string[] args)
{
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<AccessKeyId>", "<AccessSecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest
{
Method = MethodType.POST,
Domain = "dysmsapi.aliyuncs.com",
Version = "2017-05-25",
Action = "SendMessageToGlobe"
};
// request.Protocol = ProtocolType.HTTPS;
request.AddQueryParameters("To", "62123****8901");
request.AddQueryParameters("PhoneNumber", "156****0987");
// request.AddQueryParameters("From", "1234567890");
request.AddQueryParameters("Message", "have a test.");
// request.AddQueryParameters("Type", "OTP");
try
{
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(response.Data);
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}
            

C++ Demo

注意事项

参考这个示例您需要注意以下几点:

  • Domain必须为dysmsapi.aliyuncs.com,请勿修改。

  • Version必须为2017-05-25,请勿修改。

编写样例程序

说明

调用接口前需配置环境变量,以便通过环境变量读取访问凭证。AccessKey ID和AccessKey Secret的环境变量名:SMS_ACCESS_KEY_ENV 、SMS_ACCESS_KEY_SECRET_ENV。配置详情请参见在Linux、macOS和Windows系统配置环境变量

#include <cstdlib>
#include <iostream>
#include <alibabacloud/core/AlibabaCloud.h>
#include <alibabacloud/core/CommonRequest.h>
#include <alibabacloud/core/CommonClient.h>
#include <alibabacloud/core/CommonResponse.h>

using namespace std;
using namespace AlibabaCloud;

int main( int argc, char** argv )
{
AlibabaCloud::InitializeSdk();
AlibabaCloud::ClientConfiguration configuration( "cn-qingdao" );
// specify timeout when create client.
configuration.setConnectTimeout(1500);
configuration.setReadTimeout(4000);
/*
 调用接口前请配置环境变量,并进行必要的异常规避措施,如:
 const char* accessKeyId = getenv("SMS_ACCESS_KEY_ENV");
 const char* accessKeySecret = getenv("SMS_ACCESS_KEY_SECRET");
 if (!accessKeyId || !accessKeySecret) {
     cerr << "Environment variables for Access Key ID or Secret are not set." << endl;
     return -1;
 }
*/
AlibabaCloud::Credentials credential(getenv("SMS_ACCESS_KEY_ENV"), getenv("SMS_ACCESS_KEY_SECRET"));
/* use STS Token
credential.setSessionToken( "<your-sts-token>" );
*/
AlibabaCloud::CommonClient client( credential, configuration );
AlibabaCloud::CommonRequest request(AlibabaCloud::CommonRequest::RequestPattern::RpcPattern);
request.setHttpMethod(AlibabaCloud::HttpRequest::Method::Post);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setQueryParameter("Action", "SendMessageToGlobe");
request.setQueryParameter("To", "611111111");
request.setQueryParameter("From", "sender");
request.setQueryParameter("Message", "have a test.");
request.setQueryParameter("Type", "OTP");

auto response = client.commonResponse(request);
if (response.isSuccess()) {
printf("request success.\n");
printf("result: %s\n", response.result().payload().c_str());
} else {
printf("error: %s\n", response.error().errorMessage().c_str());
printf("request id: %s\n", response.error().requestId().c_str());
}

AlibabaCloud::ShutdownSdk();
return 0;
}

错误码

访问错误中心查看更多错误码。

阿里云首页 短信服务 相关技术圈