Java Demo
SMS API Java Demo
Last updated
SMS API Java Demo
Last updated
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ANT-Demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.5</version>
</dependency>
</dependencies>
</project>
public class Constants {
public static final String ACCESSKEY_ID = "******";
public static final String ACCESSKEY_SECRET = "******";
public static final String URL_MARKETING = "https://api.antgst.com/sms/txt/1/send/json";
public static final String URL_NOTIFICATION = "https://api.antgst.com/sms/txt/2/send/json";
public static final String URL_OTP = "https://api.antgst.com/sms/txt/3/send/json";
}
package com.antgst.demo;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.*;
import com.antgst.util.Constants;
public class SendMarketingSMS {
public static void main(String[] args) {
JSONObject json = new JSONObject();
json.set("authSecret", Constants.ACCESSKEY_ID + Constants.ACCESSKEY_SECRET);
// senderid If not, leave it blank
// json.set("from", "senderid");
JSONArray numbersAry = new JSONArray();
numbersAry.put("00***"); // phone number
json.set("numbers", numbersAry);
json.set("sms", "Test Marketing SMS");
String response = HttpRequest.post(Constants.URL_MARKETING)
.header("Content-Type", "application/json")
.body(json.toString())
.execute().body();
System.out.println("URL:" + Constants.URL_MARKETING
+ " Request JSON:" + json.toString()
+ " Response JSON:" + response);
}
}
package com.antgst.demo;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.antgst.util.Constants;
public class SendNotificationSMS {
public static void main(String[] args) {
JSONObject json = new JSONObject();
json.set("authSecret", Constants.ACCESSKEY_ID + Constants.ACCESSKEY_SECRET);
// senderid If not, leave it blank
// json.set("from", "senderid");
JSONArray numbersAry = new JSONArray();
numbersAry.put("00***"); // phone number
json.set("numbers", numbersAry);
json.set("sms", "Test Notification SMS");
String response = HttpRequest.post(Constants.URL_NOTIFICATION)
.header("Content-Type", "application/json")
.body(json.toString())
.execute().body();
System.out.println("URL:" + Constants.URL_NOTIFICATION
+ " Request JSON:" + json.toString()
+ " Response JSON:" + response);
}
}
package com.antgst.demo;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.antgst.util.Constants;
public class SendOTPSMS {
public static void main(String[] args) {
JSONObject json = new JSONObject();
json.set("authSecret", Constants.ACCESSKEY_ID + Constants.ACCESSKEY_SECRET);
// senderid If not, leave it blank
// json.set("from", "senderid");
json.set("number", "00***"); // phone number
json.set("sms", "Test OTP SMS 123456");
String response = HttpRequest.post(Constants.URL_OTP)
.header("Content-Type", "application/json")
.body(json.toString())
.execute().body();
System.out.println("URL:" + Constants.URL_OTP
+ " Request JSON:" + json.toString()
+ " Response JSON:" + response);
}
}