@@ -17,32 +17,63 @@ public class JPushClientExample {
1717 private static final String appKey ="dd1066407b044738b6479275" ;
1818 private static final String masterSecret = "2b38ce69b1de2a7fa95706ea" ;
1919
20- private static final String msgTitle = "Test from API example" ;
21- private static final String msgContent = "Test Test" ;
22- private static final String registrationID = "0900e8d85ef" ;
20+ public static final String msgTitle = "Test from API example" ;
21+ public static final String msgContent = "Test Test" ;
22+ public static final String registrationID = "0900e8d85ef" ;
23+ public static final String tag = "tag_api" ;
2324
2425 private static JPushClient jpushClient = null ;
2526
2627 public static void main (String [] args ) {
2728 jpushClient = new JPushClient (masterSecret , appKey , 0 , DeviceEnum .Android , false );
2829
2930 testSend ();
31+ testGetReport ();
3032 }
3133
3234 private static void testSend () {
3335 CustomMessageParams params = new CustomMessageParams ();
34- params .setReceiverType (ReceiverTypeEnum .REGISTRATION_ID );
35- params .setReceiverValue (registrationID );
36- MessageResult msgResult = jpushClient .sendCustomMessage (msgTitle , msgContent , params , null );
36+ //params.setReceiverType(ReceiverTypeEnum.REGISTRATION_ID);
37+ //params.setReceiverValue(registrationID);
38+ params .setReceiverType (ReceiverTypeEnum .TAG );
39+ params .setReceiverValue (tag );
3740
38- if (null != msgResult ) {
39- LOG .info ("responseContent - " + msgResult .responseResult .responseContent );
40- LOG .info ("msgResult - " + msgResult );
41+ MessageResult msgResult = jpushClient .sendCustomMessage (msgTitle , msgContent , params , null );
42+ LOG .debug ("responseContent - " + msgResult .responseResult .responseContent );
43+ if (msgResult .isResultOK ()) {
44+ LOG .info ("msgResult - " + msgResult );
45+ LOG .info ("messageId - " + msgResult .getMessageId ());
46+ } else {
47+ if (msgResult .getErrorCode () > 0 ) {
48+ // 业务异常
49+ LOG .warn ("Service error - ErrorCode: "
50+ + msgResult .getErrorCode () + ", ErrorMessage: "
51+ + msgResult .getErrorMessage ());
52+ } else {
53+ // 未到达 JPush
54+ LOG .error ("Other excepitons - "
55+ + msgResult .responseResult .exceptionString );
56+ }
57+ }
58+ }
59+
60+ public static void testGetReport () {
61+ ReceivedsResult receivedsResult = jpushClient .getReportReceiveds ("1708010723,1774452771" );
62+ LOG .debug ("responseContent - " + receivedsResult .responseResult .responseContent );
63+ if (receivedsResult .isResultOK ()) {
64+ LOG .info ("Receiveds - " + receivedsResult );
65+ } else {
66+ if (receivedsResult .getErrorCode () > 0 ) {
67+ // 业务异常
68+ LOG .warn ("Service error - ErrorCode: "
69+ + receivedsResult .getErrorCode () + ", ErrorMessage: "
70+ + receivedsResult .getErrorMessage ());
71+ } else {
72+ // 未到达 JPush
73+ LOG .error ("Other excepitons - "
74+ + receivedsResult .responseResult .exceptionString );
75+ }
4176 }
42-
43- ReceivedsResult rrr = jpushClient .getReportReceiveds ("1708010723,1774452771" );
44- LOG .info ("content - " + rrr .responseResult .responseContent );
45- LOG .debug ("Received - " + rrr );
4677 }
4778
4879}
0 commit comments