| | |
| | | package com.hdl.photovoltaic.jpush; |
| | | |
| | | import android.content.Context; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.gson.Gson; |
| | | import com.hdl.photovoltaic.other.HdlJpushLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | import cn.jpush.android.api.CustomMessage; |
| | | import cn.jpush.android.api.NotificationMessage; |
| | |
| | | */ |
| | | public class JPushReceiverService extends JPushMessageService { |
| | | |
| | | |
| | | /** |
| | | * 自定义消息回调 |
| | | * |
| | |
| | | */ |
| | | public void onMessage(Context context, CustomMessage customMessage) { |
| | | |
| | | HdlLogLogic.print("极光->自定义消息回调====>" + new Gson().toJson(customMessage), true); |
| | | HdlLogLogic.print("极光---自定义消息回调---" + new Gson().toJson(customMessage), false); |
| | | } |
| | | |
| | | /** |
| | | * 点击通知回调 |
| | | * 点击通知栏回调 |
| | | * |
| | | * @param context Context |
| | | * @param message 接收到的通知内容 |
| | | */ |
| | | public void onNotifyMessageOpened(Context context, NotificationMessage message) { |
| | | HdlLogLogic.print("极光->点击通知回调====>" + new Gson().toJson(message), true); |
| | | |
| | | JPushMessageInfoBean jPushMessageInfoBean = pushDataProcessing(message); |
| | | HdlJpushLogic.getInstance().JpushPushCommonData(context, jPushMessageInfoBean, true); |
| | | // //点击后删除本地通知 |
| | | // JPushInterface.clearAllNotifications(context); |
| | | } |
| | | |
| | | /** |
| | | * 收到通知回调 |
| | | * 收到推送通知回调 |
| | | * |
| | | * @param context Context |
| | | * @param message 接收到的通知内容 |
| | | */ |
| | | public void onNotifyMessageArrived(Context context, NotificationMessage message) { |
| | | HdlLogLogic.print("极光->接收到的通知内容====>" + new Gson().toJson(message), true); |
| | | |
| | | JPushMessageInfoBean jPushMessageInfoBean = pushDataProcessing(message); |
| | | HdlJpushLogic.getInstance().JpushPushCommonData(context, jPushMessageInfoBean, false); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param registrationId 注册 id |
| | | */ |
| | | public void onRegister(Context context, String registrationId) { |
| | | HdlLogLogic.print("极光->注册成功回调Id====>" + registrationId, true); |
| | | HdlLogLogic.print("极光---注册成功回调Id:" + registrationId, false); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param isConnected 长连接状态 |
| | | */ |
| | | public void onConnected(Context context, boolean isConnected) { |
| | | HdlLogLogic.print("极光->长连接状态回调====>" + isConnected, true); |
| | | HdlLogLogic.print("极光---长连接状态回调:" + isConnected, false); |
| | | } |
| | | |
| | | /** |
| | | * 推送数据作处理 |
| | | */ |
| | | private JPushMessageInfoBean pushDataProcessing(NotificationMessage message) { |
| | | try { |
| | | JPushMessageInfoBean jPushMessageInfoBean = new JPushMessageInfoBean(); |
| | | String title = message.notificationTitle; |
| | | String content = message.notificationContent; |
| | | String pushData = message.notificationExtras; |
| | | jPushMessageInfoBean.setTitle(title); |
| | | jPushMessageInfoBean.setContent(content); |
| | | if (TextUtils.isEmpty(pushData)) { |
| | | return jPushMessageInfoBean; |
| | | } |
| | | JSONObject expandDataObject = JSON.parseObject(pushData); |
| | | if (expandDataObject.containsKey("expandData")) { |
| | | String expandDataJson = Objects.requireNonNull(expandDataObject.get("expandData")).toString(); |
| | | if (TextUtils.isEmpty(expandDataJson)) { |
| | | return jPushMessageInfoBean; |
| | | } |
| | | jPushMessageInfoBean.setExpandData(expandDataJson); |
| | | JSONObject expantContentObject = JSON.parseObject(expandDataJson); |
| | | if (expantContentObject.containsKey("messageType")) { |
| | | String messageType = Objects.requireNonNull(expantContentObject.get("messageType")).toString(); |
| | | if (!TextUtils.isEmpty(messageType)) { |
| | | jPushMessageInfoBean.setMessageType(messageType); |
| | | } |
| | | } |
| | | if (expantContentObject.containsKey("homeId")) { |
| | | String homeId = Objects.requireNonNull(expantContentObject.get("homeId")).toString(); |
| | | if (!TextUtils.isEmpty(homeId)) { |
| | | jPushMessageInfoBean.setHomeId(homeId); |
| | | } |
| | | } |
| | | if (expantContentObject.containsKey("expantContent")) { |
| | | String expantContentJosn = Objects.requireNonNull(expantContentObject.get("expantContent")).toString(); |
| | | if (!TextUtils.isEmpty(expantContentJosn)) { |
| | | jPushMessageInfoBean.setExpantContent(expantContentJosn); |
| | | } |
| | | } |
| | | } |
| | | return jPushMessageInfoBean; |
| | | } catch (Exception e) { |
| | | return new JPushMessageInfoBean(); |
| | | } |
| | | } |
| | | |
| | | } |