SMS送信(即時送信)
import jp.karaden.Config;
import jp.karaden.exception.KaradenException;
import jp.karaden.exception.BadRequestException;
import jp.karaden.exception.ConnectionException;
import jp.karaden.exception.ForbiddenException;
import jp.karaden.exception.InvalidParamsException;
import jp.karaden.exception.NotFoundException;
import jp.karaden.exception.TooManyRequestsException;
import jp.karaden.exception.UnauthorizedException;
import jp.karaden.exception.UnexpectedValueException;
import jp.karaden.exception.UnknownErrorException;
import jp.karaden.exception.UnprocessableEntityException;
import jp.karaden.model.Message;
import jp.karaden.model.KaradenObjectInterface;
import jp.karaden.param.message.MessageCreateParams;
import org.apache.commons.lang3.builder.ToStringBuilder;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
import java.util.List;
public class TestSend {
public static void main(String[] args) {
Config.apiKey = "PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Config.apiVersion = "2023-01-01";
Config.tenantId = "xxxxxxxx-yyyy-zzzz-xxxx-123456789012";
MessageCreateParams params = MessageCreateParams.newBuilder()
.withServiceId(1)
.withTo("090********")
.withBody("送信テスト\nhttps://www.nttcoms.com/")
.build();
try {
Message message = Message.create(params);
System.out.println(ToStringBuilder.reflectionToString(message, MULTI_LINE_STYLE));
} catch (BadRequestException e) {
System.out.println("---BadRequestException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ConnectionException e) {
System.out.println("---ConnectionException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ForbiddenException e) {
System.out.println("---ForbiddenException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (InvalidParamsException e) {
System.out.println("---InvalidParamsException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (NotFoundException e) {
System.out.println("---NotFoundException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (TooManyRequestsException e) {
System.out.println("---TooManyRequestsException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnauthorizedException e) {
System.out.println("---UnauthorizedException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnexpectedValueException e) {
System.out.println("---UnexpectedValueException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnknownErrorException e) {
System.out.println("---UnknownErrorException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnprocessableEntityException e) {
System.out.println("---UnprocessableEntityException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (KaradenException e) {
System.out.println("[KaradenException]");
// 取りこぼした例外を表示
if(e.error == null){
System.out.println("Error: " + e.getMessage());
}else{
System.out.println("Error.: " + e.error.getMessage());
}
} catch (Exception e) {
System.out.println("[Error!]");
e.printStackTrace();
}
}
}
SMS送信(予約送信)
import jp.karaden.Config;
import jp.karaden.exception.KaradenException;
import jp.karaden.exception.BadRequestException;
import jp.karaden.exception.ConnectionException;
import jp.karaden.exception.ForbiddenException;
import jp.karaden.exception.InvalidParamsException;
import jp.karaden.exception.NotFoundException;
import jp.karaden.exception.TooManyRequestsException;
import jp.karaden.exception.UnauthorizedException;
import jp.karaden.exception.UnexpectedValueException;
import jp.karaden.exception.UnknownErrorException;
import jp.karaden.exception.UnprocessableEntityException;
import jp.karaden.exception.UnexpectedValueException;
import jp.karaden.model.Message;
import jp.karaden.model.KaradenObjectInterface;
import jp.karaden.param.message.MessageCreateParams;
import org.apache.commons.lang3.builder.ToStringBuilder;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
import java.time.OffsetDateTime;
import org.json.JSONObject;
import java.util.List;
public class TestSendSc {
public static void main(String[] args) {
Config.apiKey = "PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Config.apiVersion = "2023-01-01";
Config.tenantId = "xxxxxxxx-yyyy-zzzz-xxxx-123456789012";
OffsetDateTime datetime = OffsetDateTime.parse("2023-01-01T12:00:00+09:00:00");
MessageCreateParams params = MessageCreateParams.newBuilder()
.withServiceId(1)
.withTo("090********")
.withBody("送信テスト\nhttps://www.nttcoms.com/")
.withScheduledAt(datetime)
.build();
try {
Message message = Message.create(params);
System.out.println(ToStringBuilder.reflectionToString(message, MULTI_LINE_STYLE));
} catch (BadRequestException e) {
System.out.println("---BadRequestException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ConnectionException e) {
System.out.println("---ConnectionException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ForbiddenException e) {
System.out.println("---ForbiddenException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (InvalidParamsException e) {
System.out.println("---InvalidParamsException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (NotFoundException e) {
System.out.println("---NotFoundException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (TooManyRequestsException e) {
System.out.println("---TooManyRequestsException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnauthorizedException e) {
System.out.println("---UnauthorizedException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnexpectedValueException e) {
System.out.println("---UnexpectedValueException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnknownErrorException e) {
System.out.println("---UnknownErrorException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnprocessableEntityException e) {
System.out.println("---UnprocessableEntityException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (KaradenException e) {
System.out.println("[KaradenException]");
// 取りこぼした例外を表示
if(e.error == null){
System.out.println("Error: " + e.getMessage());
}else{
System.out.println("Error.: " + e.error.getMessage());
}
} catch (Exception e) {
System.out.println("[Error!]");
e.printStackTrace();
}
}
}
SMS送信結果取得(一括)
import jp.karaden.Config;
import jp.karaden.exception.KaradenException;
import jp.karaden.exception.BadRequestException;
import jp.karaden.exception.ConnectionException;
import jp.karaden.exception.ForbiddenException;
import jp.karaden.exception.InvalidParamsException;
import jp.karaden.exception.NotFoundException;
import jp.karaden.exception.TooManyRequestsException;
import jp.karaden.exception.UnauthorizedException;
import jp.karaden.exception.UnexpectedValueException;
import jp.karaden.exception.UnknownErrorException;
import jp.karaden.exception.UnprocessableEntityException;
import jp.karaden.model.Collection;
import jp.karaden.model.Message;
import jp.karaden.model.KaradenObjectInterface;
import jp.karaden.param.message.MessageListParams;
import org.apache.commons.lang3.builder.ToStringBuilder;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
public class TestList {
public static void main(String[] args) {
Config.apiKey = "PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Config.apiVersion = "2023-01-01";
Config.tenantId = "xxxxxxxx-yyyy-zzzz-xxxx-123456789012";
MessageListParams params = MessageListParams.newBuilder()
.withServiceId(1)
.withTo("090********")
.build();
try {
Collection messages = Message.list(params);
for (Message message : messages.getData()) {
System.out.println(ToStringBuilder.reflectionToString(message, MULTI_LINE_STYLE));
}
System.out.println(ToStringBuilder.reflectionToString(messages, MULTI_LINE_STYLE));
} catch (BadRequestException e) {
System.out.println("---BadRequestException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ConnectionException e) {
System.out.println("---ConnectionException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ForbiddenException e) {
System.out.println("---ForbiddenException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (InvalidParamsException e) {
System.out.println("---InvalidParamsException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (NotFoundException e) {
System.out.println("---NotFoundException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (TooManyRequestsException e) {
System.out.println("---TooManyRequestsException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnauthorizedException e) {
System.out.println("---UnauthorizedException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnexpectedValueException e) {
System.out.println("---UnexpectedValueException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnknownErrorException e) {
System.out.println("---UnknownErrorException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnprocessableEntityException e) {
System.out.println("---UnprocessableEntityException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (KaradenException e) {
System.out.println("[KaradenException]");
// 取りこぼした例外を表示
if(e.error == null){
System.out.println("Error: " + e.getMessage());
}else{
System.out.println("Error.: " + e.error.getMessage());
}
} catch (Exception e) {
System.out.println("[Error!]");
e.printStackTrace();
}
}
}
SMS送信結果取得(レコード単位)
import jp.karaden.Config;
import jp.karaden.exception.KaradenException;
import jp.karaden.exception.BadRequestException;
import jp.karaden.exception.ConnectionException;
import jp.karaden.exception.ForbiddenException;
import jp.karaden.exception.InvalidParamsException;
import jp.karaden.exception.NotFoundException;
import jp.karaden.exception.TooManyRequestsException;
import jp.karaden.exception.UnauthorizedException;
import jp.karaden.exception.UnexpectedValueException;
import jp.karaden.exception.UnknownErrorException;
import jp.karaden.exception.UnprocessableEntityException;
import jp.karaden.model.Message;
import jp.karaden.model.KaradenObjectInterface;
import jp.karaden.param.message.MessageDetailParams;
import org.apache.commons.lang3.builder.ToStringBuilder;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
import java.util.List;
public class TestDetail {
public static void main(String[] args) {
Config.apiKey = "PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Config.apiVersion = "2023-01-01";
Config.tenantId = "xxxxxxxx-yyyy-zzzz-xxxx-123456789012";
MessageDetailParams params = MessageDetailParams.newBuilder()
.withId("12345678-aabb-1234-abcd-123456789123")
.build();
try {
Message message = Message.detail(params);
System.out.println(ToStringBuilder.reflectionToString(message, MULTI_LINE_STYLE));
} catch (BadRequestException e) {
System.out.println("---BadRequestException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ConnectionException e) {
System.out.println("---ConnectionException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ForbiddenException e) {
System.out.println("---ForbiddenException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (InvalidParamsException e) {
System.out.println("---InvalidParamsException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (NotFoundException e) {
System.out.println("---NotFoundException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (TooManyRequestsException e) {
System.out.println("---TooManyRequestsException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnauthorizedException e) {
System.out.println("---UnauthorizedException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnexpectedValueException e) {
System.out.println("---UnexpectedValueException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnknownErrorException e) {
System.out.println("---UnknownErrorException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnprocessableEntityException e) {
System.out.println("---UnprocessableEntityException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (KaradenException e) {
System.out.println("[KaradenException]");
// 取りこぼした例外を表示
if(e.error == null){
System.out.println("Error: " + e.getMessage());
}else{
System.out.println("Error.: " + e.error.getMessage());
}
} catch (Exception e) {
System.out.println("[Error!]");
e.printStackTrace();
}
}
}
SMS送信キャンセル
import jp.karaden.Config;
import jp.karaden.exception.KaradenException;
import jp.karaden.exception.BadRequestException;
import jp.karaden.exception.ConnectionException;
import jp.karaden.exception.ForbiddenException;
import jp.karaden.exception.InvalidParamsException;
import jp.karaden.exception.NotFoundException;
import jp.karaden.exception.TooManyRequestsException;
import jp.karaden.exception.UnauthorizedException;
import jp.karaden.exception.UnexpectedValueException;
import jp.karaden.exception.UnknownErrorException;
import jp.karaden.exception.UnprocessableEntityException;
import jp.karaden.model.Message;
import jp.karaden.model.KaradenObjectInterface;
import jp.karaden.param.message.MessageCancelParams;
import org.apache.commons.lang3.builder.ToStringBuilder;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
import java.time.OffsetDateTime;
public class TestCancel {
public static void main(String[] args) {
Config.apiKey = "PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Config.apiVersion = "2023-01-01";
Config.tenantId = "xxxxxxxx-yyyy-zzzz-xxxx-123456789012";
MessageCancelParams params = MessageCancelParams.newBuilder()
.withId("12345678-aabb-1234-abcd-123456789123")
.build();
try {
Message message = Message.cancel(params);
System.out.println(ToStringBuilder.reflectionToString(message, MULTI_LINE_STYLE));
} catch (BadRequestException e) {
System.out.println("---BadRequestException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ConnectionException e) {
System.out.println("---ConnectionException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (ForbiddenException e) {
System.out.println("---ForbiddenException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (InvalidParamsException e) {
System.out.println("---InvalidParamsException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (NotFoundException e) {
System.out.println("---NotFoundException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (TooManyRequestsException e) {
System.out.println("---TooManyRequestsException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnauthorizedException e) {
System.out.println("---UnauthorizedException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnexpectedValueException e) {
System.out.println("---UnexpectedValueException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnknownErrorException e) {
System.out.println("---UnknownErrorException---");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
} catch (UnprocessableEntityException e) {
System.out.println("---UnprocessableEntityException---");
System.out.println("[e.error]");
System.out.println(ToStringBuilder.reflectionToString(e.error, MULTI_LINE_STYLE));
KaradenObjectInterface errors = e.error.getErrors();
System.out.println("[e.error.getErrors()]");
System.out.println(ToStringBuilder.reflectionToString(errors, MULTI_LINE_STYLE));
} catch (KaradenException e) {
System.out.println("[KaradenException]");
// 取りこぼした例外を表示
if(e.error == null){
System.out.println("Error: " + e.getMessage());
}else{
System.out.println("Error.: " + e.error.getMessage());
}
} catch (Exception e) {
System.out.println("[Error!]");
e.printStackTrace();
}
}
}