Browse Source

fix : Websocket调试修改2

bilingfeng 1 year ago
parent
commit
8443f9863f

+ 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) {
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <Websocket调试修改1> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <Websocket调试修改2> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 15 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/KfWebSocketMsgDTO.java

@@ -248,6 +248,11 @@ public class KfWebSocketMsgDTO {
          * 小程序名称
          * 小程序名称
          */
          */
         private String appName;
         private String appName;
+
+        /**
+         * 未读消息总数
+         */
+        private Long unReadMsgCount;
     }
     }
 
 
     @Data
     @Data
@@ -288,6 +293,11 @@ public class KfWebSocketMsgDTO {
          */
          */
         private LocalDateTime lastMsgTime;
         private LocalDateTime lastMsgTime;
 
 
+        /**
+         * 未读消息总数
+         */
+        private Long unReadMsgCount;
+
         /**
         /**
          * 开始等待时间
          * 开始等待时间
          */
          */
@@ -346,6 +356,11 @@ public class KfWebSocketMsgDTO {
          * 最后一条消息时间
          * 最后一条消息时间
          */
          */
         private LocalDateTime lastMsgTime;
         private LocalDateTime lastMsgTime;
+
+        /**
+         * 未读消息总数
+         */
+        private Long unReadMsgCount;
     }
     }
 
 
     @Data
     @Data

+ 0 - 5
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/KfWebSocketMsgParam.java

@@ -17,11 +17,6 @@ public class KfWebSocketMsgParam {
      */
      */
     private KfWebSocketMsgEnum webSocketMsgType;
     private KfWebSocketMsgEnum webSocketMsgType;
 
 
-    /**
-     * 客服id
-     */
-    private Long kfUserId;
-
     /**
     /**
      * 客服登录token, 必传参数
      * 客服登录token, 必传参数
      */
      */

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/api/KfWxApiService.java

@@ -41,7 +41,7 @@ public class KfWxApiService {
     /**
     /**
      * 通过腾讯API给玩家发送消息
      * 通过腾讯API给玩家发送消息
      */
      */
-    private String sendCustomMessageApi(GameAppletDTO gameAppletDTO, String openId, String msgType, Map<String, Object> msgParamMap) {
+    public String sendCustomMessageApi(GameAppletDTO gameAppletDTO, Map<String, Object> msgParamMap) {
         //客服消息参数构造
         //客服消息参数构造
         log.error("客服消息发送参数, paramMap : {}", JsonUtil.toString(msgParamMap));
         log.error("客服消息发送参数, paramMap : {}", JsonUtil.toString(msgParamMap));
         //获取接口token
         //获取接口token

+ 14 - 6
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/websocket/KfMsgWebsocketHandler.java

@@ -14,6 +14,7 @@ import com.zanxiang.game.module.manage.service.IGameAppletService;
 import com.zanxiang.game.module.manage.service.IKfRoomMsgService;
 import com.zanxiang.game.module.manage.service.IKfRoomMsgService;
 import com.zanxiang.game.module.manage.service.IKfRoomService;
 import com.zanxiang.game.module.manage.service.IKfRoomService;
 import com.zanxiang.game.module.manage.service.IKfSessionUserService;
 import com.zanxiang.game.module.manage.service.IKfSessionUserService;
+import com.zanxiang.game.module.manage.service.api.KfWxApiService;
 import com.zanxiang.game.module.mybatis.entity.KfRoom;
 import com.zanxiang.game.module.mybatis.entity.KfRoom;
 import com.zanxiang.game.module.mybatis.entity.KfRoomMsg;
 import com.zanxiang.game.module.mybatis.entity.KfRoomMsg;
 import com.zanxiang.game.module.mybatis.entity.KfSessionUser;
 import com.zanxiang.game.module.mybatis.entity.KfSessionUser;
@@ -63,6 +64,9 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
     @Autowired
     @Autowired
     private IDistributedLockComponent distributedLockComponent;
     private IDistributedLockComponent distributedLockComponent;
 
 
+    @Autowired
+    private KfWxApiService wxApiService;
+
     /**
     /**
      * websocket连接建立成功
      * websocket连接建立成功
      */
      */
@@ -180,14 +184,18 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
         }
         }
         //图片
         //图片
         if (Objects.equals(msgContent.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE)) {
         if (Objects.equals(msgContent.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE)) {
+//            Map<String, Object> imageMap = new HashMap<>(1);
+//            imageMap.put("media_id", msgContent.getText());
+//            msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue());
+//            msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue(), imageMap);
 
 
-            Map<String, Object> imageMap = new HashMap<>(1);
-            imageMap.put("media_id", msgContent.getText());
-            msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue());
-            msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue(), imageMap);
+            this.sendMessage(session, KfWebSocketMsgDTO.fail(param.getWebSocketMsgType(),
+                    "发图片的逻辑还没写完, 先发文本, param : " + JsonUtil.toString(param)));
+            return;
         }
         }
