瀏覽代碼

修改消息推送

udream-cxs 4 年之前
父節點
當前提交
d9b3861a07

+ 162 - 162
lift-push/src/main/java/cn/com/ty/lift/push/app/MsgRequest.java

@@ -1,162 +1,162 @@
-package cn.com.ty.lift.push.app;
-
-import com.tencent.xinge.bean.AudienceType;
-import com.tencent.xinge.bean.Message;
-import com.tencent.xinge.bean.MessageType;
-import com.tencent.xinge.bean.Platform;
-import com.tencent.xinge.push.app.PushAppRequest;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-
-import java.util.ArrayList;
-
-/**
- * 消息推送参数封装,请求体
- *
- * @author wcz
- * @since 2020/2/10
- */
-@Data
-@AllArgsConstructor
-public class MsgRequest {
-
-    public static final Integer Android = 1;
-    public static final Integer Ios = 2;
-    /**
-     * 消息标题
-     */
-    private String title;
-    /**
-     * 消息内容
-     */
-    private String content;
-
-    /**
-     * 消息推送的平台 1:andorid 2:ios
-     */
-    private Integer platform;
-
-    /**
-     * 消息是否全平台发布(平台内所有账号全部推动)
-     */
-    private Boolean allPlatform;
-
-    /**
-     * 发送的账号列表
-     */
-    private ArrayList<String> accountList;
-
-    public static MsgRequest me(String title,String content,Integer platform,Boolean allPlatform,ArrayList<String> accountList){
-        return new MsgRequest(title,content,platform,allPlatform,accountList);
-    }
-
-    public static MsgRequest android(String title,String content,ArrayList<String> accountList){
-        return new MsgRequest(title,content,Android,false,accountList);
-    }
-
-    public static MsgRequest android(String title,String content){
-        return new MsgRequest(title,content,Android,true,null);
-    }
-
-    public static MsgRequest ios(String title,String content,ArrayList<String> accountList){
-        return new MsgRequest(title,content,Ios,false,accountList);
-    }
-
-    public static MsgRequest ios(String title,String content){
-        return new MsgRequest(title,content,Ios,true,null);
-    }
-
-    public boolean isAndroid(){
-        return this.getPlatform() == Android;
-    }
-
-    public boolean isIos(){
-        return this.getPlatform() == Ios;
-    }
-
-    public PushAppRequest pushAppRequest(){
-        /**
-         * https://xg.qq.com/docs/server_api/v3/push_api_v3.html#message%EF%BC%9A%E6%B6%88%E6%81%AF%E4%BD%93
-         */
-        Message message = new Message();
-        message.setTitle(this.getTitle());
-        message.setContent(this.getContent());
-        //推送请求信息
-        PushAppRequest pushAppRequest = new PushAppRequest();
-        //消息体
-        pushAppRequest.setMessage(message);
-        /**
-         * 消息类型
-         1)notify:通知
-         2)message:透传消息/静默消息
-         */
-        pushAppRequest.setMessage_type(MessageType.notify);
-        /**
-         * 客户端平台类型
-         1)android:安卓
-         2)ios:苹果
-         */
-        if (this.isAndroid()) {
-            pushAppRequest.setPlatform(Platform.android);
-        } else if (this.isIos()) {
-            pushAppRequest.setPlatform(Platform.ios);
-        } else {
-            return null;
-        }
-        /**
-         * 推送目标
-         1)all:全量推送
-         2)tag:标签推送
-         3)token:单设备推送
-         4)token_list:设备列表推送
-         5)account:单账号推送
-         6)account_list:账号列表推送
-         */
-
-        if (this.getAllPlatform()) {
-            pushAppRequest.setAudience_type(AudienceType.all);
-        } else {
-            ArrayList<String> accountList = this.getAccountList();
-            if (null == accountList || accountList.isEmpty()) {
-                return null;
-            }
-            if (accountList.size() == 1) {
-                pushAppRequest.setAudience_type(AudienceType.account);
-            } else {
-                pushAppRequest.setAudience_type(AudienceType.account_list);
-            }
-            //推送账号
-            pushAppRequest.setAccount_list(accountList);
-        }
-
-        //打印下推送数据
-        /**
-         * {
-         * 	"audience_type": "account",
-         * 	"platform": "android",
-         * 	"message_type": "notify",
-         * 	"message": {
-         * 		"title": "天域电梯测试",
-         * 		"content": "测试信鸽消息推送,当前时间: 2019-12-24 17:03:15",
-         * 		"accept_time": null,
-         * 		"android": null,
-         * 		"ios": null
-         *        },
-         * 	"expire_time": 259200,
-         * 	"send_time": null,
-         * 	"multi_pkg": false,
-         * 	"loop_times": 0,
-         * 	"loop_interval": 0,
-         * 	"environment": "product",
-         * 	"stat_tag": null,
-         * 	"seq": 0,
-         * 	"tag_list": null,
-         * 	"account_list": ["18571500256"],
-         * 	"account_type": 0,
-         * 	"token_list": [],
-         * 	"push_id": null
-         * }
-         */
-        return pushAppRequest;
-    }
-}
+//package cn.com.ty.lift.push.app;
+//
+//import com.tencent.xinge.bean.AudienceType;
+//import com.tencent.xinge.bean.Message;
+//import com.tencent.xinge.bean.MessageType;
+//import com.tencent.xinge.bean.Platform;
+//import com.tencent.xinge.push.app.PushAppRequest;
+//import lombok.AllArgsConstructor;
+//import lombok.Data;
+//
+//import java.util.ArrayList;
+//
+///**
+// * 消息推送参数封装,请求体
+// *
+// * @author wcz
+// * @since 2020/2/10
+// */
+//@Data
+//@AllArgsConstructor
+//public class MsgRequest {
+//
+//    public static final Integer Android = 1;
+//    public static final Integer Ios = 2;
+//    /**
+//     * 消息标题
+//     */
+//    private String title;
+//    /**
+//     * 消息内容
+//     */
+//    private String content;
+//
+//    /**
+//     * 消息推送的平台 1:andorid 2:ios
+//     */
+//    private Integer platform;
+//
+//    /**
+//     * 消息是否全平台发布(平台内所有账号全部推动)
+//     */
+//    private Boolean allPlatform;
+//
+//    /**
+//     * 发送的账号列表
+//     */
+//    private ArrayList<String> accountList;
+//
+//    public static MsgRequest me(String title,String content,Integer platform,Boolean allPlatform,ArrayList<String> accountList){
+//        return new MsgRequest(title,content,platform,allPlatform,accountList);
+//    }
+//
+//    public static MsgRequest android(String title,String content,ArrayList<String> accountList){
+//        return new MsgRequest(title,content,Android,false,accountList);
+//    }
+//
+//    public static MsgRequest android(String title,String content){
+//        return new MsgRequest(title,content,Android,true,null);
+//    }
+//
+//    public static MsgRequest ios(String title,String content,ArrayList<String> accountList){
+//        return new MsgRequest(title,content,Ios,false,accountList);
+//    }
+//
+//    public static MsgRequest ios(String title,String content){
+//        return new MsgRequest(title,content,Ios,true,null);
+//    }
+//
+//    public boolean isAndroid(){
+//        return this.getPlatform() == Android;
+//    }
+//
+//    public boolean isIos(){
+//        return this.getPlatform() == Ios;
+//    }
+//
+//    public PushAppRequest pushAppRequest(){
+//        /**
+//         * https://xg.qq.com/docs/server_api/v3/push_api_v3.html#message%EF%BC%9A%E6%B6%88%E6%81%AF%E4%BD%93
+//         */
+//        Message message = new Message();
+//        message.setTitle(this.getTitle());
+//        message.setContent(this.getContent());
+//        //推送请求信息
+//        PushAppRequest pushAppRequest = new PushAppRequest();
+//        //消息体
+//        pushAppRequest.setMessage(message);
+//        /**
+//         * 消息类型
+//         1)notify:通知
+//         2)message:透传消息/静默消息
+//         */
+//        pushAppRequest.setMessage_type(MessageType.notify);
+//        /**
+//         * 客户端平台类型
+//         1)android:安卓
+//         2)ios:苹果
+//         */
+//        if (this.isAndroid()) {
+//            pushAppRequest.setPlatform(Platform.android);
+//        } else if (this.isIos()) {
+//            pushAppRequest.setPlatform(Platform.ios);
+//        } else {
+//            return null;
+//        }
+//        /**
+//         * 推送目标
+//         1)all:全量推送
+//         2)tag:标签推送
+//         3)token:单设备推送
+//         4)token_list:设备列表推送
+//         5)account:单账号推送
+//         6)account_list:账号列表推送
+//         */
+//
+//        if (this.getAllPlatform()) {
+//            pushAppRequest.setAudience_type(AudienceType.all);
+//        } else {
+//            ArrayList<String> accountList = this.getAccountList();
+//            if (null == accountList || accountList.isEmpty()) {
+//                return null;
+//            }
+//            if (accountList.size() == 1) {
+//                pushAppRequest.setAudience_type(AudienceType.account);
+//            } else {
+//                pushAppRequest.setAudience_type(AudienceType.account_list);
+//            }
+//            //推送账号
+//            pushAppRequest.setAccount_list(accountList);
+//        }
+//
+//        //打印下推送数据
+//        /**
+//         * {
+//         * 	"audience_type": "account",
+//         * 	"platform": "android",
+//         * 	"message_type": "notify",
+//         * 	"message": {
+//         * 		"title": "天域电梯测试",
+//         * 		"content": "测试信鸽消息推送,当前时间: 2019-12-24 17:03:15",
+//         * 		"accept_time": null,
+//         * 		"android": null,
+//         * 		"ios": null
+//         *        },
+//         * 	"expire_time": 259200,
+//         * 	"send_time": null,
+//         * 	"multi_pkg": false,
+//         * 	"loop_times": 0,
+//         * 	"loop_interval": 0,
+//         * 	"environment": "product",
+//         * 	"stat_tag": null,
+//         * 	"seq": 0,
+//         * 	"tag_list": null,
+//         * 	"account_list": ["18571500256"],
+//         * 	"account_type": 0,
+//         * 	"token_list": [],
+//         * 	"push_id": null
+//         * }
+//         */
+//        return pushAppRequest;
+//    }
+//}

