66import android .support .v4 .app .NotificationCompat ;
77import android .text .TextUtils ;
88
9+ import com .alibaba .fastjson .JSON ;
10+ import com .alibaba .fastjson .JSONObject ;
911import com .netease .im .IMApplication ;
1012import com .netease .im .session .extension .RedPacketOpenAttachement ;
13+ import com .netease .im .uikit .common .util .log .LogUtil ;
1114import com .netease .nimlib .sdk .NIMClient ;
1215import com .netease .nimlib .sdk .msg .MessageBuilder ;
1316import com .netease .nimlib .sdk .msg .MsgService ;
@@ -88,6 +91,7 @@ public static void sendAddFriendNotification(String account, String content) {
8891 }
8992
9093 public static void receiver (NotificationManager manager , CustomNotification customNotification ) {
94+ LogUtil .i ("SessionUtil" , customNotification .getFromAccount ());
9195 Map <String , Object > map = customNotification .getPushPayload ();
9296 if (map != null && map .containsKey ("type" )) {
9397 String type = (String ) map .get ("type" );
@@ -101,32 +105,37 @@ public static void receiver(NotificationManager manager, CustomNotification cust
101105 builder .setContentIntent (contentIntent );
102106 builder .setSmallIcon (IMApplication .getNotify_msg_drawable_id ());
103107 manager .notify ((int ) System .currentTimeMillis (), builder .build ());
104- } else if (SessionUtil .CUSTOM_Notification_redpacket_open .equals (type )) {
105- Map <String , Object > data = (Map <String , Object >) map .get ("data" );
106-
107- Map <String , Object > dict = (Map <String , Object >) data .get ("dict" );
108- String sendId = (String ) dict .get ("sendId" );
109- String openId = (String ) dict .get ("openId" );
110- String hasRedPacket = (String ) dict .get ("hasRedPacket" );
111- String serialNo = (String ) dict .get ("serialNo" );
112-
113- String timestamp = (String ) data .get ("timestamp" );
114- long t = 0L ;
115- try {
116- t = Long .parseLong (timestamp );
117- } catch (NumberFormatException e ) {
118- t = System .currentTimeMillis () / 1000 ;
119- e .printStackTrace ();
120- }
108+ } else {
109+ String content = customNotification .getContent ();
110+ if (!TextUtils .isEmpty (content )) {
111+ JSONObject object = JSON .parseObject (content );
112+ JSONObject data = object .getJSONObject ("data" );
113+
114+ JSONObject dict = data .getJSONObject ("dict" );
115+ String sendId = dict .getString ("sendId" );
116+ String openId = dict .getString ("openId" );
117+ String hasRedPacket = dict .getString ("hasRedPacket" );
118+ String serialNo = dict .getString ("serialNo" );
119+
120+ String timestamp = data .getString ("timestamp" );
121+ long t = 0L ;
122+ try {
123+ t = Long .parseLong (timestamp );
124+ } catch (NumberFormatException e ) {
125+ t = System .currentTimeMillis () / 1000 ;
126+ e .printStackTrace ();
127+ }
121128// LogUtil.i("timestamp","timestamp:"+timestamp);
122129// LogUtil.i("timestamp","t:"+t);
123130// LogUtil.i("timestamp",""+data);
124- String sessionId = (String ) data .get ("sessionId" );
125- String sessionType = (String ) data .get ("sessionType" );
126- final String id = getSessionType (sessionType ) == SessionTypeEnum .P2P ? openId : sessionId ;
127- sendRedPacketOpenLocal (id , getSessionType (sessionType ), sendId , openId , hasRedPacket , serialNo , t );
131+ String sessionId = (String ) data .get ("sessionId" );
132+ String sessionType = (String ) data .get ("sessionType" );
133+ final String id = getSessionType (sessionType ) == SessionTypeEnum .P2P ? openId : sessionId ;
134+ sendRedPacketOpenLocal (id , getSessionType (sessionType ), sendId , openId , hasRedPacket , serialNo , t );
135+ }
128136 }
129137 }
138+
130139 }
131140
132141 /**
0 commit comments