Browse Source

fix : 客服系统自动回复增加图片

bilingfeng 1 year ago
parent
commit
ee89659a35

+ 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服务启动成功 < (客服系统KfSessionUser表更新为复合主键´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (自动回复增加图片´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 50 - 4
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java

@@ -31,6 +31,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.util.UriComponentsBuilder;
+import reactor.util.function.Tuple2;
 
 import java.io.IOException;
 import java.math.BigDecimal;
@@ -103,6 +104,9 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
     @Autowired
     private RedisUtil<String> redisUtil;
 
+    @Autowired
+    private KfWxApiService wxApiService;
+
     @Autowired
     private IDistributedLockComponent distributedLockComponent;
 
@@ -211,8 +215,14 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
             //玩家符合条件
             if (CollectionUtils.isNotEmpty(orderList) && orderList.stream().map(Order::getAmount)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).intValue() >= kfSystemReply.getRechargeReplyAmount()) {
-                //发送消息
-                this.sysMsgSend(gameId, openId, kfSystemReply.getRechargeReplyContent(), kfRoom);
+                //发送文字消息
+                if (Strings.isNotBlank(kfSystemReply.getRechargeReplyContent())) {
+                    this.sysMsgSend(gameId, openId, kfSystemReply.getRechargeReplyContent(), kfRoom);
+                }
+                //发送图片消息
+                if (Strings.isNotBlank(kfSystemReply.getRechargeReplyPicture())) {
+                    this.sysImgMsgSend(gameId, openId, kfSystemReply.getRechargeReplyPicture(), kfRoom);
+                }
             }
         }
         //判断玩家是否已接入状态, 非带接入状态, 不发送
@@ -238,13 +248,45 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         msgParamMap.put("touser", openId);
         msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue());
         msgParamMap.put("text", textMap);
-        kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //调腾讯接口发送消息
+        Tuple2<Long, String> tuple2 = kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //发送失败
+        if (!Objects.equals(tuple2.getT1(), 0L)) {
+            return;
+        }
         //保存消息
         Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
         kfRoomMsgMap.put("text", msgContent);
         kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT, JsonUtil.toString(kfRoomMsgMap)));
     }
 
+    private void sysImgMsgSend(Long gameId, String openId, String imageUrl, KfRoom kfRoom) {
+        //发送消息
+        Map<String, Object> imageMap = new HashMap<>(1);
+        //图片上传到腾讯, 转成 media_id
+        Tuple2<Long, String> uploadTuple2 = wxApiService.mediaUpload(gameId, FileUtil.urlToMultipartFile(imageUrl));
+        //素材上传失败
+        if (uploadTuple2.getT1() != 0) {
+            return;
+        }
+        imageMap.put("media_id", uploadTuple2.getT2());
+        //构造消息发送参数
+        Map<String, Object> msgParamMap = new HashMap<>(3);
+        msgParamMap.put("touser", openId);
+        msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue());
+        msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue(), imageMap);
+        //调腾讯接口发送消息
+        Tuple2<Long, String> tuple2 = wxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //发送失败
+        if (!Objects.equals(tuple2.getT1(), 0L)) {
+            return;
+        }
+        //保存消息
+        Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
+        kfRoomMsgMap.put("image", imageUrl);
+        kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE, JsonUtil.toString(kfRoomMsgMap)));
+    }
+
     private boolean orderHandle(String orderId, Long gameId, KfAppletMsgDTO kfAppletMsgDTO, KfRoom kfRoom, KfRoomMsg kfRoomMsg) {
         //判断收到的消息是否为充值消息或者小程序消息
         if (!KfAppletMsgDTO.MSG_CONTENT_PAY.contains(kfAppletMsgDTO.getContent())
@@ -475,7 +517,11 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         msgParamMap.put("touser", openId);
         msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue());
         msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue(), linkMap);
-        kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        Tuple2<Long, String> tuple2 = kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //发送失败
+        if (!Objects.equals(tuple2.getT1(), 0L)) {
+            return;
+        }
         //保存发送的支付链接消息
         kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK, JsonUtil.toString(msgParamMap)));
         //删除待支付订单标记

+ 5 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/websocket/KfMsgWebsocketHandler.java

@@ -455,7 +455,11 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
         msgParamMap.put("touser", openId);
         msgParamMap.put("text", textMap);
         msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue());
-        kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        Tuple2<Long, String> tuple2 = kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //发送失败
+        if (!Objects.equals(tuple2.getT1(), 0L)) {
+            return;
+        }
         //保存消息
         Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
         kfRoomMsgMap.put("text", kfSystemReply.getWorkSysReply());

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfSystemReply.java

@@ -56,6 +56,11 @@ public class KfSystemReply {
      */
     private String rechargeReplyContent;
 
+    /**
+     * 充值回复图片
+     */
+    private String rechargeReplyPicture;
+
     /**
      * 开始时间
      */