Переглянути джерело

修复ios横屏消息接收不到问题

udream-cxs 4 роки тому
батько
коміт
ec5d325f9a

+ 14 - 1
lift-push/pom.xml

@@ -26,11 +26,24 @@
             <version>1.0-SNAPSHOT</version>
         </dependency>
         <!--从私有仓库加载依赖-->
-        <dependency>
+        <!--信鸽插件换成极光插件-->
+        <!--<dependency>
             <groupId>com.tencent</groupId>
             <artifactId>xinge-push</artifactId>
             <version>1.2.0</version>
+        </dependency>-->
+        <dependency>
+            <groupId>cn.jpush.api</groupId>
+            <artifactId>jpush-client</artifactId>
+            <version>3.4.3</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.jpush.api</groupId>
+            <artifactId>jiguang-common</artifactId>
+            <version>1.1.7</version>
         </dependency>
+
+
         <dependency>
             <groupId>cn.com.xwy</groupId>
             <artifactId>xwy-spring-boot</artifactId>

+ 23 - 19
lift-push/src/main/java/cn/com/ty/lift/push/jiguang/JiGuangServiceImpl.java

@@ -8,6 +8,7 @@ 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.IosAlert;
 import cn.jpush.api.push.model.notification.IosNotification;
 import cn.jpush.api.push.model.notification.Notification;
 import lombok.extern.slf4j.Slf4j;
@@ -21,7 +22,13 @@ import java.util.Collection;
 public class JiGuangServiceImpl implements JiGuangService {
     @Autowired
     private JpushConfig jpushConfig;
+    private IosAlert buildTitleAndBody(String title,String content){
+        return IosAlert.newBuilder().setTitleAndBody(title, null , content).build();
+    }
 
+    private IosAlert buildTitleAndBody(JiGuangMessage msg){
+        return buildTitleAndBody(msg.getTitile(), msg.getContent());
+    }
     @Override
     public boolean pushAll(JiGuangMessage msg) {
         return push(PushPayload.newBuilder()
@@ -29,9 +36,8 @@ public class JiGuangServiceImpl implements JiGuangService {
                         .setAudience(Audience.all())//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(IosNotification.newBuilder() //发送ios
-                                        .setCategory(msg.getTitile())
-                                        .setAlert(msg.getContent()) //消息体
-                                        .setBadge(+1)
+                                        .setAlert(buildTitleAndBody(msg)) //消息体
+                                        .setBadge(1)
                                         .setSound("happy") //ios提示音
                                         .addExtras(msg.getExtras()) //附加参数
                                         .build())
@@ -42,28 +48,28 @@ public class JiGuangServiceImpl implements JiGuangService {
                                         .build())
                                 .build()
                         )
-                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+                        .setOptions(Options.newBuilder().setApnsProduction(jpushConfig.getApnsProduction()).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())  //所有平台的用户
+                        .setPlatform(Platform.ios())  //所有平台的用户
                         .setAudience(Audience.all())//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(IosNotification.newBuilder() //发送ios
-                                        .setCategory(msg.getTitile())
-                                        .setAlert(msg.getContent()) //消息体
+                                        .setAlert(buildTitleAndBody(msg)) //消息体
                                         .setBadge(+1)
                                         .setSound("happy") //ios提示音
                                         .addExtras(msg.getExtras()) //附加参数
                                         .build())
                                 .build()
                         )
-                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+                        .setOptions(Options.newBuilder().setApnsProduction(jpushConfig.getApnsProduction()).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
 //                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
                         .build()
         );
@@ -72,19 +78,18 @@ public class JiGuangServiceImpl implements JiGuangService {
     @Override
     public boolean pushIos(JiGuangMessage msg, String... registids) {
         return push(PushPayload.newBuilder()
-                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setPlatform(Platform.ios())  //所有平台的用户
                         .setAudience(Audience.registrationId(registids))//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(IosNotification.newBuilder() //发送ios
-                                        .setCategory(msg.getTitile())
-                                        .setAlert(msg.getContent()) //消息体
+                                        .setAlert(buildTitleAndBody(msg)) //消息体
                                         .setBadge(+1)
                                         .setSound("happy") //ios提示音
                                         .addExtras(msg.getExtras()) //附加参数
                                         .build())
                                 .build()
                         )
-                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+                        .setOptions(Options.newBuilder().setApnsProduction(jpushConfig.getApnsProduction()).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
 //                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
                         .build()
         );
@@ -93,19 +98,18 @@ public class JiGuangServiceImpl implements JiGuangService {
     @Override
     public boolean pushIos(JiGuangMessage msg, Collection registids) {
         return push(PushPayload.newBuilder()
-                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setPlatform(Platform.ios())  //所有平台的用户
                         .setAudience(Audience.registrationId(registids))//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(IosNotification.newBuilder() //发送ios
-                                        .setCategory(msg.getTitile())
-                                        .setAlert(msg.getContent()) //消息体
+                                        .setAlert(buildTitleAndBody(msg)) //消息体
                                         .setBadge(+1)
                                         .setSound("happy") //ios提示音
                                         .addExtras(msg.getExtras()) //附加参数
                                         .build())
                                 .build()
                         )
-                        .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
+                        .setOptions(Options.newBuilder().setApnsProduction(jpushConfig.getApnsProduction()).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
 //                .setMessage(Message.newBuilder().setMsgContent(msg.getContent()).addExtras(msg.getExtras()).build())//自定义信息
                         .build()
         );
@@ -114,7 +118,7 @@ public class JiGuangServiceImpl implements JiGuangService {
     @Override
     public boolean pushAndroid(JiGuangMessage msg) {
         return push(PushPayload.newBuilder()
-                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setPlatform(Platform.android())  //所有平台的用户
                         .setAudience(Audience.all())//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(AndroidNotification.newBuilder() //发送android
@@ -133,7 +137,7 @@ public class JiGuangServiceImpl implements JiGuangService {
     @Override
     public boolean pushAndroid(JiGuangMessage msg, String... registids) {
         return push(PushPayload.newBuilder()
-                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setPlatform(Platform.android())  //所有平台的用户
                         .setAudience(Audience.registrationId(registids))//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(AndroidNotification.newBuilder() //发送android
@@ -152,7 +156,7 @@ public class JiGuangServiceImpl implements JiGuangService {
     @Override
     public boolean pushAndroid(JiGuangMessage msg, Collection registids) {
         return push(PushPayload.newBuilder()
-                        .setPlatform(Platform.all())  //所有平台的用户
+                        .setPlatform(Platform.android())  //所有平台的用户
                         .setAudience(Audience.registrationId(registids))//registrationId指定用户
                         .setNotification(Notification.newBuilder()
                                 .addPlatformNotification(AndroidNotification.newBuilder() //发送android

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

@@ -23,6 +23,11 @@ public class JpushConfig {
      */
     private String liveTime = "1000";
 
+    /**
+     * 线上环境推送,还是测试环境推送
+     */
+    private Boolean apnsProduction = false;
+
 
     private JPushClient jPushClient;