wjc
8 小时以前 4bc924d0ce29560a5e1ad1adf1042de032d954a1
app/src/main/java/com/hdl/photovoltaic/other/HdlPushLogic.java
@@ -2,14 +2,21 @@
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;
@@ -47,6 +54,78 @@
    }
    /**
     * 添加推送Token
     *
     * @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的推送Token,在极光为RegId
        json.addProperty("software", "PHOTOVOLTAIC");//软件来源把PHOTOVOLTAIC改成XENTERRA,也就云端说的通道号(channel)
        json.addProperty("platform", "ALIYUN_APNS");//阿里云的版本的platform
//        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);
                }
            }
        });
    }
    /**
     * 删除推送Token
     *
     * @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             上下文
@@ -72,7 +151,7 @@
            }
        } else {
//            if (isOpened) {
                //产品经理说暂时不做 2024年03月29日10:34:44
            //产品经理说暂时不做 2024年03月29日10:34:44
//                boolean existsActivity = AppManagerUtils.getAppManager().existsActivity(MessageCenterListActivity.class);
//                if (existsActivity) {
//                    //存在唯一一种可能就是当前活动窗口就是它
@@ -157,6 +236,22 @@
                        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)) {