1515import cn .jpush .api .push .model .EncryptPushPayload ;
1616import cn .jpush .api .push .model .PushPayload ;
1717import com .google .gson .Gson ;
18+ import com .google .gson .JsonElement ;
19+ import com .google .gson .JsonObject ;
20+ import com .google .gson .JsonParser ;
1821import com .google .gson .reflect .TypeToken ;
1922
2023import java .util .Map ;
@@ -29,6 +32,8 @@ public class GroupPushClient {
2932 private String _groupPushPath ;
3033 private String _encryptType ;
3134 private Gson _gson = new Gson ();
35+ private JsonParser _jsonParser = new JsonParser ();
36+
3237
3338 public GroupPushClient (String groupMasterSecret , String groupKey ) {
3439 this (groupMasterSecret , groupKey , null , ClientConfig .getInstance ());
@@ -43,11 +48,17 @@ public GroupPushClient(String groupMasterSecret, String groupKey, HttpProxy prox
4348 this ._httpClient = new NativeHttpClient (authCode , proxy , conf );
4449 }
4550
46- public Map < String , PushResult > sendGroupPush (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
51+ public GroupPushResult sendGroupPush (PushPayload pushPayload ) throws APIConnectionException , APIRequestException {
4752 Preconditions .checkArgument (! (null == pushPayload ), "pushPayload should not be null" );
4853 ResponseWrapper response = _httpClient .sendPost (_baseUrl + _groupPushPath , getEncryptData (pushPayload ));
49- return _gson .fromJson (response .responseContent ,
50- new TypeToken <Map <String , PushResult >>(){}.getType ());
54+ // 2020-8-6 兼容分组推送新返回的group_msgid结构
55+ JsonObject responseJson = _jsonParser .parse (response .responseContent ).getAsJsonObject ();
56+ String groupMsgIdKey = "group_msgid" ;
57+ JsonElement _groupMsgId = responseJson .get (groupMsgIdKey );
58+ String groupMsgId = null != _groupMsgId ? _groupMsgId .getAsString () : "" ;
59+ responseJson .remove (groupMsgIdKey );
60+ Map <String , PushResult > result = _gson .fromJson (responseJson , new TypeToken <Map <String , PushResult >>(){}.getType ());
61+ return new GroupPushResult (groupMsgId , result );
5162 }
5263
5364 /**
0 commit comments