+ 68 - 62
lift-push/src/main/java/cn/com/ty/lift/push/app/PushConsumer.java

@@ -3,6 +3,8 @@ package cn.com.ty.lift.push.app;
 import cn.com.ty.lift.common.model.PushMessage;
 import cn.com.ty.lift.common.model.TimeMessage;
 import cn.com.ty.lift.common.utils.ValuePool;
+import cn.com.ty.lift.push.jiguang.JiGuangMessage;
+import cn.com.ty.lift.push.jiguang.JiGuangService;
 import cn.com.ty.lift.push.message.service.TimeMessageService;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -26,96 +28,100 @@ import java.util.List;
 @Component
 @AllArgsConstructor
 public class PushConsumer {
-    private static List<String> titles =
-            new ArrayList<>(Arrays.asList("公司公告", "团队消息", "年检消息", "保养消息", "急修消息", "提醒", "工作消息","订单消息","审核消息","邀请成为专家","附近的人","专家处罚","撤销专家处罚"));
-    private XingePush xingePush;
+    private static List<String> titles = new ArrayList<>(Arrays.asList("公司公告", "团队消息", "年检消息", "保养消息", "急修消息", "提醒", "工作消息", "订单消息", "审核消息", "邀请成为专家", "附近的人", "专家处罚", "撤销专家处罚"));
+    //    private XingePush xingePush;
     private JmsMessagingTemplate jmsMessagingTemplate;
-    private final TimeMessageService timeMessageService;
-
-    private class Processor {
-        private String destination;
-        private PushMessage pushMessage;
-        private boolean result;
-
-        private Processor(String destination, PushMessage pushMessage) {
-            this.destination = destination;
-            this.pushMessage = pushMessage;
-        }
-
-        private Processor perform() {
-            String title = pushMessage.getTitle();
-            String content = pushMessage.getContent();
-            List<String> toList = pushMessage.getToList();
-            switch (this.destination) {
-                case ValuePool.PUSH_QUEUE_ANDROID_TOKEN:
-                    result = xingePush.pushTokenOnAndroid(title, content, toList);
-                    break;
-                case ValuePool.PUSH_QUEUE_ANDROID_ALL:
-                    result = xingePush.pushAllOnAndroid(title, content);
-                    break;
-                case ValuePool.PUSH_QUEUE_IOS_TOKEN:
-                    result = xingePush.pushTokenOnIos(title, content, toList);
-                    break;
-                case ValuePool.PUSH_QUEUE_IOS_ALL:
-                    result = xingePush.pushAllOnIos(title, content);
-                    break;
-                default:
-                    result = true;
-            }
-            return this;
-        }
-
-        private void tryAgain() {
-            int tryCount = pushMessage.getTryCount();
-            if (!result && tryCount < ValuePool.PUSH_TRY_MAX_TIMES) {
-                pushMessage.setTryCount(tryCount + 1);
-                jmsMessagingTemplate.send(destination, new GenericMessage<>(pushMessage));
-            }
-        }
-    }
-
-    private void process(String destination, PushMessage pushMessage) {
-        if (pushMessage.needSplit()) {
-            List<ArrayList<String>> doSplit = pushMessage.doSplit(ValuePool.PUSH_MAX_SIZE);
-            for (ArrayList<String> list : doSplit) {
-                pushMessage.setToList(list);
-                new Processor(destination, pushMessage).perform().tryAgain();
-            }
-        } else {
-            new Processor(destination, pushMessage).perform().tryAgain();
-        }
-    }
+    private TimeMessageService timeMessageService;
+    private JiGuangService jiGuangService;
+
+//    private class Processor {
+//        private String destination;
+//        private PushMessage pushMessage;
+//        private boolean result;
+//
+//        private Processor(String destination, PushMessage pushMessage) {
+//            this.destination = destination;
+//            this.pushMessage = pushMessage;
+//        }
+//
+//        private Processor perform() {
+//            String title = pushMessage.getTitle();
+//            String content = pushMessage.getContent();
+//            List<String> toList = pushMessage.getToList();
+//            switch (this.destination) {
+//                case ValuePool.PUSH_QUEUE_ANDROID_TOKEN:
+//                    result = xingePush.pushTokenOnAndroid(title, content, toList);
+//                    break;
+//                case ValuePool.PUSH_QUEUE_ANDROID_ALL:
+//                    result = xingePush.pushAllOnAndroid(title, content);
+//                    break;
+//                case ValuePool.PUSH_QUEUE_IOS_TOKEN:
+//                    result = xingePush.pushTokenOnIos(title, content, toList);
+//                    break;
+//                case ValuePool.PUSH_QUEUE_IOS_ALL:
+//                    result = xingePush.pushAllOnIos(title, content);
+//                    break;
+//                default:
+//                    result = true;
+//            }
+//            return this;
+//        }
+//
+//        private void tryAgain() {
+//            int tryCount = pushMessage.getTryCount();
+//            if (!result && tryCount < ValuePool.PUSH_TRY_MAX_TIMES) {
+//                pushMessage.setTryCount(tryCount + 1);
+//                jmsMessagingTemplate.send(destination, new GenericMessage<>(pushMessage));
+//            }
+//        }
+//    }
+
+//    private void process(String destination, PushMessage pushMessage) {
+//        if (pushMessage.needSplit()) {
+//            List<ArrayList<String>> doSplit = pushMessage.doSplit(ValuePool.PUSH_MAX_SIZE);
+//            for (ArrayList<String> list : doSplit) {
+//                pushMessage.setToList(list);
+//                new Processor(destination, pushMessage).perform().tryAgain();
+//            }
+//        } else {
+//            new Processor(destination, pushMessage).perform().tryAgain();
+//        }
+//    }
 
     @JmsListener(destination = ValuePool.PUSH_QUEUE_ANDROID_TOKEN)
     public void listenAndroidTokenQueue(PushMessage pushMessage) {
         saveMessage(pushMessage);
 
+        jiGuangService.pushAndroid(JiGuangMessage.create(pushMessage), pushMessage.getToList());
         log.info("listen {} receive message:{}", ValuePool.PUSH_QUEUE_ANDROID_TOKEN, pushMessage);
-        process(ValuePool.PUSH_QUEUE_ANDROID_TOKEN, pushMessage);
+//        process(ValuePool.PUSH_QUEUE_ANDROID_TOKEN, pushMessage);
     }
 
     @JmsListener(destination = ValuePool.PUSH_QUEUE_ANDROID_ALL)
     public void listenAndroidAllQueue(PushMessage pushMessage) {
         saveMessage(pushMessage);
 
+        jiGuangService.pushAndroid(JiGuangMessage.create(pushMessage));
         log.info("listen {} receive message:{}", ValuePool.PUSH_QUEUE_ANDROID_ALL, pushMessage);
-        process(ValuePool.PUSH_QUEUE_ANDROID_ALL, pushMessage);
+//        process(ValuePool.PUSH_QUEUE_ANDROID_ALL, pushMessage);
     }
 
     @JmsListener(destination = ValuePool.PUSH_QUEUE_IOS_TOKEN)
     public void listenIosTokenQueue(PushMessage pushMessage) {
         saveMessage(pushMessage);
 
+        jiGuangService.pushIos(JiGuangMessage.create(pushMessage), pushMessage.getToList());
         log.info("listen {} receive message:{}", ValuePool.PUSH_QUEUE_IOS_TOKEN, pushMessage);
-        process(ValuePool.PUSH_QUEUE_IOS_TOKEN, pushMessage);
+//        process(ValuePool.PUSH_QUEUE_IOS_TOKEN, pushMessage);
     }
 
     @JmsListener(destination = ValuePool.PUSH_QUEUE_IOS_ALL)
     public void listenIosAllQueue(PushMessage pushMessage) {
         saveMessage(pushMessage);
 
+        jiGuangService.pushIos(JiGuangMessage.create(pushMessage));
         log.info("listen {} receive message:{}", ValuePool.PUSH_QUEUE_IOS_ALL, pushMessage);
-        process(ValuePool.PUSH_QUEUE_IOS_ALL, pushMessage);
+//        process(ValuePool.PUSH_QUEUE_IOS_ALL, pushMessage);
     }
 
     /**

+ 369 - 369
lift-push/src/main/java/cn/com/ty/lift/push/app/XingePush.java

@@ -1,369 +1,369 @@
-package cn.com.ty.lift.push.app;
-
-import cn.com.ty.lift.common.utils.ValuePool;
-import cn.hutool.core.date.DateUtil;
-import com.alibaba.fastjson.JSON;
-import com.tencent.xinge.XingeApp;
-import com.tencent.xinge.bean.*;
-import com.tencent.xinge.push.app.PushAppRequest;
-import com.tencent.xinge.push.app.PushAppResponse;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * 腾讯信鸽推动 https://xg.qq.com/docs/server_api/v3/push_api_v3.html
- *
- * @author wcz
- * @since 2020/2/10
- */
-@Slf4j
-public class XingePush {
-    private String appId     = "40d4e2e854433";
-    private String secretKey = "fa99dc19157b00fc71cf8d7e840273a3";
-
-    /**
-     * 消息推送 >>>
-     */
-    private XingeApp xingeApp;
-
-    /**
-     * 默认配置创建xinge push
-     */
-    public XingePush() {
-        xingeApp = new XingeApp(appId, secretKey);
-    }
-
-    /**
-     * 指定api密钥创建xinge push
-     */
-    public XingePush(String appId, String secretKey) {
-        this.appId = appId;
-        this.secretKey = secretKey;
-        xingeApp = new XingeApp(appId, secretKey);
-    }
-
-    /**
-     * 推送到android指定的token设备
-     * @param title 消息标题
-     * @param content 消息正文
-     * @param toList 推送的token
-     */
-    public boolean pushTokenOnAndroid(String title, String content, List<String> toList) {
-        return pushMessage(RequestBuilder.android(title, content, AudienceType.token.getType(), toList));
-    }
-    /**
-     * 推送到android指定的account设备
-     * @param title 消息标题
-     * @param content 消息正文
-     * @param toList 推送的account
-     */
-    public boolean pushAccountOnAndroid(String title, String content, List<String> toList) {
-        return pushMessage(RequestBuilder.android(title, content, AudienceType.account.getType(), toList));
-    }
-    /**
-     * 推送到android的所有设备
-     * @param title 消息标题
-     * @param content 消息正文
-     */
-    public boolean pushAllOnAndroid(String title, String content) {
-        return pushMessage(RequestBuilder.android(title, content));
-    }
-    /**
-     * 推送到ios指定的token设备
-     * @param title 消息标题
-     * @param content 消息正文
-     * @param toList 推送的token
-     */
-    public boolean pushTokenOnIos(String title, String content, List<String> toList) {
-        return pushMessage(RequestBuilder.ios(title, content, AudienceType.token.getType(), toList));
-    }
-    /**
-     * 推送到android指定的account设备
-     * @param title 消息标题
-     * @param content 消息正文
-     * @param toList 推送的account
-     */
-    public boolean pushAccountOnIos(String title, String content, List<String> toList) {
-        return pushMessage(RequestBuilder.ios(title, content, AudienceType.account.getType(), toList));
-    }
-    /**
-     * 推送到ios指定的token设备
-     * @param title 消息标题
-     * @param content 消息正文
-     */
-    public boolean pushAllOnIos(String title, String content) {
-        return pushMessage(RequestBuilder.ios(title, content));
-    }
-    /**
-     * 消息推送
-     */
-    private boolean pushMessage(RequestBuilder requestBuilder) {
-        PushAppRequest pushAppRequest = requestBuilder.createPushAppRequest();
-        if(Objects.isNull(pushAppRequest)){
-            return false;
-        }
-        String request = pushAppRequest.toString();
-        //推送结果 0是推送成功 PushAppResponse
-        /**
-         * seq	int64_t	是	与请求包一致(如果请求包是非法json该字段为0)
-         * push_id	string	是	推送id
-         * ret_code	int32_t	是	错误码,详细参照错误码对照表
-         * environment	string	是	用户指定推送环境,仅支持iOS product: 生产环境 dev: 开发环境
-         * err_msg	string	否	请求出错时的错误信息
-         * result	string	否	请求正确时,若有额外数据要返回,则结果封装在该字段的json中,若无额外数据,则可能无此字段
-         *
-         * {
-         * 	"result": "[0]",
-         * 	"environment": "product",
-         * 	"push_id": "1079290952",
-         * 	"err_msg": "",
-         * 	"ret_code": 0,
-         * 	"seq": 0
-         * }
-         */
-        log.info("Pushing PushAppRequest: {}", request);
-        try {
-            JSONObject pushApp = xingeApp.pushApp(request);
-            if (Objects.isNull(pushApp)) {
-                return false;
-            }
-            log.info("Push complete and response: {}", pushApp.toString());
-            PushAppResponse pushAppResponse = JSON.parseObject(pushApp.toString(), PushAppResponse.class);
-            return pushAppResponse.getRet_code() == 0;
-        } catch (Exception e) {
-            log.error("Push fail, occur exception:", e);
-            return false;
-        }
-    }
-
-    @Data
-    private static class RequestBuilder {
-        /**
-         * 消息标题
-         */
-        private String       title;
-        /**
-         * 消息内容
-         */
-        private String       content;
-        /**
-         * 消息推送的平台 1:android 2:ios
-         */
-        private Integer      platform;
-        /**
-         * 多种推送目标的,比如:全量、标签、单设备、设备列表、单账号、账号列表
-         * 0 all 1 tag 2 token 3 token_list 4 account 5 account_list
-         */
-        private int          audienceType;
-        /**
-         * 发送的账号列表/token_list
-         */
-        private List<String> toList;
-
-        private RequestBuilder(String title, String content, Integer platform, int audienceType){
-            this.title = title;
-            this.content = content;
-            this.platform = platform;
-            this.audienceType = audienceType;
-        }
-        private RequestBuilder(String title, String content, Integer platform, int audienceType, List<String> toList){
-            this.title = title;
-            this.content = content;
-            this.platform = platform;
-            this.audienceType = audienceType;
-            this.toList = toList;
-        }
-
-        public static RequestBuilder android(String title, String content, int audienceType, List<String> toList) {
-            return new RequestBuilder(title, content, Platform.android.getType(), audienceType, toList);
-        }
-
-        public static RequestBuilder android(String title, String content) {
-            return new RequestBuilder(title, content, Platform.android.getType(), AudienceType.all.getType());
-        }
-
-        public static RequestBuilder ios(String title, String content, int audienceType, List<String> toList) {
-            return new RequestBuilder(title, content, Platform.ios.getType(), audienceType, toList);
-        }
-
-        public static RequestBuilder ios(String title, String content) {
-            return new RequestBuilder(title, content, Platform.ios.getType(), AudienceType.all.getType());
-        }
-
-        public boolean isAndroid() {
-            return this.getPlatform() == Platform.android.getType();
-        }
-
-        public boolean isIos() {
-            return this.getPlatform() == Platform.ios.getType();
-        }
-
-        public boolean isToken(){
-            return this.audienceType == AudienceType.token.getType();
-        }
-
-        public boolean isAccount(){
-            return this.audienceType == AudienceType.account.getType();
-        }
-
-        public boolean isAll(){
-            return this.audienceType == AudienceType.all.getType();
-        }
-
-        public PushAppRequest createPushAppRequest() {
-            /**
-             * https://xg.qq.com/docs/server_api/v3/push_api_v3.html#message%EF%BC%9A%E6%B6%88%E6%81%AF%E4%BD%93
-             */
-            //推送请求信息
-            PushAppRequest pushAppRequest = new PushAppRequest();
-            /**
-             * 消息类型
-             1)notify:通知
-             2)message:透传消息/静默消息
-             */
-            pushAppRequest.setMessage_type(MessageType.notify);
-            /**
-             * 指定推送时间
-             * 1)格式为yyyy-MM-DD HH:MM:SS
-             * 2)若小于服务器当前时间,则会立即推送
-             * 3)仅全量推送和标签推送支持此字段
-             */
-            pushAppRequest.setSend_time(DateUtil.now());
-            /**
-             * 消息离线存储时间(单位为秒),最长72小时
-             * 1)若expire_time=0,则表示实时消息
-             * 2)若expire_time大于0且小于800s,则系统会重置为800s
-             * 3)若expire_time>=800s,按实际设置时间存储,最长72小时
-             * 4)设置的最大值不得超过2147483647,否则会导致推送失败
-             */
-            //pushAppRequest.setExpire_time(24 * 60 * 60);
-            /**
-             * 循环任务重复次数
-             * 1)仅支持全推、标签推
-             * 2)建议取值[1, 15]
-             */
-            //pushAppRequest.setLoop_times(2);
-            /**
-             * 循环执行消息下发的间隔
-             * 1)必须配合loop_times使用
-             * 2)以天为单位,取值[1, 14]
-             * 3)loop_times和loop_interval一起表示消息下发任务的循环规则
-             */
-            //pushAppRequest.setLoop_interval(2);
-            /**
-             * 客户端平台类型
-             1)android:安卓
-             2)ios:苹果
-             */
-            Message message = new Message();
-            message.setTitle(this.getTitle());
-            message.setContent(this.getContent());
-
-            if (this.isAndroid()) {
-                pushAppRequest.setPlatform(Platform.android);
-                MessageAndroid messageAndroid = new MessageAndroid();
-                /**
-                 * 通知消息对象的唯一标识(只对信鸽通道生效)
-                 * 1)大于0:会覆盖先前相同id的消息
-                 * 2)等于0:展示本条通知且不影响其他消息
-                 * 3)等于-1:将清除先前所有消息,仅展示本条消息
-                 */
-                messageAndroid.setN_id(0);
-//                ClickAction clickAction = new ClickAction();
-//                clickAction.setActivity("");
-//                messageAndroid.setAction(clickAction);
-                message.setAndroid(messageAndroid);
-            } else if (this.isIos()) {
-                pushAppRequest.setPlatform(Platform.ios);
-                Alert alert = new Alert();
-                alert.setTitle(this.getTitle());
-                alert.setBody(this.getContent());
-                Aps aps = new Aps();
-                aps.setAlert(alert);
-                MessageIOS messageIOS = new MessageIOS();
-                messageIOS.setAps(aps);
-                message.setIos(messageIOS);
-            } else {
-                log.error("Failed to Create PushAppRequest: Invalid platform type.(1:android, 2:ios)");
-                return null;
-            }
-            pushAppRequest.setMessage(message);
-            /**
-             * 推送目标
-             1)all:全量推送
-             2)tag:标签推送
-             3)token:单设备推送
-             4)token_list:设备列表推送,最多1000 token
-             5)account:单账号推送
-             6)account_list:账号列表推送,最多1000 个account
-             */
-            if (this.isAll()) {
-                pushAppRequest.setAudience_type(AudienceType.all);
-                return pushAppRequest;
-            } else {
-                if (null == toList || toList.isEmpty()) {
-                    log.error("Failed to Create PushAppRequest: 'toList' is null or empty when 'audienceType' is not 'ALL'.");
-                    return null;
-                }
-                if(toList.size() > ValuePool.PUSH_MAX_SIZE){
-                    log.error("Failed to Create PushAppRequest: the max size of 'toList' is 1000.");
-                    return null;
-                }
-                if (this.isToken()) {
-                    if (toList.size() == 1) {
-                        pushAppRequest.setAudience_type(AudienceType.token);
-                    } else {
-                        pushAppRequest.setAudience_type(AudienceType.token_list);
-                    }
-                    pushAppRequest.setToken_list(new ArrayList<>(toList));
-                    return pushAppRequest;
-                } else if (this.isAccount()) {
-                    if (toList.size() == 1) {
-                        pushAppRequest.setAudience_type(AudienceType.account);
-                    } else {
-                        pushAppRequest.setAudience_type(AudienceType.account_list);
-                    }
-                    pushAppRequest.setAccount_list(new ArrayList<>(toList));
-                    return pushAppRequest;
-                } else {
-                    log.error("Failed to Create PushAppRequest: 'audienceType' is not Invalid. (0:all, 2:token, 4:account)");
-                    return null;
-                }
-            }
-
-            //打印推送数据
-            /**
-             * {
-             * 	"audience_type": "account",
-             * 	"platform": "android",
-             * 	"message_type": "notify",
-             * 	"message": {
-             * 		"title": "天域电梯测试",
-             * 		"content": "测试信鸽消息推送,当前时间: 2019-12-24 17:03:15",
-             * 		"accept_time": null,
-             * 		"android": null,
-             * 		"ios": null
-             *        },
-             * 	"expire_time": 259200,
-             * 	"send_time": null,
-             * 	"multi_pkg": false,
-             * 	"loop_times": 0,
-             * 	"loop_interval": 0,
-             * 	"environment": "product",
-             * 	"stat_tag": null,
-             * 	"seq": 0,
-             * 	"tag_list": null,
-             * 	"account_list": ["18571500256"],
-             * 	"account_type": 0,
-             * 	"token_list": [],
-             * 	"push_id": null
-             * }
-             */
-        }
-    }
-}
+//package cn.com.ty.lift.push.app;
+//
+//import cn.com.ty.lift.common.utils.ValuePool;
+//import cn.hutool.core.date.DateUtil;
+//import com.alibaba.fastjson.JSON;
+//import com.tencent.xinge.XingeApp;
+//import com.tencent.xinge.bean.*;
+//import com.tencent.xinge.push.app.PushAppRequest;
+//import com.tencent.xinge.push.app.PushAppResponse;
+//import lombok.Data;
+//import lombok.extern.slf4j.Slf4j;
+//import org.json.JSONObject;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//import java.util.Objects;
+//
+///**
+// * 腾讯信鸽推动 https://xg.qq.com/docs/server_api/v3/push_api_v3.html
+// *
+// * @author wcz
+// * @since 2020/2/10
+// */
+//@Slf4j
+//public class XingePush {
+//    private String appId     = "40d4e2e854433";
+//    private String secretKey = "fa99dc19157b00fc71cf8d7e840273a3";
+//
+//    /**
+//     * 消息推送 >>>
+//     */
+//    private XingeApp xingeApp;
+//
+//    /**
+//     * 默认配置创建xinge push
+//     */
+//    public XingePush() {
+//        xingeApp = new XingeApp(appId, secretKey);
+//    }
+//
+//    /**
+//     * 指定api密钥创建xinge push
+//     */
+//    public XingePush(String appId, String secretKey) {
+//        this.appId = appId;
+//        this.secretKey = secretKey;
+//        xingeApp = new XingeApp(appId, secretKey);
+//    }
+//
+//    /**
+//     * 推送到android指定的token设备
+//     * @param title 消息标题
+//     * @param content 消息正文
+//     * @param toList 推送的token
+//     */
+//    public boolean pushTokenOnAndroid(String title, String content, List<String> toList) {
+//        return pushMessage(RequestBuilder.android(title, content, AudienceType.token.getType(), toList));
+//    }
+//    /**
+//     * 推送到android指定的account设备
+//     * @param title 消息标题
+//     * @param content 消息正文
+//     * @param toList 推送的account
+//     */
+//    public boolean pushAccountOnAndroid(String title, String content, List<String> toList) {
+//        return pushMessage(RequestBuilder.android(title, content, AudienceType.account.getType(), toList));
+//    }
+//    /**
+//     * 推送到android的所有设备
+//     * @param title 消息标题
+//     * @param content 消息正文
+//     */
+//    public boolean pushAllOnAndroid(String title, String content) {
+//        return pushMessage(RequestBuilder.android(title, content));
+//    }
+//    /**
+//     * 推送到ios指定的token设备
+//     * @param title 消息标题
+//     * @param content 消息正文
+//     * @param toList 推送的token
+//     */
+//    public boolean pushTokenOnIos(String title, String content, List<String> toList) {
+//        return pushMessage(RequestBuilder.ios(title, content, AudienceType.token.getType(), toList));
+//    }
+//    /**
+//     * 推送到android指定的account设备
+//     * @param title 消息标题
+//     * @param content 消息正文
+//     * @param toList 推送的account
+//     */
+//    public boolean pushAccountOnIos(String title, String content, List<String> toList) {
+//        return pushMessage(RequestBuilder.ios(title, content, AudienceType.account.getType(), toList));
+//    }
+//    /**
+//     * 推送到ios指定的token设备
+//     * @param title 消息标题
+//     * @param content 消息正文
+//     */
+//    public boolean pushAllOnIos(String title, String content) {
+//        return pushMessage(RequestBuilder.ios(title, content));
+//    }
+//    /**
+//     * 消息推送
+//     */
+//    private boolean pushMessage(RequestBuilder requestBuilder) {
+//        PushAppRequest pushAppRequest = requestBuilder.createPushAppRequest();
+//        if(Objects.isNull(pushAppRequest)){
+//            return false;
+//        }
+//        String request = pushAppRequest.toString();
+//        //推送结果 0是推送成功 PushAppResponse
+//        /**
+//         * seq	int64_t	是	与请求包一致(如果请求包是非法json该字段为0)
+//         * push_id	string	是	推送id
+//         * ret_code	int32_t	是	错误码,详细参照错误码对照表
+//         * environment	string	是	用户指定推送环境,仅支持iOS product: 生产环境 dev: 开发环境
+//         * err_msg	string	否	请求出错时的错误信息
+//         * result	string	否	请求正确时,若有额外数据要返回,则结果封装在该字段的json中,若无额外数据,则可能无此字段
+//         *
+//         * {
+//         * 	"result": "[0]",
+//         * 	"environment": "product",
+//         * 	"push_id": "1079290952",
+//         * 	"err_msg": "",
+//         * 	"ret_code": 0,
+//         * 	"seq": 0
+//         * }
+//         */
+//        log.info("Pushing PushAppRequest: {}", request);
+//        try {
+//            JSONObject pushApp = xingeApp.pushApp(request);
+//            if (Objects.isNull(pushApp)) {
+//                return false;
+//            }
+//            log.info("Push complete and response: {}", pushApp.toString());
+//            PushAppResponse pushAppResponse = JSON.parseObject(pushApp.toString(), PushAppResponse.class);
+//            return pushAppResponse.getRet_code() == 0;
+//        } catch (Exception e) {
+//            log.error("Push fail, occur exception:", e);
+//            return false;
+//        }
+//    }
+//
+//    @Data
+//    private static class RequestBuilder {
+//        /**
+//         * 消息标题
+//         */
+//        private String       title;
+//        /**
+//         * 消息内容
+//         */
+//        private String       content;
+//        /**
+//         * 消息推送的平台 1:android 2:ios
+//         */
+//        private Integer      platform;
+//        /**
+//         * 多种推送目标的,比如:全量、标签、单设备、设备列表、单账号、账号列表
+//         * 0 all 1 tag 2 token 3 token_list 4 account 5 account_list
+//         */
+//        private int          audienceType;
+//        /**
+//         * 发送的账号列表/token_list
+//         */
+//        private List<String> toList;
+//
+//        private RequestBuilder(String title, String content, Integer platform, int audienceType){
+//            this.title = title;
+//            this.content = content;
+//            this.platform = platform;
+//            this.audienceType = audienceType;
+//        }
+//        private RequestBuilder(String title, String content, Integer platform, int audienceType, List<String> toList){
+//            this.title = title;
+//            this.content = content;
+//            this.platform = platform;
+//            this.audienceType = audienceType;
+//            this.toList = toList;
+//        }
+//
+//        public static RequestBuilder android(String title, String content, int audienceType, List<String> toList) {
+//            return new RequestBuilder(title, content, Platform.android.getType(), audienceType, toList);
+//        }
+//
+//        public static RequestBuilder android(String title, String content) {
+//            return new RequestBuilder(title, content, Platform.android.getType(), AudienceType.all.getType());
+//        }
+//
+//        public static RequestBuilder ios(String title, String content, int audienceType, List<String> toList) {
+//            return new RequestBuilder(title, content, Platform.ios.getType(), audienceType, toList);
+//        }
+//
+//        public static RequestBuilder ios(String title, String content) {
+//            return new RequestBuilder(title, content, Platform.ios.getType(), AudienceType.all.getType());
+//        }
+//
+//        public boolean isAndroid() {
+//            return this.getPlatform() == Platform.android.getType();
+//        }
+//
+//        public boolean isIos() {
+//            return this.getPlatform() == Platform.ios.getType();
+//        }
+//
+//        public boolean isToken(){
+//            return this.audienceType == AudienceType.token.getType();
+//        }
+//
+//        public boolean isAccount(){
+//            return this.audienceType == AudienceType.account.getType();
+//        }
+//
+//        public boolean isAll(){
+//            return this.audienceType == AudienceType.all.getType();
+//        }
+//
+//        public PushAppRequest createPushAppRequest() {
+//            /**
+//             * https://xg.qq.com/docs/server_api/v3/push_api_v3.html#message%EF%BC%9A%E6%B6%88%E6%81%AF%E4%BD%93
+//             */
+//            //推送请求信息
+//            PushAppRequest pushAppRequest = new PushAppRequest();
+//            /**
+//             * 消息类型
+//             1)notify:通知
+//             2)message:透传消息/静默消息
+//             */
+//            pushAppRequest.setMessage_type(MessageType.notify);
+//            /**
+//             * 指定推送时间
+//             * 1)格式为yyyy-MM-DD HH:MM:SS
+//             * 2)若小于服务器当前时间,则会立即推送
+//             * 3)仅全量推送和标签推送支持此字段
+//             */
+//            pushAppRequest.setSend_time(DateUtil.now());
+//            /**
+//             * 消息离线存储时间(单位为秒),最长72小时
+//             * 1)若expire_time=0,则表示实时消息
+//             * 2)若expire_time大于0且小于800s,则系统会重置为800s
+//             * 3)若expire_time>=800s,按实际设置时间存储,最长72小时
+//             * 4)设置的最大值不得超过2147483647,否则会导致推送失败
+//             */
+//            //pushAppRequest.setExpire_time(24 * 60 * 60);
+//            /**
+//             * 循环任务重复次数
+//             * 1)仅支持全推、标签推
+//             * 2)建议取值[1, 15]
+//             */
+//            //pushAppRequest.setLoop_times(2);
+//            /**
+//             * 循环执行消息下发的间隔
+//             * 1)必须配合loop_times使用
+//             * 2)以天为单位,取值[1, 14]
+//             * 3)loop_times和loop_interval一起表示消息下发任务的循环规则
+//             */
+//            //pushAppRequest.setLoop_interval(2);
+//            /**
+//             * 客户端平台类型
+//             1)android:安卓
+//             2)ios:苹果
+//             */
+//            Message message = new Message();
+//            message.setTitle(this.getTitle());
+//            message.setContent(this.getContent());
+//
+//            if (this.isAndroid()) {
+//                pushAppRequest.setPlatform(Platform.android);
+//                MessageAndroid messageAndroid = new MessageAndroid();
+//                /**
+//                 * 通知消息对象的唯一标识(只对信鸽通道生效)
+//                 * 1)大于0:会覆盖先前相同id的消息
+//                 * 2)等于0:展示本条通知且不影响其他消息
+//                 * 3)等于-1:将清除先前所有消息,仅展示本条消息
+//                 */
+//                messageAndroid.setN_id(0);
+////                ClickAction clickAction = new ClickAction();
+////                clickAction.setActivity("");
+////                messageAndroid.setAction(clickAction);
+//                message.setAndroid(messageAndroid);
+//            } else if (this.isIos()) {
+//                pushAppRequest.setPlatform(Platform.ios);
+//                Alert alert = new Alert();
+//                alert.setTitle(this.getTitle());
+//                alert.setBody(this.getContent());
+//                Aps aps = new Aps();
+//                aps.setAlert(alert);
+//                MessageIOS messageIOS = new MessageIOS();
+//                messageIOS.setAps(aps);
+//                message.setIos(messageIOS);
+//            } else {
+//                log.error("Failed to Create PushAppRequest: Invalid platform type.(1:android, 2:ios)");
+//                return null;
+//            }
+//            pushAppRequest.setMessage(message);
+//            /**
+//             * 推送目标
+//             1)all:全量推送
+//             2)tag:标签推送
+//             3)token:单设备推送
+//             4)token_list:设备列表推送,最多1000 token
+//             5)account:单账号推送
+//             6)account_list:账号列表推送,最多1000 个account
+//             */
+//            if (this.isAll()) {
+//                pushAppRequest.setAudience_type(AudienceType.all);
+//                return pushAppRequest;
+//            } else {
+//                if (null == toList || toList.isEmpty()) {
+//                    log.error("Failed to Create PushAppRequest: 'toList' is null or empty when 'audienceType' is not 'ALL'.");
+//                    return null;
+//                }
+//                if(toList.size() > ValuePool.PUSH_MAX_SIZE){
+//                    log.error("Failed to Create PushAppRequest: the max size of 'toList' is 1000.");
+//                    return null;
+//                }
+//                if (this.isToken()) {
+//                    if (toList.size() == 1) {
+//                        pushAppRequest.setAudience_type(AudienceType.token);
+//                    } else {
+//                        pushAppRequest.setAudience_type(AudienceType.token_list);
+//                    }
+//                    pushAppRequest.setToken_list(new ArrayList<>(toList));
+//                    return pushAppRequest;
+//                } else if (this.isAccount()) {
+//                    if (toList.size() == 1) {
+//                        pushAppRequest.setAudience_type(AudienceType.account);
+//                    } else {
+//                        pushAppRequest.setAudience_type(AudienceType.account_list);
+//                    }
+//                    pushAppRequest.setAccount_list(new ArrayList<>(toList));
+//                    return pushAppRequest;
+//                } else {
+//                    log.error("Failed to Create PushAppRequest: 'audienceType' is not Invalid. (0:all, 2:token, 4:account)");
+//                    return null;
+//                }
+//            }
+//
+//            //打印推送数据
+//            /**
+//             * {
+//             * 	"audience_type": "account",
+//             * 	"platform": "android",
+//             * 	"message_type": "notify",
+//             * 	"message": {
+//             * 		"title": "天域电梯测试",
+//             * 		"content": "测试信鸽消息推送,当前时间: 2019-12-24 17:03:15",
+//             * 		"accept_time": null,
+//             * 		"android": null,
+//             * 		"ios": null
+//             *        },
+//             * 	"expire_time": 259200,
+//             * 	"send_time": null,
+//             * 	"multi_pkg": false,
+//             * 	"loop_times": 0,
+//             * 	"loop_interval": 0,
+//             * 	"environment": "product",
+//             * 	"stat_tag": null,
+//             * 	"seq": 0,
+//             * 	"tag_list": null,
+//             * 	"account_list": ["18571500256"],
+//             * 	"account_type": 0,
+//             * 	"token_list": [],
+//             * 	"push_id": null
+//             * }
+//             */
+//        }
+//    }
+//}

+ 6 - 6
lift-push/src/main/java/cn/com/ty/lift/push/conf/SystemConfiguration.java

@@ -3,7 +3,7 @@ package cn.com.ty.lift.push.conf;
 import cn.com.ty.lift.common.sql.SqlAnalysisInterceptor;
 import cn.com.ty.lift.common.sql.SqlIllegalInterceptor;
 import cn.com.ty.lift.common.utils.ValuePool;
-import cn.com.ty.lift.push.app.XingePush;
+//import cn.com.ty.lift.push.app.XingePush;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
@@ -38,9 +38,9 @@ import java.time.format.DateTimeFormatter;
 @Slf4j
 @Data
 @Configuration
-@ConfigurationProperties(prefix = "xinge")
+//@ConfigurationProperties(prefix = "xinge")
 public class SystemConfiguration {
-    private String appId;
+    /*private String appId;
     private String secretKey;
 
     @PostConstruct
@@ -51,16 +51,16 @@ public class SystemConfiguration {
         log.info("###| secretKey    : {}", secretKey);
         log.info("============================================================");
     }
-    /**
+    *//**
      * 创建tencent xinge 消息推送
-     */
+     *//*
     @Bean
     public XingePush xingePush(){
         if(StrUtil.hasEmpty(appId,secretKey)){
             return new XingePush();
         }
         return new XingePush(appId, secretKey);
-    }
+    }*/
     /**
      * 全局格式化日期
      */

+ 32 - 0
lift-push/src/main/java/cn/com/ty/lift/push/jiguang/JiGuangMessage.java

@@ -0,0 +1,32 @@
+package cn.com.ty.lift.push.jiguang;
+
+import cn.com.ty.lift.common.model.PushMessage;
+import lombok.Data;
+
+import java.util.Map;
+
+@Data
+public class JiGuangMessage {
+    private String titile;
+    private String content;
+    private Map<String, String> extras;
+
+    private JiGuangMessage(String titile, String content) {
+        this.titile = titile;
+        this.content = content;
+    }
+
+    /**
+     * 提供对外创建接口
+     * @param titile
+     * @param content
+     * @return
+     */
+    public static JiGuangMessage create(String titile, String content) {
+        return new JiGuangMessage(titile, content);
+    }
+
+    public static JiGuangMessage create(PushMessage message) {
+        return new JiGuangMessage(message.getTitle(), message.getContent());
+    }
+}

+ 55 - 0
lift-push/src/main/java/cn/com/ty/lift/push/jiguang/JiGuangService.java

@@ -0,0 +1,55 @@
+package cn.com.ty.lift.push.jiguang;
+
+import cn.jpush.api.push.model.PushPayload;
+
+import java.util.Collection;
+
+
+
+public interface JiGuangService {
+    /**
+     * 推送全部
+     * @param msg
+     * @return
+     */
+    boolean pushAll(JiGuangMessage msg);
+
+    /**
+     * 推送所有ios
+     * @param msg
+     * @return
+     */
+    boolean pushIos(JiGuangMessage msg);
+
+    /**
+     * 推送指定的regid推送ios
+     * @param msg
+     * @param registids
+     * @return
+     */
+    boolean pushIos(JiGuangMessage msg, String... registids);
+    boolean pushIos(JiGuangMessage msg, Collection registids);
+
+    /**
+     * 推送所有安卓
+     * @param msg
+     * @return
+     */
+    boolean pushAndroid(JiGuangMessage msg);
+
+    /**
+     * 推送指定的regid推送安卓
+     * @param msg
+     * @param registids
+     * @return
+     */
+    boolean pushAndroid(JiGuangMessage msg, String... registids);
+    boolean pushAndroid(JiGuangMessage msg, Collection registids);
+
+    /**
+     * 推送消息
+     * @param pushPayload
+     * @return
+     */
+    boolean push(PushPayload pushPayload);
+}

+ 190 - 0
lift-push/src/main/java/cn/com/ty/lift/push/jiguang/JiGuangServiceImpl.java

@@ -0,0 +1,190 @@
+package cn.com.ty.lift.push.jiguang;
+
+import cn.jiguang.common.resp.APIConnectionException;
+import cn.jiguang.common.resp.APIRequestException;
+import cn.jpush.api.push.PushResult;
+import cn.jpush.api.push.model.Options;
+import cn.jpush.api.push.model.Platform;
+import cn.jpush.api.push.model.PushPayload;
+import cn.jpush.api.push.model.audience.Audience;
+import cn.jpush.api.push.model.notification.AndroidNotification;
+import cn.jpush.api.push.model.notification.IosNotification;
+import cn.jpush.api.push.model.notification.Notification;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+
+@Slf4j
+@Service
+public class JiGuangServiceImpl implements JiGuangService {
+    @Autowired
+    private JpushConfig jpushConfig;
+
+    @Override
+    public boolean pushAll(JiGuangMessage msg) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.all())//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(IosNotification.newBuilder() //发送ios
+                                        .setCategory(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .setBadge(+1)
+                                        .setSound("happy") //ios提示音
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .build())
+                                .addPlatformNotification(AndroidNotification.newBuilder() //发送android
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .setTitle(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean pushIos(JiGuangMessage msg) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.all())//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(IosNotification.newBuilder() //发送ios
+                                        .setCategory(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .setBadge(+1)
+                                        .setSound("happy") //ios提示音
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean pushIos(JiGuangMessage msg, String... registids) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.registrationId(registids))//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(IosNotification.newBuilder() //发送ios
+                                        .setCategory(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .setBadge(+1)
+                                        .setSound("happy") //ios提示音
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean pushIos(JiGuangMessage msg, Collection registids) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.registrationId(registids))//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(IosNotification.newBuilder() //发送ios
+                                        .setCategory(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .setBadge(+1)
+                                        .setSound("happy") //ios提示音
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean pushAndroid(JiGuangMessage msg) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.all())//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(AndroidNotification.newBuilder() //发送android
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .setTitle(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean pushAndroid(JiGuangMessage msg, String... registids) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.registrationId(registids))//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(AndroidNotification.newBuilder() //发送android
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .setTitle(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean pushAndroid(JiGuangMessage msg, Collection registids) {
+        return push(PushPayload.newBuilder()
+                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setAudience(Audience.registrationId(registids))//registrationId指定用户
+                        .setNotification(Notification.newBuilder()
+                                .addPlatformNotification(AndroidNotification.newBuilder() //发送android
+                                        .addExtras(msg.getExtras()) //附加参数
+                                        .setTitle(msg.getTitile())
+                                        .setAlert(msg.getContent()) //消息体
+                                        .build())
+                                .build()
+                        )
+                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+//                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
+                        .build()
+        );
+    }
+
+    @Override
+    public boolean push(PushPayload pushPayload) {
+        log.info("发送极光推送请求: {}", pushPayload);
+        PushResult result = null;
+        try {
+            result = jpushConfig.getJPushClient().sendPush(pushPayload);
+        } catch (APIConnectionException e) {
+            log.error("极光推送连接异常: ", e);
+        } catch (APIRequestException e) {
+            log.error("极光推送请求异常: ", e);
+        }
+        if (result != null && result.isResultOK()) {
+            log.info("极光推送请求成功: {}", result);
+            return true;
+        } else {
+            log.info("极光推送请求失败: {}", result);
+            return false;
+        }
+    }
+}

+ 38 - 0
lift-push/src/main/java/cn/com/ty/lift/push/jiguang/JpushConfig.java

@@ -0,0 +1,38 @@
+package cn.com.ty.lift.push.jiguang;
+
+import cn.jpush.api.JPushClient;
+import lombok.Data;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+@Data
+@Component("jpushConfig")
+public class JpushConfig {
+
+    /**
+     * 极光推送的用户名
+     */
+    private String appkey = "bd76ee7fb5dac9d04b12a521";
+    /**
+     * 极光推送的密码
+     */
+    private String masterSecret = "18304fdffe957858a2e376ad";
+    /**
+     * 极光推送设置过期时间
+     */
+    private String liveTime = "1000";
+
+
+    private JPushClient jPushClient;
+
+    @PostConstruct
+    public void initJPushClient() {
+        jPushClient = new JPushClient(masterSecret, appkey);
+    }
+
+    // 获取推送客户端
+    public JPushClient getJPushClient() {
+        return jPushClient;
+    }
+}

+ 81 - 26
lift-push/src/main/java/cn/com/ty/lift/push/message/controller/TimeMessageController.java

@@ -4,6 +4,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -42,14 +43,20 @@ public class TimeMessageController {
 	public RestResponse<MessageBO> list(@RequestBody MessageVo messageVo) {
 		IPage<TimeMessage> page = new Page<>(messageVo.getPageNum(), messageVo.getPageSize());
 		IPage<TimeMessage> result = timeMessageService.page(page,
-				Wrappers.<TimeMessage>query().eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
+				Wrappers.<TimeMessage>query()
+						.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
 						.eq(messageVo.getType() != null, "type", messageVo.getType())
-						.notIn("device_model", ApiConstants.DeviceModel.PC).orderByAsc("view_flag")
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)
+						.orderByAsc("view_flag")
 						.orderByDesc("create_time"));
 		MessageBO messageBO = MessageBO.pageCastMessageBo(result);
 		messageBO.setReadCount((long) timeMessageService.count(Wrappers.<TimeMessage>query()
-				.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId()).eq("view_flag", 1)
-				.eq("type", messageVo.getType()).notIn("device_model", ApiConstants.DeviceModel.PC)));
+				.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
+				.eq("view_flag", 1)
+				.eq("type", messageVo.getType())
+				.eq("statuz",1)
+				.notIn("device_model", ApiConstants.DeviceModel.PC)));
 		messageBO.setUnreadCount(messageBO.getTotal() - messageBO.getReadCount());
 		return RestResponse.success(messageBO);
 	}
