Skip to content

Commit ac7bdc0

Browse files
KenChoiKenChoi
authored andcommitted
Add new APIs
1 parent 61969ff commit ac7bdc0

File tree

12 files changed

+751
-31
lines changed

12 files changed

+751
-31
lines changed

example/main/java/cn/jsms/api/JSMSExample.java

Lines changed: 157 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import cn.jiguang.common.ClientConfig;
44
import cn.jiguang.common.ServiceHelper;
55
import cn.jiguang.common.connection.ApacheHttpClient;
6+
import cn.jiguang.common.resp.ResponseWrapper;
7+
import cn.jsms.api.account.AccountBalanceResult;
8+
import cn.jsms.api.account.AppBalanceResult;
9+
import cn.jsms.api.schedule.model.RecipientPayload;
10+
import cn.jsms.api.schedule.model.ScheduleListResult;
11+
import cn.jsms.api.schedule.model.ScheduleResult;
612
import org.slf4j.Logger;
713
import org.slf4j.LoggerFactory;
814

@@ -11,6 +17,9 @@
1117
import cn.jsms.api.common.SMSClient;
1218
import cn.jsms.api.common.model.SMSPayload;
1319

20+
import java.util.ArrayList;
21+
import java.util.List;
22+
1423

1524
public class JSMSExample {
1625

@@ -29,7 +38,7 @@ public static void main(String[] args) {
2938
public static void testSendSMSCode() {
3039
SMSClient client = new SMSClient(masterSecret, appkey);
3140
SMSPayload payload = SMSPayload.newBuilder()
32-
.setMobildNumber("13800138000")
41+
.setMobileNumber("13800138000")
3342
.setTempId(1)
3443
.build();
3544
try {
@@ -56,7 +65,7 @@ public static void testSendSMSWithIHttpClient() {
5665
// 如果使用 NettyHttpClient,发送完请求后要调用 close 方法
5766
// client.close();
5867
SMSPayload payload = SMSPayload.newBuilder()
59-
.setMobildNumber("13800138000")
68+
.setMobileNumber("13800138000")
6069
.setTempId(1)
6170
.build();
6271
try {
@@ -100,7 +109,7 @@ public static void testSendValidSMSCode() {
100109
public static void testSendVoiceSMSCode() {
101110
SMSClient client = new SMSClient(masterSecret, appkey);
102111
SMSPayload payload = SMSPayload.newBuilder()
103-
.setMobildNumber("13800138000")
112+
.setMobileNumber("13800138000")
104113
.setTTL(90)
105114
.build();
106115
try {
@@ -118,7 +127,7 @@ public static void testSendVoiceSMSCode() {
118127
public static void testSendTemplateSMS() {
119128
SMSClient client = new SMSClient(masterSecret, appkey);
120129
SMSPayload payload = SMSPayload.newBuilder()
121-
.setMobildNumber("13800138000")
130+
.setMobileNumber("13800138000")
122131
.setTempId(1)
123132
.addTempPara("test", "jpush")
124133
.build();
@@ -133,5 +142,149 @@ public static void testSendTemplateSMS() {
133142
LOG.error("Connection error. Should retry later. ", e);
134143
}
135144
}
145+
146+
public static void testSendScheduleSMS() {
147+
SMSClient client = new SMSClient(masterSecret, appkey);
148+
SMSPayload payload = SMSPayload.newBuilder()
149+
.setMobileNumber("13570210796")
150+
.setTempId(1111)
151+
.setSendTime("2017-07-31 16:17:00")
152+
.addTempPara("number", "798560")
153+
.build();
154+
try {
155+
ScheduleResult result = client.sendScheduleSMS(payload);
156+
LOG.info(result.toString());
157+
} catch (APIConnectionException e) {
158+
LOG.error("Connection error. Should retry later. ", e);
159+
} catch (APIRequestException e) {
160+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
161+
LOG.info("HTTP Status: " + e.getStatus());
162+
LOG.info("Error Message: " + e.getMessage());
163+
}
164+
}
165+
166+
public static void testUpdateScheduleSMS() {
167+
SMSClient client = new SMSClient(masterSecret, appkey);
168+
SMSPayload payload = SMSPayload.newBuilder()
169+
.setMobileNumber("13800138000")
170+
.setTempId(1111)
171+
.setSendTime("2017-07-31 15:00:00")
172+
.addTempPara("number", "110110")
173+
.build();
174+
try {
175+
ScheduleResult result = client.updateScheduleSMS(payload, "dsfd");
176+
LOG.info(result.toString());
177+
} catch (APIConnectionException e) {
178+
LOG.error("Connection error. Should retry later. ", e);
179+
} catch (APIRequestException e) {
180+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
181+
LOG.info("HTTP Status: " + e.getStatus());
182+
LOG.info("Error Message: " + e.getMessage());
183+
}
184+
}
185+
186+
public static void testSendBatchScheduleSMS() {
187+
SMSClient client = new SMSClient(masterSecret, appkey);
188+
List<RecipientPayload> list = new ArrayList<RecipientPayload>();
189+
RecipientPayload recipientPayload1 = new RecipientPayload.Builder()
190+
.setMobile("13800138000")
191+
.addTempPara("number", "638938")
192+
.build();
193+
RecipientPayload recipientPayload2 = new RecipientPayload.Builder()
194+
.setMobile("13800138001")
195+
.addTempPara("number", "829302")
196+
.build();
197+
list.add(recipientPayload1);
198+
list.add(recipientPayload2);
199+
RecipientPayload[] recipientPayloads = new RecipientPayload[list.size()];
200+
SMSPayload smsPayload = SMSPayload.newBuilder()
201+
.setSendTime("2017-07-31 16:00:00")
202+
.setTempId(1245)
203+
.setRecipients(recipientPayloads)
204+
.build();
205+
try {
206+
ScheduleListResult result = client.sendBatchScheduleSMS(smsPayload);
207+
LOG.info(result.toString());
208+
} catch (APIConnectionException e) {
209+
LOG.error("Connection error. Should retry later. ", e);
210+
} catch (APIRequestException e) {
211+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
212+
LOG.info("HTTP Status: " + e.getStatus());
213+
LOG.info("Error Message: " + e.getMessage());
214+
}
215+
}
216+
217+
public static void testUpdateBatchScheduleSMS() {
218+
SMSClient client = new SMSClient(masterSecret, appkey);
219+
List<RecipientPayload> list = new ArrayList<RecipientPayload>();
220+
RecipientPayload recipientPayload1 = new RecipientPayload.Builder()
221+
.setMobile("13800138000")
222+
.addTempPara("number", "328393")
223+
.build();
224+
RecipientPayload recipientPayload2 = new RecipientPayload.Builder()
225+
.setMobile("13800138001")
226+
.addTempPara("number", "489042")
227+
.build();
228+
list.add(recipientPayload1);
229+
list.add(recipientPayload2);
230+
RecipientPayload[] recipientPayloads = new RecipientPayload[list.size()];
231+
SMSPayload smsPayload = SMSPayload.newBuilder()
232+
.setSendTime("2017-07-31 16:00:00")
233+
.setTempId(1245)
234+
.setRecipients(recipientPayloads)
235+
.build();
236+
try {
237+
ScheduleListResult result = client.updateBatchScheduleSMS(smsPayload, "dfs");
238+
LOG.info(result.toString());
239+
} catch (APIConnectionException e) {
240+
LOG.error("Connection error. Should retry later. ", e);
241+
} catch (APIRequestException e) {
242+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
243+
LOG.info("HTTP Status: " + e.getStatus());
244+
LOG.info("Error Message: " + e.getMessage());
245+
}
246+
}
247+
248+
public static void testDeleteScheduleSMS() {
249+
SMSClient client = new SMSClient(masterSecret, appkey);
250+
try {
251+
ResponseWrapper result = client.deleteScheduleSMS("sd");
252+
LOG.info("Response content: " + result.responseContent + " response code: " + result.responseCode);
253+
} catch (APIConnectionException e) {
254+
LOG.error("Connection error. Should retry later. ", e);
255+
} catch (APIRequestException e) {
256+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
257+
LOG.info("HTTP Status: " + e.getStatus());
258+
LOG.info("Error Message: " + e.getMessage());
259+
}
260+
}
261+
262+
public static void testGetAccountSMSBalance() {
263+
SMSClient client = new SMSClient(masterSecret, appkey);
264+
try {
265+
AccountBalanceResult result = client.getSMSBalance();
266+
LOG.info(result.toString());
267+
} catch (APIConnectionException e) {
268+
LOG.error("Connection error. Should retry later. ", e);
269+
} catch (APIRequestException e) {
270+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
271+
LOG.info("HTTP Status: " + e.getStatus());
272+
LOG.info("Error Message: " + e.getMessage());
273+
}
274+
}
275+
276+
public static void testGetAppSMSBalance() {
277+
SMSClient client = new SMSClient(masterSecret, appkey);
278+
try {
279+
AppBalanceResult result = client.getAppSMSBalance();
280+
LOG.info(result.toString());
281+
} catch (APIConnectionException e) {
282+
LOG.error("Connection error. Should retry later. ", e);
283+
} catch (APIRequestException e) {
284+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
285+
LOG.info("HTTP Status: " + e.getStatus());
286+
LOG.info("Error Message: " + e.getMessage());
287+
}
288+
}
136289

137290
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<dependency>
4242
<groupId>cn.jpush.api</groupId>
4343
<artifactId>jiguang-common</artifactId>
44-
<version>1.0.6</version>
44+
<version>1.0.8</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>com.google.code.gson</groupId>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cn.jsms.api.account;
2+
3+
import cn.jiguang.common.resp.BaseResult;
4+
import com.google.gson.annotations.Expose;
5+
6+
public class AccountBalanceResult extends BaseResult {
7+
@Expose int dev_balance;
8+
9+
public int getDevBalance() {
10+
return dev_balance;
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.jsms.api.account;
2+
3+
import cn.jiguang.common.resp.BaseResult;
4+
import com.google.gson.annotations.Expose;
5+
6+
public class AppBalanceResult extends BaseResult {
7+
8+
@Expose int app_balance;
9+
10+
public int getAppBalance() {
11+
return app_balance;
12+
}
13+
}

src/main/java/cn/jsms/api/common/JSMSConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class JSMSConfig {
1717
public final static String VOICE_CODE_PATH = "sms.voice.code.path";
1818

1919
public final static String TEMP_MESSAGE_PATH = "sms.temp.message.path";
20+
21+
public final static String SCHEDULE_PATH = "sms.schedule.path";
22+
23+
public final static String ACCOUNT_PATH = "sms.account.path";
2024

2125
public static final String MAX_RETRY_TIMES = ClientConfig.MAX_RETRY_TIMES;
2226

@@ -28,6 +32,8 @@ public JSMSConfig() {
2832
clientConfig.put(VALID_PATH, "/valid");
2933
clientConfig.put(VOICE_CODE_PATH, "/v1/voice_codes");
3034
clientConfig.put(TEMP_MESSAGE_PATH, "/v1/messages");
35+
clientConfig.put(SCHEDULE_PATH, "/v1/schedule");
36+
clientConfig.put(ACCOUNT_PATH, "/v1/accounts");
3137
clientConfig.put(MAX_RETRY_TIMES, 3);
3238
clientConfig.put(SEND_VERSION, 1);
3339
}

0 commit comments

Comments
 (0)