Browse Source

fix : SDK兼容客服支付且发送指定客服消息链接

bilingfeng 1 year ago
parent
commit
2688a88cb3

+ 8 - 2
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfMsgContentServiceImpl.java

@@ -94,7 +94,13 @@ public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfM
         map.add("image", formEntity);
         //http请求头
         HttpEntity<LinkedMultiValueMap<String, Object>> httpEntity = new HttpEntity<>(map, httpHeaders);
-        Object result = restTemplate.postForObject(uri, httpEntity, Object.class);
+        Object result;
+        try {
+            result = restTemplate.postForObject(uri, httpEntity, Object.class);
+        } catch (Exception e) {
+            log.error("腾讯上传图片接口调用异常, uri : {}, e : {}", uri, e.getMessage());
+            throw new BaseException("腾讯上传图片接口调用异常!");
+        }
         return JsonUtil.toString(result);
     }
 
@@ -153,7 +159,7 @@ public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfM
             responseEntity = restTemplate.exchange(URIUtil.fillUrlParams(url, pathParam, Boolean.FALSE),
                     HttpMethod.POST, new HttpEntity<>(param, headers), String.class);
         } catch (Exception e) {
-            log.error("腾讯接口调用异常, e : {}", e.getMessage());
+            log.error("腾讯接口调用异常, url : {}, param : {}, e : {}", url, param, e.getMessage());
             throw new BaseException("腾讯接口调用异常!");
         }
         return responseEntity.getBody();

+ 40 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfLink.java

@@ -0,0 +1,40 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-12-06
+ * @description : 客服链接
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_kf_link")
+public class KfLink {
+
+    /**
+     * 应用id
+     */
+    private String appId;
+
+    /**
+     * 第三方客服链接
+     */
+    private String customLink;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/KfLinkMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.KfLink;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-12-06
+ * @description :  ${description}
+ */
+public interface KfLinkMapper extends BaseMapper<KfLink> {
+}

+ 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) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <国家属性老数据更新, 日志整理> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <兼容客服支付, 且发送指定客服消息> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 12 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IKfLinkService.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.sdk.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.KfLink;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-12-06
+ * @description : 客服链接
+ */
+public interface IKfLinkService extends IService<KfLink> {
+}

+ 27 - 11
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletServiceImpl.java

@@ -6,10 +6,7 @@ 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.PayDeviceEnum;
 import com.zanxiang.game.module.base.pojo.enums.PayWayEnum;
-import com.zanxiang.game.module.mybatis.entity.Game;
-import com.zanxiang.game.module.mybatis.entity.GameApplet;
-import com.zanxiang.game.module.mybatis.entity.GameExt;
-import com.zanxiang.game.module.mybatis.entity.Order;
+import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
 import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
 import com.zanxiang.game.module.sdk.pojo.dto.*;
@@ -73,6 +70,9 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     @Autowired
     private MiPayService miPayService;
 
+    @Autowired
+    private IKfLinkService kfLinkService;
+
     @Value("${payConfig.wxPay.customH5Url}")
     private String customH5Url;
 
@@ -113,10 +113,16 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         }
         //消息内容
         AppletMsgDTO appletMsgDTO = JsonUtil.toObj(postData, AppletMsgDTO.class);
-        //用户客服支付会话
-        if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_TEXT)
-                && Objects.equals(appletMsgDTO.getContent(), AppletMsgDTO.MSG_CONTENT_PAY)) {
-            return this.customPayMessage(gameAppletDTO, 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_EVENT)
@@ -178,9 +184,7 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         return Objects.equals(miPayNotifyResult, Boolean.TRUE) ? successResult : failResult;
     }
 
-    private String customPayMessage(GameAppletDTO gameAppletDTO, AppletMsgDTO appletMsgDTO) {
-        //用户信息
-        UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
+    private String customPayMessage(GameAppletDTO gameAppletDTO, UserDTO userDTO) {
         //查询用户最新客服支付订单
         Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
                 .eq(Order::getUserId, userDTO.getId())
@@ -196,6 +200,18 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         return HttpStatusEnum.SUCCESS.getMsg();
     }
 
+    private String customLinkMessage(GameAppletDTO gameAppletDTO, UserDTO userDTO) {
+        //判断是否配置了第三方客服链接
+        KfLink kfLink = kfLinkService.getById(gameAppletDTO.getAppId());
+        if (kfLink == null || Strings.isBlank(kfLink.getCustomLink())) {
+            return HttpStatusEnum.SUCCESS.getMsg();
+        }
+        //其他消息对象
+        Map<String, Object> textMap = new HashMap<>(1);
+        textMap.put("content", kfLink.getCustomLink());
+        return this.sendCustomMessageApi(gameAppletDTO, userDTO.getOpenId(), "text", textMap);
+    }
+
     private String sendCustomMessage(GameAppletDTO gameAppletDTO, String openId, Order order) {
         //查询订单支付方式
         GamePayWayDTO gamePayWayDTO = gamePayWayService.getById(order.getGamePayWayId());

+ 18 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/KfLinkServiceImpl.java

@@ -0,0 +1,18 @@
+package com.zanxiang.game.module.sdk.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.mybatis.entity.KfLink;
+import com.zanxiang.game.module.mybatis.mapper.KfLinkMapper;
+import com.zanxiang.game.module.sdk.service.IKfLinkService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-12-06
+ * @description : 客服链接
+ */
+@Slf4j
+@Service
+public class KfLinkServiceImpl extends ServiceImpl<KfLinkMapper, KfLink> implements IKfLinkService {
+}