From f151e203da870dbe281defcb1daf84a1a38ecac1 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期一, 29 十二月 2025 09:59:57 +0800
Subject: [PATCH] Merge branch 'master' into google

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlPushLogic.java |  264 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 264 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlPushLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlPushLogic.java
new file mode 100644
index 0000000..004975e
--- /dev/null
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlPushLogic.java
@@ -0,0 +1,264 @@
+package com.hdl.photovoltaic.other;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.text.TextUtils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.photovoltaic.config.AppConfigManage;
+import com.hdl.photovoltaic.config.ConstantManage;
+import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.enums.MessageStateType;
+import com.hdl.photovoltaic.internet.HttpClient;
+import com.hdl.photovoltaic.internet.api.HttpApi;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.push.PushMessageInfoBean;
+import com.hdl.photovoltaic.ui.BPowerStationActivity;
+import com.hdl.photovoltaic.ui.bean.MessageBean;
+import com.hdl.photovoltaic.utils.SharedPreUtils;
+import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
+
+import org.greenrobot.eventbus.EventBus;
+
+import java.util.Objects;
+
+import cn.jpush.android.api.NotificationMessage;
+
+
+/**
+ * 鏋佸厜鎺ㄩ�佷俊鎭鐞嗛�昏緫
+ */
+public class HdlPushLogic {
+    private static volatile HdlPushLogic sHdlPushLogic;
+
+    /**
+     * 鑾峰彇褰撳墠瀵硅薄
+     *
+     * @return HdlAccountLogic
+     */
+    public static synchronized HdlPushLogic getInstance() {
+        if (sHdlPushLogic == null) {
+            synchronized (HdlPushLogic.class) {
+                if (sHdlPushLogic == null) {
+                    sHdlPushLogic = new HdlPushLogic();
+                }
+            }
+
+        }
+        return sHdlPushLogic;
+    }
+
+    /**
+     * 娣诲姞鎺ㄩ�乀oken
+     *
+     * @param cloudCallBeak -
+     */
+    public void pushAdd(CloudCallBeak<String> cloudCallBeak) {
+        String requestUrl = HttpApi.POST_push_add;
+        JsonObject json = new JsonObject();
+        json.addProperty("deviceName", Build.MODEL);//璁惧鍚嶇О
+        json.addProperty("deviceType", "Android");//璁惧绫诲瀷
+        json.addProperty("produce", AppConfigManage.isIsOnlineServer());//琛ㄧず鏄惁鏄寮忔湇鍔″櫒
+        json.addProperty("pushToken", UserConfigManage.getInstance().getPushToken());//App鐨勬帹閫乀oken锛屽湪鏋佸厜涓篟egId
+        json.addProperty("software", "PHOTOVOLTAIC");//涔熷氨浜戠璇寸殑閫氶亾鍙凤紙channel)
+        json.addProperty("platform", "ALIYUN_APNS");//闃块噷浜戠殑鐗堟湰鐨刾latform
+//        json.addProperty("platform", "FCM");//google鐨勭増鏈殑platform
+        json.addProperty("language", UserConfigManage.getInstance().getCurrentAppLanguage());//2.0杩藉姞鐨勫瓧娈�
+
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+            @Override
+            public void onSuccess(String pushId) {
+                if (!TextUtils.isEmpty(pushId)) {
+                    UserConfigManage.getInstance().setPushId(pushId);
+                    UserConfigManage.getInstance().Save();
+                }
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(pushId);
+                }
+
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onFailure(e);
+                }
+            }
+        });
+
+
+    }
+
+    /**
+     * 鍒犻櫎鎺ㄩ�乀oken
+     *
+     * @param cloudCallBeak -
+     */
+    public void pushDel(CloudCallBeak<String> cloudCallBeak) {
+        String requestUrl = HttpApi.POST_push_del;
+        JsonObject json = new JsonObject();
+        json.addProperty("pushId", UserConfigManage.getInstance().getPushId());
+        json.addProperty("pushToken", UserConfigManage.getInstance().getPushToken());
+
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+            @Override
+            public void onSuccess(String jsonStr) {
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(jsonStr);
+                }
+
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onFailure(e);
+                }
+            }
+        });
+
+
+    }
+
+    /**
+     * 鎺ㄩ�佹暟鎹粺涓�澶勭悊鐨勬柟娉�
+     *
+     * @param context             涓婁笅鏂�
+     * @param pushMessageInfoBean 鎺ㄩ�佹暟鎹璞″疄浣�
+     * @param isAppInForeground   true琛ㄧず鏄墠鍙帮紝false琛ㄧず鍚庡彴
+     */
+    public void PushPushCommonData(Context context, PushMessageInfoBean pushMessageInfoBean, boolean isAppInForeground) {
+        if (UserConfigManage.getInstance().isBAccount()) {
+            //娣诲姞鎺ㄩ�佹暟鎹埌缂撳瓨鍒楄〃涓�;
+//            this.addPushDataToMemoryList(pushMessageInfoBean);
+            if (isAppInForeground) {
+                //搴旂敤鍦ㄥ墠鍙伴�氱煡鏇存柊浣忓畢娑堟伅鍒楄〃鍗冲彲
+                BaseEventBus bus = new BaseEventBus();
+                bus.setTopic(ConstantManage.refresh_message_house);
+                bus.setType(ConstantManage.refresh_message_house);
+                EventBus.getDefault().postSticky(bus);
+            } else {
+                // 瀹夎鍟嗚烦杞晫闈�
+//                Intent intent = new Intent(context, BPowerStationActivity.class);
+//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//                intent.putExtra("skip", "skip");//閲岄潰鍒ゆ柇鏈夎繖涓爣璇嗗氨璺宠浆鍒版秷鎭腑蹇冪晫闈�
+//                context.startActivity(intent);
+            }
+        } else {
+//            if (isOpened) {
+            //浜у搧缁忕悊璇存殏鏃朵笉鍋� 2024骞�03鏈�29鏃�10:34:44
+
+//            }
+        }
+    }
+
+
+    /**
+     * 娣诲姞鍦ㄦ帹閫佹暟鎹埌缂撳瓨鍒楄〃涓�
+     */
+    private void addPushDataToMemoryList(PushMessageInfoBean pushMessageInfoBean) {
+        try {
+            boolean isPushAddCache = SharedPreUtils.getBoolean("pushAddCache");
+            if (!isPushAddCache) {
+                //鏈夊彲鑳藉垹闄ゆ帹閫乀oken鎺ュ彛澶辫触锛屾崲璐﹀彿鍚庯紝渚濈劧涔熶細鏀跺埌涓婃璐﹀彿鐨勬帹閫�;
+                return;
+            }
+            if (TextUtils.isEmpty(pushMessageInfoBean.getExpantContent())) {
+                return;
+            }
+            Gson gson = new Gson();
+            MessageBean messageBean = gson.fromJson(pushMessageInfoBean.getExpantContent(), MessageBean.class);
+            if (messageBean == null) {
+                return;
+            }
+            messageBean.setTitle(pushMessageInfoBean.getContent());
+            messageBean.setDeviceDesc(pushMessageInfoBean.getContent());
+            HdlMessageLogic.getInstance().setListMessage(messageBean, 0);
+            HdlLogLogic.print("鏋佸厜鎺ㄩ��---娣诲姞鍦ㄦ帹閫佹暟鎹埌缂撳瓨鍒楄〃涓�---" + new Gson().toJson(pushMessageInfoBean));
+        } catch (Exception ignored) {
+        }
+    }
+
+    /**
+     * 鎺ㄩ�佹暟鎹綔杞寚瀹氭帹閫佹ā鍨�
+     *
+     * @param title   鎺ㄩ�佹爣棰� 鍙�夊弬鏁�(涓嶅瓨鍦ㄤ紶绌哄瓧绗�)
+     * @param content 鎺ㄩ�佸唴瀹� 鍙�夊弬鏁�(涓嶅瓨鍦ㄤ紶绌哄瓧绗�)
+     * @param data    娑堟伅鎷撳睍璐熻浇鏁版嵁 鍙�夊弬鏁�(涓嶅瓨鍦ㄤ紶绌哄瓧绗�)
+     */
+    public PushMessageInfoBean pushDataProcessing(String title, String content, String data) {
+        try {
+            PushMessageInfoBean pushMessageInfoBean = new PushMessageInfoBean();
+            pushMessageInfoBean.setTitle(title);
+            pushMessageInfoBean.setContent(content);
+            if (TextUtils.isEmpty(data)) {
+                return pushMessageInfoBean;
+            }
+            JSONObject pushDataObject = JSON.parseObject(data);
+            if (pushDataObject.containsKey("expandData")) {
+                String expandDataJson = Objects.requireNonNull(pushDataObject.get("expandData")).toString();
+                if (TextUtils.isEmpty(expandDataJson)) {
+                    return pushMessageInfoBean;
+                }
+                pushMessageInfoBean.setExpandData(expandDataJson);
+                JSONObject expandDataObject = JSON.parseObject(expandDataJson);
+                if (expandDataObject.containsKey("messageType")) {
+                    String messageType = Objects.requireNonNull(expandDataObject.get("messageType")).toString();
+                    if (!TextUtils.isEmpty(messageType)) {
+                        pushMessageInfoBean.setMessageType(messageType);
+                    }
+                }
+                if (TextUtils.isEmpty(title)) {
+                    if (expandDataObject.containsKey("title")) {
+                        String messageTitle = Objects.requireNonNull(expandDataObject.get("title")).toString();
+                        if (!TextUtils.isEmpty(messageTitle)) {
+                            pushMessageInfoBean.setTitle(messageTitle);
+                        }
+                    }
+                }
+                if (TextUtils.isEmpty(content)) {
+                    if (expandDataObject.containsKey("content")) {
+                        String messageContent = Objects.requireNonNull(expandDataObject.get("content")).toString();
+                        if (!TextUtils.isEmpty(messageContent)) {
+                            pushMessageInfoBean.setTitle(messageContent);
+                        }
+                    }
+                }
+                if (expandDataObject.containsKey("homeId")) {
+                    String homeId = Objects.requireNonNull(expandDataObject.get("homeId")).toString();
+                    if (!TextUtils.isEmpty(homeId)) {
+                        pushMessageInfoBean.setHomeId(homeId);
+                    }
+                }
+                if (expandDataObject.containsKey("expantContent")) {
+                    String expantContentJson = Objects.requireNonNull(expandDataObject.get("expantContent")).toString();
+                    if (!TextUtils.isEmpty(expantContentJson)) {
+                        pushMessageInfoBean.setExpantContent(expantContentJson);
+                    }
+                    JSONObject expantContentObject = JSON.parseObject(expantContentJson);
+                    if (expantContentObject.containsKey("aiPrompt")) {
+                        String aiPrompt = Objects.requireNonNull(expantContentObject.get("aiPrompt")).toString();
+                        if (!TextUtils.isEmpty(aiPrompt)) {
+                            pushMessageInfoBean.setAiPrompt(Boolean.parseBoolean(aiPrompt));
+                        }
+                    }
+                    if (expantContentObject.containsKey("msgId")) {
+                        String msgId = Objects.requireNonNull(expantContentObject.get("msgId")).toString();
+                        if (!TextUtils.isEmpty(msgId)) {
+                            pushMessageInfoBean.setMsgId(msgId);
+                        }
+                    }
+
+                }
+            }
+            return pushMessageInfoBean;
+        } catch (Exception e) {
+            return new PushMessageInfoBean();
+        }
+    }
+}

--
Gitblit v1.8.0