1414import cn .jpush .api .push .model .*;
1515import cn .jpush .api .push .model .audience .Audience ;
1616import com .google .gson .*;
17- import com .google .gson .reflect .TypeToken ;
1817
19- import java .lang .reflect .Type ;
20- import java .util .HashMap ;
2118import java .util .List ;
22- import java .util .Map ;
2319
2420/**
2521 * Entrance for sending Push.
@@ -39,6 +35,7 @@ public class PushClient {
3935 private String _pushValidatePath ;
4036 private String batchRegidPushPath ;
4137 private String batchAliasPushPath ;
38+ private String _filePushPath ;
4239
4340 private JsonParser _jsonParser = new JsonParser ();
4441
@@ -92,6 +89,7 @@ public PushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPro
9289 this ._baseUrl = (String ) conf .get (ClientConfig .PUSH_HOST_NAME );
9390 this ._pushPath = (String ) conf .get (ClientConfig .PUSH_PATH );
9491 this ._pushValidatePath = (String ) conf .get (ClientConfig .PUSH_VALIDATE_PATH );
92+ this ._filePushPath = (String ) conf .get (ClientConfig .FILE_PUSH_PATH );
9593
9694 this ._apnsProduction = (Integer ) conf .get (ClientConfig .APNS_PRODUCTION );
9795 this ._timeToLive = (Long ) conf .get (ClientConfig .TIME_TO_LIVE );
@@ -106,6 +104,7 @@ public PushClient(String masterSecret, String appKey, HttpProxy proxy, ClientCon
106104 this ._baseUrl = (String ) conf .get (ClientConfig .PUSH_HOST_NAME );
107105 this ._pushPath = (String ) conf .get (ClientConfig .PUSH_PATH );
108106 this ._pushValidatePath = (String ) conf .get (ClientConfig .PUSH_VALIDATE_PATH );
107+ this ._filePushPath = (String ) conf .get (ClientConfig .FILE_PUSH_PATH );
109108
110109 this .batchAliasPushPath = (String ) conf .get (ClientConfig .BATCH_ALIAS_PUSH_PATH );
111110 this .batchRegidPushPath = (String ) conf .get (ClientConfig .BATCH_REGID_PUSH_PATH );
@@ -162,35 +161,16 @@ public void setBaseUrl(String baseUrl) {
162161 }
163162
164163 public PushResult sendPush (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
165- Preconditions .checkArgument (!(null == pushPayload ), "pushPayload should not be null" );
166-
167- if (_apnsProduction > 0 ) {
168- pushPayload .resetOptionsApnsProduction (true );
169- } else if (_apnsProduction == 0 ) {
170- pushPayload .resetOptionsApnsProduction (false );
171- }
172-
173- if (_timeToLive >= 0 ) {
174- pushPayload .resetOptionsTimeToLive (_timeToLive );
175- }
164+ checkPushPayload (pushPayload );
176165
177166 ResponseWrapper response = _httpClient .sendPost (_baseUrl + _pushPath , getEncryptData (pushPayload ));
178167
179168 return BaseResult .fromResponse (response , PushResult .class );
180169 }
181170
182- public PushResult sendPushValidate (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
183- Preconditions .checkArgument (!(null == pushPayload ), "pushPayload should not be null" );
184-
185- if (_apnsProduction > 0 ) {
186- pushPayload .resetOptionsApnsProduction (true );
187- } else if (_apnsProduction == 0 ) {
188- pushPayload .resetOptionsApnsProduction (false );
189- }
190171
191- if (_timeToLive >= 0 ) {
192- pushPayload .resetOptionsTimeToLive (_timeToLive );
193- }
172+ public PushResult sendPushValidate (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
173+ checkPushPayload (pushPayload );
194174
195175 ResponseWrapper response = _httpClient .sendPost (_baseUrl + _pushValidatePath , getEncryptData (pushPayload ));
196176
@@ -211,6 +191,14 @@ public PushResult sendPush(String payloadString) throws APIConnectionException,
211191 return BaseResult .fromResponse (response , PushResult .class );
212192 }
213193
194+ public PushResult sendFilePush (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
195+ checkPushPayload (pushPayload );
196+
197+ ResponseWrapper response = _httpClient .sendPost (_baseUrl + _filePushPath , getEncryptData (pushPayload ));
198+
199+ return BaseResult .fromResponse (response , PushResult .class );
200+ }
201+
214202 public PushResult sendPushValidate (String payloadString ) throws APIConnectionException , APIRequestException {
215203 Preconditions .checkArgument (StringUtils .isNotEmpty (payloadString ), "pushPayload should not be empty" );
216204
@@ -358,6 +346,20 @@ private String getEncryptData(String pushPayload, Audience audience) {
358346 return pushPayload ;
359347 }
360348
349+ private void checkPushPayload (PushPayload pushPayload ) {
350+ Preconditions .checkArgument (!(null == pushPayload ), "pushPayload should not be null" );
351+
352+ if (_apnsProduction > 0 ) {
353+ pushPayload .resetOptionsApnsProduction (true );
354+ } else if (_apnsProduction == 0 ) {
355+ pushPayload .resetOptionsApnsProduction (false );
356+ }
357+
358+ if (_timeToLive >= 0 ) {
359+ pushPayload .resetOptionsTimeToLive (_timeToLive );
360+ }
361+ }
362+
361363}
362364
363365
0 commit comments