33import cn .jiguang .common .ClientConfig ;
44import cn .jiguang .common .ServiceHelper ;
55import 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 ;
612import org .slf4j .Logger ;
713import org .slf4j .LoggerFactory ;
814
1117import cn .jsms .api .common .SMSClient ;
1218import cn .jsms .api .common .model .SMSPayload ;
1319
20+ import java .util .ArrayList ;
21+ import java .util .List ;
22+
1423
1524public 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}
0 commit comments