浏览代码

fix :bug修改, 兼容小程序消息

bilingfeng 1 年之前
父节点
当前提交
f9a1600853

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <Websocket客服系统优化处理04> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <Websocket客服系统优化处理05> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 0 - 5
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/constant/RedisKeyConstant.java

@@ -42,9 +42,4 @@ public class RedisKeyConstant {
      */
     public static final String GAME_CUSTOM_PAY_SIGN = "game_sdk_manage_custom_pay_sign_";
 
-    /**
-     * 客服支付订单重新获取缓存
-     */
-    public static final String GAME_CUSTOM_PAY = "game_sdk_manage_custom_pay_";
-
 }

+ 5 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/enums/KfRoomMsgTypeEnum.java

@@ -14,6 +14,11 @@ import java.util.Objects;
 @AllArgsConstructor
 public enum KfRoomMsgTypeEnum {
 
+    /**
+     * 小程序消息
+     */
+    KF_MSG_TYPE_MINI_APP("miniprogrampage"),
+
     /**
      * 文本消息
      */

+ 29 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/KfAppletMsgDTO.java

@@ -2,6 +2,9 @@ package com.zanxiang.game.module.manage.pojo.dto;
 
 import lombok.Data;
 
+import java.util.Arrays;
+import java.util.List;
+
 /**
  * @author : lingfeng
  * @time : 2023-01-05
@@ -23,7 +26,7 @@ public class KfAppletMsgDTO {
     /**
      * 客服支付约定消息文本
      */
-    public static final String MSG_CONTENT_PAY = "2";
+    public static final List<String> MSG_CONTENT_PAY = Arrays.asList("2", "CZ", "充值");
 
     /**
      * 开发者微信号
@@ -69,4 +72,29 @@ public class KfAppletMsgDTO {
      * 图片地址
      */
     private String PicUrl;
+
+    /**
+     * 标题
+     */
+    private String Title;
+
+    /**
+     * 小程序id
+     */
+    private String AppId;
+
+    /**
+     * 小程序路径
+     */
+    private String PagePath;
+
+    /**
+     * 小程序图片
+     */
+    private String ThumbUrl;
+
+    /**
+     * 小程序图片媒体id
+     */
+    private String ThumbMediaId;
 }

+ 34 - 18
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/KfWebSocketMsgDTO.java

@@ -1,6 +1,7 @@
 package com.zanxiang.game.module.manage.pojo.dto;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import com.zanxiang.erp.security.util.SecurityUtil;
 import com.zanxiang.game.module.manage.enums.KfRoomMsgTypeEnum;
 import com.zanxiang.game.module.manage.enums.KfWebSocketMsgEnum;