-
-
+        wxApiService.sendCustomMessageApi(gameAppletDTO, msgParamMap);
+        //发送失败, 通知返回
+        //发送成功, 消息入库
     }
     }
 
 
     private void kfFinishSession(WebSocketSession session, KfWebSocketMsgEnum webSocketMsgType, Long gameId, Long roomId) {
     private void kfFinishSession(WebSocketSession session, KfWebSocketMsgEnum webSocketMsgType, Long gameId, Long roomId) {

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <增加日志调试客服会话> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <消息转发到后台处理> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +
                 "\\ `--.| | | | |/ / \n" +

+ 21 - 14
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletServiceImpl.java

@@ -2,10 +2,13 @@ package com.zanxiang.game.module.sdk.service.impl;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.base.ServerInfo;
 import com.zanxiang.game.module.base.pojo.dto.H5GameConfigDTO;
 import com.zanxiang.game.module.base.pojo.dto.H5GameConfigDTO;
 import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
 import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
 import com.zanxiang.game.module.base.pojo.enums.PayDeviceEnum;
 import com.zanxiang.game.module.base.pojo.enums.PayDeviceEnum;
 import com.zanxiang.game.module.base.pojo.enums.PayWayEnum;
 import com.zanxiang.game.module.base.pojo.enums.PayWayEnum;
+import com.zanxiang.game.module.base.rpc.IAgentRpc;
+import com.zanxiang.game.module.base.rpc.IKfMsgRpc;
 import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
 import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
 import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
 import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
@@ -20,6 +23,7 @@ import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
 import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.logging.log4j.util.Strings;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
@@ -43,9 +47,6 @@ import java.util.Objects;
 @Service
 @Service
 public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApplet> implements IGameAppletService {
 public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApplet> implements IGameAppletService {
 
 
-    @Autowired
-    private IUserService userService;
-
     @Autowired
     @Autowired
     private IOrderService orderService;
     private IOrderService orderService;
 
 
@@ -73,6 +74,9 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     @Autowired
     @Autowired
     private IKfLinkService kfLinkService;
     private IKfLinkService kfLinkService;
 
 
+    @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
+    private IKfMsgRpc kfMsgRpc;
+
     @Value("${payConfig.wxPay.customH5Url}")
     @Value("${payConfig.wxPay.customH5Url}")
     private String customH5Url;
     private String customH5Url;
 
 
@@ -115,22 +119,25 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
 
 
         log.error("收到腾讯监听服务器内容, appletMsgDTO : {}", JsonUtil.toString(appletMsgDTO));
         log.error("收到腾讯监听服务器内容, appletMsgDTO : {}", JsonUtil.toString(appletMsgDTO));
 
 
-        //文本消息
-        if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_TEXT)) {
-            //用户信息
-            UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
-            //用户客服支付会话
-            if (Objects.equals(appletMsgDTO.getContent(), AppletMsgDTO.MSG_CONTENT_PAY)) {
-                return this.customPayMessage(gameAppletDTO, userDTO);
-            }
-            //非客服会话, 返回指定的客服链接
-            return this.customLinkMessage(gameAppletDTO, userDTO);
-        }
+//        //文本消息
+//        if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_TEXT)) {
+//            //用户信息
+//            UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
+//            //用户客服支付会话
+//            if (Objects.equals(appletMsgDTO.getContent(), AppletMsgDTO.MSG_CONTENT_PAY)) {
+//                return this.customPayMessage(gameAppletDTO, userDTO);
+//            }
+//            //非客服会话, 返回指定的客服链接
+//            return this.customLinkMessage(gameAppletDTO, userDTO);
+//        }
         //米大师支付回调事件
         //米大师支付回调事件
         if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_EVENT)
         if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_EVENT)
                 && Objects.equals(appletMsgDTO.getEvent(), AppletMsgDTO.EVENT_MI_PAY_CALL_BACK)) {
                 && Objects.equals(appletMsgDTO.getEvent(), AppletMsgDTO.EVENT_MI_PAY_CALL_BACK)) {
             return this.miPayMessage(appletMsgDTO, gameAppletDTO);
             return this.miPayMessage(appletMsgDTO, gameAppletDTO);
         }
         }
+
+        kfMsgRpc.appletMsg(postData);
+
         //其他消息不处理, 直接返回成功
         //其他消息不处理, 直接返回成功
         return result;
         return result;
     }
     }