Browse Source

微信回调验签测试

skyline 2 years ago
parent
commit
424ceffdcd

+ 2 - 2
miniapp/src/main/java/com/kym/miniapp/controller/InvoiceController.java

@@ -81,8 +81,8 @@ public class InvoiceController {
      * @return
      */
     @PostMapping("/notify")
-    R<?> invoiceNotify(HttpServletRequest request,@RequestBody String body) {
-        wxPayService.invoiceNotify(request,body);
+    R<?> invoiceNotify(HttpServletRequest request) {
+        wxPayService.invoiceNotify(request);
         return R.success();
     }
 

+ 1 - 1
service/src/main/java/com/kym/service/wechat/WxPayService.java

@@ -52,5 +52,5 @@ public interface WxPayService {
 
     void wxInvoiceNotify(Object[] notifyRes);
 
-    void invoiceNotify(HttpServletRequest request, String body);
+    void invoiceNotify(HttpServletRequest request);
 }

+ 5 - 6
service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -216,7 +216,7 @@ public class WxPayServiceImpl implements WxPayService {
     }
 
     @SneakyThrows
-    Object[] handleWxNotify2(HttpServletRequest request, String body) {
+    Object[] handleWxNotify2(HttpServletRequest request) {
         var no = RandomUtil.randomInt(1000, 9999);
         var signature = request.getHeader("Wechatpay-Signature");
         var serial = request.getHeader("Wechatpay-Serial");
@@ -232,8 +232,8 @@ public class WxPayServiceImpl implements WxPayService {
         for (int lenght; (lenght = inputStream.read(buffer)) != -1; ) {
             result.write(buffer, 0, lenght);
         }
-        LOGGER.info("【body1】:{}",new String(result.toByteArray()));
-        LOGGER.info("【body2】:{}",body);
+        var body = result.toString();
+        LOGGER.info("【body1】:{}",body);
 
 
         LOGGER.info("微信支付回调{}:\nBody数据:\n{}", no, result);
@@ -871,11 +871,10 @@ public class WxPayServiceImpl implements WxPayService {
      * 接收电子发票相关回调通知
      *
      * @param request
-     * @param body
      */
     @Override
-    public void invoiceNotify(HttpServletRequest request, String body) {
-        var notifyRes = handleWxNotify2(request, body);
+    public void invoiceNotify(HttpServletRequest request) {
+        var notifyRes = handleWxNotify2(request);
         var requestParam = (RequestParam) notifyRes[0];
         Notification notification = JSONObject.parseObject(requestParam.getBody(), Notification.class);
         switch (notification.getEventType()) {