use of cn.jiguang.common.resp.APIRequestException in project ed-springboot-learning by QQ986945193.
the class JSMSExample method testGetAppSMSBalance.
public static void testGetAppSMSBalance() {
SMSClient client = new SMSClient(masterSecret, appkey);
try {
AppBalanceResult result = client.getAppSMSBalance();
LOG.info(result.toString());
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
use of cn.jiguang.common.resp.APIRequestException in project ed-springboot-learning by QQ986945193.
the class JSMSExample method testUpdateBatchScheduleSMS.
public static void testUpdateBatchScheduleSMS() {
SMSClient client = new SMSClient(masterSecret, appkey);
List<RecipientPayload> list = new ArrayList<RecipientPayload>();
RecipientPayload recipientPayload1 = new RecipientPayload.Builder().setMobile("13800138000").addTempPara("number", "328393").build();
RecipientPayload recipientPayload2 = new RecipientPayload.Builder().setMobile("13800138001").addTempPara("number", "489042").build();
list.add(recipientPayload1);
list.add(recipientPayload2);
RecipientPayload[] recipientPayloads = new RecipientPayload[list.size()];
ScheduleSMSPayload smsPayload = ScheduleSMSPayload.newBuilder().setSendTime("2017-07-31 16:00:00").setTempId(1245).setRecipients(list.toArray(recipientPayloads)).build();
try {
BatchSMSResult result = client.updateBatchScheduleSMS(smsPayload, "dfs");
LOG.info(result.toString());
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
use of cn.jiguang.common.resp.APIRequestException in project ed-springboot-learning by QQ986945193.
the class JSMSExample method testUpdateTemplate.
// 只有审核不通过状态的模板才允许修改
public void testUpdateTemplate() {
try {
SMSClient client = new SMSClient(masterSecret, appkey);
TemplatePayload payload = TemplatePayload.newBuilder().setTempId(12345).setTemplate("您好,您的验证码是{{code}},2分钟内有效!").setType(1).setTTL(120).setRemark("验证短信").build();
SendTempSMSResult result = client.updateTemplate(payload, 12345);
LOG.info(result.toString());
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
use of cn.jiguang.common.resp.APIRequestException in project ed-springboot-learning by QQ986945193.
the class JSMSExample method testSendSMSWithIHttpClient.
public static void testSendSMSWithIHttpClient() {
SMSClient client = new SMSClient(masterSecret, appkey);
String authCode = ServiceHelper.getBasicAuthorization(appkey, masterSecret);
ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, ClientConfig.getInstance());
// NettyHttpClient httpClient = new NettyHttpClient(authCode, null,
// ClientConfig.getInstance());
// ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null,
// ClientConfig.getInstance());
// 可以切换 HttpClient,默认使用的是 NativeHttpClient
client.setHttpClient(httpClient);
// 如果使用 NettyHttpClient,发送完请求后要调用 close 方法
// client.close();
SMSPayload payload = SMSPayload.newBuilder().setMobileNumber("13800138000").setTempId(1).build();
try {
SendSMSResult res = client.sendSMSCode(payload);
System.out.println(res.toString());
LOG.info(res.toString());
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
use of cn.jiguang.common.resp.APIRequestException in project ed-springboot-learning by QQ986945193.
the class JSMSExample method testSendValidSMSCode.
public static void testSendValidSMSCode() {
SMSClient client = new SMSClient(masterSecret, appkey);
try {
ValidSMSResult res = client.sendValidSMSCode("01658697-45d9-4644-996d-69a1b14e2bb8", "556618");
System.out.println(res.toString());
LOG.info(res.toString());
} catch (APIConnectionException e) {
e.printStackTrace();
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
if (e.getErrorCode() == 50010) {
// do something
}
System.out.println(e.getStatus() + " errorCode: " + e.getErrorCode() + " " + e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
Aggregations