@@ -62,23 +69,39 @@ public class TimeMessageController {
 		Map<String, Object> result = new HashMap<>();
 		TimeMessageDto systemOne = new TimeMessageDto();
 		int count = timeMessageService
-				.count(Wrappers.<TimeMessage>query().eq(userId != null, "user_id", userId)
-						.eq("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC));
+				.count(Wrappers.<TimeMessage>query()
+						.eq(userId != null, "user_id", userId)
+						.eq("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC));
 		TimeMessage one = timeMessageService.getOne(
-				Wrappers.<TimeMessage>query().eq(userId != null, "user_id", userId)
-						.eq("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC).orderByAsc("view_flag")
-						.orderByDesc("create_time").last("Limit 1"));
+				Wrappers.<TimeMessage>query()
+						.eq(userId != null, "user_id", userId)
+						.eq("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)
+						.orderByAsc("view_flag")
+						.orderByDesc("create_time")
+						.last("Limit 1"));
 		systemOne.setCount(count);
 		systemOne.setTimeMessage(one);
 		result.put("系统消息", systemOne);
 		TimeMessageDto noticeOne = new TimeMessageDto();
 		int noticeOneCount = timeMessageService
-				.count(Wrappers.<TimeMessage>query().eq(userId != null, "user_id", userId)
-						.notIn("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC));
+				.count(Wrappers.<TimeMessage>query()
+						.eq(userId != null, "user_id", userId)
+						.notIn("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC));
 		TimeMessage notice = timeMessageService.getOne(
-				Wrappers.<TimeMessage>query().eq(userId != null, "user_id", userId)
-						.notIn("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC).orderByAsc("view_flag")
-						.orderByDesc("create_time").last("Limit 1"));
+				Wrappers.<TimeMessage>query()
+						.eq(userId != null, "user_id", userId)
+						.notIn("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)
+						.orderByAsc("view_flag")
+						.orderByDesc("create_time")
+						.last("Limit 1"));
 		noticeOne.setCount(noticeOneCount);
 		noticeOne.setTimeMessage(notice);
 		result.put("通知消息", noticeOne);
@@ -96,13 +119,21 @@ public class TimeMessageController {
 	public RestResponse<MessageBO> systemList(@RequestBody MessageVo messageVo) {
 		IPage<TimeMessage> page = new Page<>(messageVo.getPageNum(), messageVo.getPageSize());
 		IPage<TimeMessage> result = timeMessageService.page(page,
-				Wrappers.<TimeMessage>query().eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
-						.eq("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC).orderByAsc("view_flag")
+				Wrappers.<TimeMessage>query()
+						.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
+						.eq("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)
+						.orderByAsc("view_flag")
 						.orderByDesc("create_time"));
 		MessageBO messageBO = MessageBO.pageCastMessageBo(result);
 		messageBO.setReadCount((long) timeMessageService
-				.count(Wrappers.<TimeMessage>query().eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
-						.eq("view_flag", 1).eq("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC)));
+				.count(Wrappers.<TimeMessage>query()
+						.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
+						.eq("view_flag", 1)
+						.eq("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)));
 		messageBO.setUnreadCount(messageBO.getTotal() - messageBO.getReadCount());
 		return RestResponse.success(messageBO);
 	}
@@ -118,13 +149,21 @@ public class TimeMessageController {
 	public RestResponse<MessageBO> noticeList(@RequestBody MessageVo messageVo) {
 		IPage<TimeMessage> page = new Page<>(messageVo.getPageNum(), messageVo.getPageSize());
 		IPage<TimeMessage> result = timeMessageService.page(page,
-				Wrappers.<TimeMessage>query().eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
-						.notIn("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC).orderByAsc("view_flag")
+				Wrappers.<TimeMessage>query()
+						.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
+						.notIn("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)
+						.orderByAsc("view_flag")
 						.orderByDesc("create_time"));
 		MessageBO messageBO = MessageBO.pageCastMessageBo(result);
 		messageBO.setReadCount((long) timeMessageService
-				.count(Wrappers.<TimeMessage>query().eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
-						.eq("view_flag", 1).notIn("type", 0).notIn("device_model", ApiConstants.DeviceModel.PC)));
+				.count(Wrappers.<TimeMessage>query()
+						.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId())
+						.eq("view_flag", 1)
+						.notIn("type", 0)
+						.eq("statuz",1)
+						.notIn("device_model", ApiConstants.DeviceModel.PC)));
 		messageBO.setUnreadCount(messageBO.getTotal() - messageBO.getReadCount());
 		return RestResponse.success(messageBO);
 	}
@@ -136,11 +175,27 @@ public class TimeMessageController {
 	@PostMapping("/deleteMessageList")
 	public RestResponse<MessageBO> deleteMessageList(@RequestBody MessageVo messageVo) {
 		if (messageVo.getType() == 0) {
-			timeMessageService.remove(Wrappers.<TimeMessage>query()
-					.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId()).eq("type", 0));
+			TimeMessage updateEntity = new TimeMessage();
+			updateEntity.setStatuz(0);
+			timeMessageService.update(updateEntity,new QueryWrapper<TimeMessage>()
+					.eq("user_id",messageVo.getUserId())
+//					.eq("type",messageVo.getType())
+					.in(messageVo.getIds()!=null && messageVo.getIds().size()>0,"id",messageVo.getIds())
+					.eq("type",0)
+			);
+//			timeMessageService.remove(Wrappers.<TimeMessage>query()
+//					.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId()).eq("type", 0));
 		} else {
-			timeMessageService.remove(Wrappers.<TimeMessage>query()
-					.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId()).notIn("type", 0));
+//			timeMessageService.remove(Wrappers.<TimeMessage>query()
+//					.eq(messageVo.getUserId() != null, "user_id", messageVo.getUserId()).notIn("type", 0));
+			TimeMessage updateEntity = new TimeMessage();
+			updateEntity.setStatuz(0);
+			timeMessageService.update(updateEntity,new QueryWrapper<TimeMessage>()
+					.eq("user_id",messageVo.getUserId())
+					.eq("type",messageVo.getType())
+					.in(messageVo.getIds()!=null && messageVo.getIds().size()>0,"id",messageVo.getIds())
+//					.ne("type",0)
+			);
 		}
 		return RestResponse.success();
 	}