This topic provides a demo to describe how to use Alibaba Cloud SDK for Java to call the SendMessageToGlobe operation. This API operation allows you to send text messages to the regions outside mainland China.

Usage notes

Before you use the SDK sample code, note the following information:

  • When you define a new default profile, the value of the regionId parameter must be ap-southeast-1 and cannot be modified. Note that regionId is the first parameter in the default profile.
  • The domain name must be and cannot be modified.
  • The API version number must be 2018-05-01 and cannot be modified.
Note The version that is used in the demo Maven dependency is a sample version. For information about the latest version of the core library, visit the Maven repository.

Sample code

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;
public class CommonRpc {
    public static void main(String[] args) {
        // Initialize the AcsClient object. You can query <accessKeyId> and <accessSecret> in the Short Message Service (SMS) console.
        DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        // The domain name, which cannot be modified.
        // The API version number, which cannot be modified.
        // The API operation.
        // Required. Specify the mobile phone number to receive the text message. Note that you must add the country code to the beginning of the mobile phone number.
        request.putQueryParameter("To", "62123****8901");
        // Optional. Specify the ID of the sender.
        //request.putQueryParameter("From", "1234567890");
        // Required. Specify the text message content.
        request.putQueryParameter("Message", "have a test.");
        try {
            CommonResponse response = client.getCommonResponse(request);
        } catch (ServerException e) {
        } catch (ClientException e) {