2727public class PushClient {
2828 public static final String HOST_NAME_SSL = "https://api.jpush.cn" ;
2929 public static final String PUSH_PATH = "/v3/push" ;
30+ public static final String PUSH_VALIDATE_PATH = "/v3/push/validate" ;
3031
3132 private final NativeHttpClient _httpClient ;
3233 private JsonParser _jsonParser = new JsonParser ();
@@ -66,7 +67,7 @@ public PushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPro
6667 ServiceHelper .checkBasic (appKey , masterSecret );
6768
6869 String authCode = ServiceHelper .getBasicAuthorization (appKey , masterSecret );
69- this ._baseUrl = HOST_NAME_SSL + PUSH_PATH ;
70+ this ._baseUrl = HOST_NAME_SSL ;
7071 this ._httpClient = new NativeHttpClient (authCode , maxRetryTimes , proxy );
7172 }
7273
@@ -106,7 +107,20 @@ public PushResult sendPush(PushPayload pushPayload) throws APIConnectionExceptio
106107 pushPayload .resetOptionsApnsProduction (_apnsProduction );
107108 }
108109
109- ResponseWrapper response = _httpClient .sendPost (_baseUrl , pushPayload .toString ());
110+ ResponseWrapper response = _httpClient .sendPost (_baseUrl + PUSH_PATH , pushPayload .toString ());
111+
112+ return PushResult .fromResponse (response );
113+ }
114+
115+ public PushResult sendPushValidate (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
116+ Preconditions .checkArgument (! (null == pushPayload ), "pushPayload should not be null" );
117+
118+ if (_globalSettingEnabled ) {
119+ pushPayload .resetOptionsTimeToLive (_timeToLive );
120+ pushPayload .resetOptionsApnsProduction (_apnsProduction );
121+ }
122+
123+ ResponseWrapper response = _httpClient .sendPost (_baseUrl + PUSH_VALIDATE_PATH , pushPayload .toString ());
110124
111125 return PushResult .fromResponse (response );
112126 }
@@ -120,11 +134,26 @@ public PushResult sendPush(String payloadString) throws APIConnectionException,
120134 Preconditions .checkArgument (false , "payloadString should be a valid JSON string." );
121135 }
122136
123- ResponseWrapper response = _httpClient .sendPost (_baseUrl , payloadString );
137+ ResponseWrapper response = _httpClient .sendPost (_baseUrl + PUSH_PATH , payloadString );
138+
139+ return PushResult .fromResponse (response );
140+ }
141+
142+ public PushResult sendPushValidate (String payloadString ) throws APIConnectionException , APIRequestException {
143+ Preconditions .checkArgument (StringUtils .isNotEmpty (payloadString ), "pushPayload should not be empty" );
144+
145+ try {
146+ _jsonParser .parse (payloadString );
147+ } catch (JsonParseException e ) {
148+ Preconditions .checkArgument (false , "payloadString should be a valid JSON string." );
149+ }
150+
151+ ResponseWrapper response = _httpClient .sendPost (_baseUrl + PUSH_VALIDATE_PATH , payloadString );
124152
125153 return PushResult .fromResponse (response );
126154 }
127155
156+
128157}
129158
130159
0 commit comments