@@ -24,8 +25,6 @@ import java.util.List;
 @NoArgsConstructor
 public class KfWebSocketMsgDTO {
 
-    private static final long serialVersionUID = 1L;
-
     /**
      * webSocket消息类型
      */
@@ -315,8 +314,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class GameBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 游戏id
          */
@@ -339,8 +336,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class WaitUserBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 玩家openId
          */
@@ -416,8 +411,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class RoomBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 房间id
          */
@@ -485,8 +478,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class RoomMsgBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 消息id
          */
@@ -544,8 +535,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class MsgContentBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 文本内容
          */
@@ -560,15 +549,45 @@ public class KfWebSocketMsgDTO {
          * 图文消息
          */
         private LinkBean link;
+
+        /**
+         * 小程序消息
+         */
+        private MiniAppBean miniprogrampage;
     }
 
     @Data
     @Builder
     @AllArgsConstructor
     @NoArgsConstructor
-    public static class LinkBean {
+    public static class MiniAppBean {
+
+        /**
+         * 标题
+         */
+        private String title;
+
+        /**
+         * 小程序id
+         */
+        private String appId;
 
-        private static final long serialVersionUID = 1L;
+        /**
+         * 路径
+         */
+        private String pagePath;
+
+        /**
+         * 图片地址
+         */
+        private String thumbUrl;
+    }
+
+    @Data
+    @Builder
+    @AllArgsConstructor
+    @NoArgsConstructor
+    public static class LinkBean {
 
         /**
          * 标题
@@ -588,6 +607,7 @@ public class KfWebSocketMsgDTO {
         /**
          * 图片地址
          */
+        @JsonProperty("thumb_url")
         private String thumbUrl;
     }
 
@@ -597,8 +617,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class PageBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 当前页数
          */
@@ -626,8 +644,6 @@ public class KfWebSocketMsgDTO {
     @NoArgsConstructor
     public static class ResultBean {
 
-        private static final long serialVersionUID = 1L;
-
         /**
          * 0 : 成功, 其他失败
          */

+ 30 - 26
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java

@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.zanxiang.erp.security.util.SecurityUtil;
 import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
 import com.zanxiang.game.module.manage.constant.RedisKeyConstant;
-import com.zanxiang.game.module.manage.enums.ExpireTimeEnum;
 import com.zanxiang.game.module.manage.enums.KfRoomMsgOwnerEnum;
 import com.zanxiang.game.module.manage.enums.KfRoomMsgTypeEnum;
 import com.zanxiang.game.module.manage.enums.KfWebSocketMsgEnum;
@@ -119,19 +118,21 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         KfWebSocketMsgDTO.MsgContentBean msgContent = this.getMsgContent(kfAppletMsgDTO);
         KfRoomMsg kfRoomMsg = this.transform(kfAppletMsgDTO, gameApplet, kfRoom, postData, msgContent);
         //判断是否请求支付链接
-        String orderId = redisUtil.getCache(RedisKeyConstant.GAME_CUSTOM_PAY + kfAppletMsgDTO.getFromUserName());
-        if (Strings.isNotBlank(orderId) && Objects.equals(kfAppletMsgDTO.getContent(), KfAppletMsgDTO.MSG_CONTENT_PAY)) {
-            Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
-                    .eq(Order::getOrderId, orderId)
-                    .and(qw -> qw.eq(Order::getStatus, OrderStatusEnum.READY_PAY.getValue())
-                            .or().eq(Order::getStatus, OrderStatusEnum.WAIT_PAY.getValue())
-                    )
-            );
-            if (order != null) {
-                this.sendCustomPayMessage(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom, order);
-                kfRoomMsg.setReadStatus(Boolean.TRUE);
-                kfRoomMsgService.save(kfRoomMsg);
-                return;
+        String orderId = redisUtil.getCache(RedisKeyConstant.GAME_CUSTOM_PAY_SIGN + kfAppletMsgDTO.getFromUserName());
+        //存在客服支付订单
+        if (Strings.isNotBlank(orderId)) {
+            //收到的是充值消息或者小程序消息, 回复充值链接
+            if (KfAppletMsgDTO.MSG_CONTENT_PAY.contains(kfAppletMsgDTO.getContent())
+                    || Objects.equals(kfAppletMsgDTO.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_MINI_APP.getValue())) {
+                Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderId, orderId));
+                //存在待支付的客服支付订单, 判断订单状态
+                if (Objects.equals(order.getStatus(), OrderStatusEnum.READY_PAY.getValue())
+                        || Objects.equals(order.getStatus(), OrderStatusEnum.WAIT_PAY.getValue())) {
+                    this.sendCustomPayMessage(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom, order);
+                    kfRoomMsg.setReadStatus(Boolean.TRUE);
+                    kfRoomMsgService.save(kfRoomMsg);
+                    return;
+                }
             }
         }
         //保存房间消息
@@ -171,19 +172,13 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
             return;
         }
         //查询订单
-        Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
-                .eq(Order::getOrderId, orderId)
-                .and(qw -> qw.eq(Order::getStatus, OrderStatusEnum.READY_PAY.getValue())
-                        .or().eq(Order::getStatus, OrderStatusEnum.WAIT_PAY.getValue())
-                )
-        );
-        if (order == null) {
-            return;
+        Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderId, orderId));
+        //存在待支付的客服支付订单, 判断订单状态
+        if (Objects.equals(order.getStatus(), OrderStatusEnum.READY_PAY.getValue())
+                || Objects.equals(order.getStatus(), OrderStatusEnum.WAIT_PAY.getValue())) {
+            //发送订单支付消息
+            this.sendCustomPayMessage(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), null, order);
         }
-        this.sendCustomPayMessage(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), null, order);
-        redisUtil.deleteCache(customPaySign);
-        redisUtil.setCache(RedisKeyConstant.GAME_CUSTOM_PAY + kfAppletMsgDTO.getFromUserName(),
-                orderId, ExpireTimeEnum.FIVE_MIN.getTime());
     }
 
     private KfWebSocketMsgDTO transform(KfRoom kfRoom, Long gameId, KfRoomMsg kfRoomMsg, KfWebSocketMsgDTO.MsgContentBean msgContent) {
@@ -283,6 +278,15 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         if (Objects.equals(KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue(), kfAppletMsgDTO.getMsgType())) {
             msgContentBean.setImage(this.mediaConvertOss(kfAppletMsgDTO.getPicUrl()));
         }
+        if (Objects.equals(KfRoomMsgTypeEnum.KF_MSG_TYPE_MINI_APP.getValue(), kfAppletMsgDTO.getMsgType())) {
+            msgContentBean.setMiniprogrampage(KfWebSocketMsgDTO.MiniAppBean
+                    .builder()
+                    .title(kfAppletMsgDTO.getTitle())
+                    .appId(kfAppletMsgDTO.getAppId())
+                    .pagePath(kfAppletMsgDTO.getPagePath())
+                    .thumbUrl(kfAppletMsgDTO.getThumbUrl())
+                    .build());
+        }
         return msgContentBean;
     }
 

