@@ -80,14 +80,48 @@ public void onSucceed(ResponseWrapper responseWrapper) {
8080
8181 public static void testSendPush () {
8282 ClientConfig clientConfig = ClientConfig .getInstance ();
83- clientConfig .setPushHostName ("http://113.31.136.110:8800" );
84- clientConfig .setEncryptType (EncryptKeys .ENCRYPT_SMS_TYPE );
8583 final JPushClient jpushClient = new JPushClient (MASTER_SECRET , APP_KEY , null , clientConfig );
8684// String authCode = ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET);
8785 // Here you can use NativeHttpClient or NettyHttpClient or ApacheHttpClient.
8886 // Call setHttpClient to set httpClient,
8987 // If you don't invoke this method, default httpClient will use NativeHttpClient.
9088
89+ // ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);
90+ // NettyHttpClient httpClient =new NettyHttpClient(authCode, null, clientConfig);
91+ // jpushClient.getPushClient().setHttpClient(httpClient);
92+ final PushPayload payload = buildPushObject_android_and_ios ();
93+ // // For push, all you need do is to build PushPayload object.
94+ // PushPayload payload = buildPushObject_all_alias_alert();
95+ try {
96+ PushResult result = jpushClient .sendPush (payload );
97+ LOG .info ("Got result - " + result );
98+ System .out .println (result );
99+ // 如果使用 NettyHttpClient,需要手动调用 close 方法退出进程
100+ // If uses NettyHttpClient, call close when finished sending request, otherwise process will not exit.
101+ // jpushClient.close();
102+ } catch (APIConnectionException e ) {
103+ LOG .error ("Connection error. Should retry later. " , e );
104+ LOG .error ("Sendno: " + payload .getSendno ());
105+
106+ } catch (APIRequestException e ) {
107+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
108+ LOG .info ("HTTP Status: " + e .getStatus ());
109+ LOG .info ("Error Code: " + e .getErrorCode ());
110+ LOG .info ("Error Message: " + e .getErrorMessage ());
111+ LOG .info ("Msg ID: " + e .getMsgId ());
112+ LOG .error ("Sendno: " + payload .getSendno ());
113+ }
114+ }
115+
116+ public static void testSendPushWithEncrypt () {
117+ ClientConfig clientConfig = ClientConfig .getInstance ();
118+ clientConfig .setEncryptType (EncryptKeys .ENCRYPT_SMS2_TYPE );
119+ final JPushClient jpushClient = new JPushClient (MASTER_SECRET , APP_KEY , null , clientConfig );
120+ // String authCode = ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET);
121+ // Here you can use NativeHttpClient or NettyHttpClient or ApacheHttpClient.
122+ // Call setHttpClient to set httpClient,
123+ // If you don't invoke this method, default httpClient will use NativeHttpClient.
124+
91125// ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);
92126// NettyHttpClient httpClient =new NettyHttpClient(authCode, null, clientConfig);
93127// jpushClient.getPushClient().setHttpClient(httpClient);
@@ -118,8 +152,6 @@ public static void testSendPush() {
118152 //use String to build PushPayload instance
119153 public static void testSendPush_fromJSON () {
120154 ClientConfig clientConfig = ClientConfig .getInstance ();
121- clientConfig .setPushHostName ("http://113.31.136.110:8800" );
122- clientConfig .setEncryptType (EncryptKeys .ENCRYPT_SMS_TYPE );
123155 JPushClient jpushClient = new JPushClient (MASTER_SECRET , APP_KEY , null , clientConfig );
124156 Gson gson = new GsonBuilder ()
125157 .registerTypeAdapter (PlatformNotification .class , new InterfaceAdapter <PlatformNotification >())
0 commit comments