Răsfoiți Sursa

微信客服回调配置

wks 1 an în urmă
părinte
comite
a4791256fd

+ 26 - 10
src/main/java/com/ydtech/modules/admin/controller/WechatController.java

@@ -3,7 +3,6 @@ package com.ydtech.modules.admin.controller;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.admin.model.vo.WechatBindVo;
-import com.ydtech.modules.admin.model.vo.WechatCustomerCallbackVo;
 import com.ydtech.modules.admin.model.vo.WechatLoginVo;
 import com.ydtech.modules.admin.model.vo.WechatVo;
 import com.ydtech.modules.admin.service.WechatService;
@@ -13,11 +12,14 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Map;
 
 @Api(tags = "微信业务")
 @Slf4j
@@ -51,11 +53,25 @@ public class WechatController extends BaseController {
         }
     }
 
-    @PostMapping(path = "/customer/callback", consumes = MediaType.APPLICATION_XML_VALUE)
+    @GetMapping(path = "/customer/callback")
     @ApiOperation(value = "客服回调")
-    HttpResult<String> customerCallback(@RequestBody WechatCustomerCallbackVo wechatCustomerCallbackVo) {
-        log.info(wechatCustomerCallbackVo.toString());
-        return null;
+    public HttpResult<String> customerCallback(HttpServletRequest request) throws IOException {
+        log.info(request.getMethod());
+        log.info(request.getHeader("Accept"));
+        Map<String, String[]> parameterMap = request.getParameterMap();
+
+        log.info();
+        log.info(convertStreamToString(request.getInputStream()));
+        return HttpResult.ok(convertStreamToString(request.getInputStream()));
     }
 
+    public String convertStreamToString(ServletInputStream inputStream) throws IOException {
+        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+        StringBuilder stringBuilder = new StringBuilder();
+        String line;
+        while ((line = reader.readLine()) != null) {
+            stringBuilder.append(line + "\n");
+        }
+        return stringBuilder.toString();
+    }
 }