+ 12 - 3
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfRoomMsgServiceImpl.java

@@ -77,9 +77,15 @@ public class KfRoomMsgServiceImpl extends ServiceImpl<KfRoomMsgMapper, KfRoomMsg
         KfWebSocketMsgDTO.RoomMsgBean roomMsgBean = BeanUtil.copy(kfRoomMsg, KfWebSocketMsgDTO.RoomMsgBean.class);
         roomMsgBean.setMsgType(KfRoomMsgTypeEnum.getMsgTypeEnum(kfRoomMsg.getMsgType()));
         roomMsgBean.setContent(JsonUtil.toObj(kfRoomMsg.getContent(), KfWebSocketMsgDTO.MsgContentBean.class));
+        //判断是否是系统消息
+        if (Objects.equals(roomMsgBean.getMsgOwner(), KfRoomMsgOwnerEnum.KF_MSG_OWNER_SYSTEM.getValue())) {
+            roomMsgBean.setKfUserName("系统消息");
+        }
         //客服消息, 设置客服名字
-        String kfUserName = kfUserNameMap.get(roomMsgBean.getKfUserId());
-        roomMsgBean.setKfUserName(kfUserName == null ? "查询erp客服名字异常" : kfUserName);
+        if (Objects.equals(roomMsgBean.getMsgOwner(), KfRoomMsgOwnerEnum.KF_MSG_OWNER_KF.getValue())) {
+            String kfUserName = kfUserNameMap.get(roomMsgBean.getKfUserId());
+            roomMsgBean.setKfUserName(kfUserName == null ? "查询erp客服名字异常" : kfUserName);
+        }
         return roomMsgBean;
     }
 
@@ -103,7 +109,10 @@ public class KfRoomMsgServiceImpl extends ServiceImpl<KfRoomMsgMapper, KfRoomMsg
     }
 
     private Map<Long, String> getKfUserNameMap(List<KfRoomMsg> roomMsgList) {
-        List<Long> kfUserIdList = roomMsgList.stream().map(KfRoomMsg::getKfUserId).collect(Collectors.toList());
+        List<Long> kfUserIdList = roomMsgList.stream()
+                .filter(msg -> Objects.equals(msg.getMsgOwner(), KfRoomMsgOwnerEnum.KF_MSG_OWNER_KF.getValue()))
+                .map(KfRoomMsg::getKfUserId)
+                .distinct().collect(Collectors.toList());
         Map<Long, String> kfUserNameMap;
         try {
             kfUserNameMap = sysUserRpc.getUserNameByIds(kfUserIdList).getData();

+ 3 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfSessionUserServiceImpl.java

@@ -85,6 +85,9 @@ public class KfSessionUserServiceImpl extends ServiceImpl<KfSessionUserMapper, K
         if (Objects.equals(waitUserMsgBean.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue())) {
             waitUserMsgBean.setContent("[充值]");
         }
+        if (Objects.equals(waitUserMsgBean.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_MINI_APP.getValue())) {
+            waitUserMsgBean.setContent("[小程序]");
+        }
         return waitUserMsgBean;
     }
 }

+ 2 - 1
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfQuickReply.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.*;
 
+import java.io.Serializable;
 import java.time.LocalDateTime;
 
 /**
@@ -18,7 +19,7 @@ import java.time.LocalDateTime;
 @ToString
 @Builder
 @TableName("t_kf_quick_reply")
-public class KfQuickReply {
+public class KfQuickReply implements Serializable {
 
     private static final long serialVersionUID = 1L;
 

+ 2 - 1
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfRoom.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.*;
 
+import java.io.Serializable;
 import java.time.LocalDateTime;
 
 /**
@@ -18,7 +19,7 @@ import java.time.LocalDateTime;
 @ToString
 @Builder
 @TableName("t_kf_room")
-public class KfRoom {
+public class KfRoom implements Serializable {
 
     private static final long serialVersionUID = 1L;
 

+ 2 - 1
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfRoomMsg.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.*;
 
+import java.io.Serializable;
 import java.time.LocalDateTime;
 
 /**
@@ -18,7 +19,7 @@ import java.time.LocalDateTime;
 @ToString
 @Builder
 @TableName("t_kf_room_msg")
-public class KfRoomMsg {
+public class KfRoomMsg implements Serializable {
 
     private static final long serialVersionUID = 1L;
 

+ 2 - 1
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfSessionUser.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.*;
 
+import java.io.Serializable;
 import java.time.LocalDateTime;
 
 /**
@@ -18,7 +19,7 @@ import java.time.LocalDateTime;
 @ToString
 @Builder
 @TableName("t_kf_session_user")
-public class KfSessionUser {
+public class KfSessionUser implements Serializable {
 
     private static final long serialVersionUID = 1L;