Explorar el Código

fix: 补回接口

wuwenyi hace 2 semanas
padre
commit
37ced18c08

+ 9 - 8
src/main/java/com/qqflow/engine/domain/ewechat/controller/EnterpriseWechatCallbackController.java

@@ -46,13 +46,14 @@ public class EnterpriseWechatCallbackController {
         return enterpriseWechatValidator.appVerifyGetReq(req);
     }
 
-//    @Operation(summary = "企微应用回调")
-//    @PostMapping("/{callbackCode}/callback")
-//    public String wechatCallback(EnterpriseWechatCallbackReq req, @PathVariable String callbackCode, @RequestBody String reqBody) {
-//        log.info("企微应用post回调接口收到请求,callbackCode:{}, body::{}", callbackCode, JsonUtil.entity2Json(req));
-//        log.info("企微应用post回调接口收到请求:callbackCode:{}, body::{}", callbackCode, reqBody);
-//        enterpriseWechatCallbackService.appCallback(req, callbackCode, reqBody);
-//        return "success";
-//    }
+    @Operation(summary = "企微应用post回调")
+    @PostMapping("/app-callback")
+    public String wechatAppPostCallback(EnterpriseWechatCallbackReq req, @RequestBody String reqBody) {
+        log.info("企微应用post回调接口收到请求:{}", JsonUtil.entity2Json(req));
+        log.info("企微应用post回调接口收到请求体:{}", reqBody);
+        enterpriseWechatCallbackService.appCallback(req, reqBody);
+        // 返回 success 表示处理成功,否则企微会持续重试
+        return "success";
+    }
 
 }

+ 3 - 0
src/main/java/com/qqflow/engine/domain/ewechat/service/EnterpriseWechatCallbackService.java

@@ -10,4 +10,7 @@ import com.qqflow.engine.domain.ewechat.model.enterprise.callback.EnterpriseWech
 public interface EnterpriseWechatCallbackService {
     /** 企微的回调,大部分都是第三方代开发的回调信息 */
     void callback(EnterpriseWechatCallbackReq req, String reqBody);
+
+    /** 企微自建应用的回调(接收消息/事件推送) */
+    void appCallback(EnterpriseWechatCallbackReq req, String reqBody);
 }

+ 16 - 0
src/main/java/com/qqflow/engine/domain/ewechat/service/impl/EnterpriseWechatCallbackServiceImpl.java

@@ -1,12 +1,15 @@
 package com.qqflow.engine.domain.ewechat.service.impl;
 
 import com.qqflow.engine.common.util.Assert;
+import com.qqflow.engine.common.util.JsonUtil;
+import com.qqflow.engine.common.util.XmlUtil;
 import com.qqflow.engine.domain.ewechat.api.EnterpriseWechatApi;
 import com.qqflow.engine.domain.ewechat.component.EnterpriseWechatValidator;
 import com.qqflow.engine.domain.ewechat.mapper.EnterpriseWechatCorpMapper;
 import com.qqflow.engine.domain.ewechat.enums.EnterpriseWechatInfoType;
 import com.qqflow.engine.domain.ewechat.model.enterprise.EnterpriseWechatEvent;
 import com.qqflow.engine.domain.ewechat.model.enterprise.callback.EnterpriseWechatCallbackReq;
+import com.qqflow.engine.domain.ewechat.model.enterprise.callback.EnterpriseWechatMsgDecryptBody;
 import com.qqflow.engine.domain.ewechat.service.EnterpriseWechatCallbackService;
 import com.qqflow.engine.domain.ewechat.service.EnterpriseWechatService;
 import com.qqflow.engine.domain.ewechat.util.EnterpriseWechatUtil;
@@ -36,4 +39,17 @@ public class EnterpriseWechatCallbackServiceImpl implements EnterpriseWechatCall
         context.publishEvent(new EnterpriseWechatEvent(infoType, result));
     }
 
+    @Override
+    public void appCallback(EnterpriseWechatCallbackReq req, String reqBody) {
+        // 应用回调的 ToUserName 即企业 CorpID,decrypt 会用它作为 receiveid 解密验签
+        String result = validator.decrypt(req, reqBody);
+        if (result == null) {
+            // 解密失败不再抛出,避免企微重试刷错误日志;配置错误可通过该日志排查
+            log.error("企微应用回调解密失败,请求参数:{},请求体:{}", JsonUtil.entity2Json(req), reqBody);
+            return;
+        }
+        EnterpriseWechatMsgDecryptBody msgBody = XmlUtil.fromXml(result, EnterpriseWechatMsgDecryptBody.class);
+        log.info("企微应用回调,消息类型:{},事件类型:{},明文:{}", msgBody.getMsgType(), msgBody.getEvent(), result);
+    }
+
 }