Search in sources :

Example 1 with APIRequestException

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());
    }
}
Also used : APIConnectionException(cn.jiguang.common.resp.APIConnectionException) AppBalanceResult(cn.jsms.api.account.AppBalanceResult) SMSClient(cn.jsms.api.common.SMSClient) APIRequestException(cn.jiguang.common.resp.APIRequestException)

Example 2 with APIRequestException

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());
    }
}
Also used : ScheduleSMSPayload(cn.jsms.api.schedule.model.ScheduleSMSPayload) APIConnectionException(cn.jiguang.common.resp.APIConnectionException) SMSClient(cn.jsms.api.common.SMSClient) RecipientPayload(cn.jsms.api.common.model.RecipientPayload) BatchSMSResult(cn.jsms.api.common.model.BatchSMSResult) ArrayList(java.util.ArrayList) APIRequestException(cn.jiguang.common.resp.APIRequestException)

Example 3 with APIRequestException

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());
    }
}
Also used : APIConnectionException(cn.jiguang.common.resp.APIConnectionException) SMSClient(cn.jsms.api.common.SMSClient) SendTempSMSResult(cn.jsms.api.template.SendTempSMSResult) TemplatePayload(cn.jsms.api.template.TemplatePayload) APIRequestException(cn.jiguang.common.resp.APIRequestException)

Example 4 with APIRequestException

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());
    }
}
Also used : APIConnectionException(cn.jiguang.common.resp.APIConnectionException) SMSClient(cn.jsms.api.common.SMSClient) SendSMSResult(cn.jsms.api.SendSMSResult) ApacheHttpClient(cn.jiguang.common.connection.ApacheHttpClient) APIRequestException(cn.jiguang.common.resp.APIRequestException) SMSPayload(cn.jsms.api.common.model.SMSPayload) ScheduleSMSPayload(cn.jsms.api.schedule.model.ScheduleSMSPayload) BatchSMSPayload(cn.jsms.api.common.model.BatchSMSPayload)

Example 5 with APIRequestException

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());
    }
}
Also used : APIConnectionException(cn.jiguang.common.resp.APIConnectionException) ValidSMSResult(cn.jsms.api.ValidSMSResult) SMSClient(cn.jsms.api.common.SMSClient) APIRequestException(cn.jiguang.common.resp.APIRequestException)

Aggregations

APIRequestException (cn.jiguang.common.resp.APIRequestException)108 APIConnectionException (cn.jiguang.common.resp.APIConnectionException)105 Test (org.junit.Test)51 JPushClient (cn.jpush.api.JPushClient)37 SMSClient (cn.jsms.api.common.SMSClient)23 JsonObject (com.google.gson.JsonObject)23 BaseTest (cn.jsms.api.BaseTest)18 ScheduleSMSPayload (cn.jsms.api.schedule.model.ScheduleSMSPayload)17 PushPayload (cn.jpush.api.push.model.PushPayload)16 PushResult (cn.jpush.api.push.PushResult)14 BaseTest (cn.jpush.api.BaseTest)11 GroupPushResult (cn.jpush.api.push.GroupPushResult)11 BatchSMSPayload (cn.jsms.api.common.model.BatchSMSPayload)11 JsonPrimitive (com.google.gson.JsonPrimitive)11 SendSMSResult (cn.jsms.api.SendSMSResult)9 SMSPayload (cn.jsms.api.common.model.SMSPayload)9 ClientConfig (cn.jiguang.common.ClientConfig)8 ResponseWrapper (cn.jiguang.common.resp.ResponseWrapper)8 ScheduleResult (cn.jpush.api.schedule.ScheduleResult)6 BatchSMSResult (cn.jsms.api.common.model.BatchSMSResult)6