Althars123 3 年之前
父節點
當前提交
ffdd98c261

+ 37 - 23
zzjs-admin/src/main/java/com/miaxis/app/controller/film/NotifyController.java

@@ -73,14 +73,14 @@ public class NotifyController {
      */
     @PostMapping(value = "/wxpay")
     @ApiOperation("微信支付回调")
-    public WxNotifyReturnDTO wxpayNotify(@RequestBody FilmWxpayDTO filmWxpayDTO, HttpServletRequest request, BufferedReader br) throws GeneralSecurityException, IOException {
+    public WxNotifyReturnDTO wxpayNotify(@RequestBody FilmWxpayDTO filmWxpayDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
 
-        String bodyString = getBodyString(br);
+        String bodyString = getBodyString(request);
         System.out.println(bodyString);
         Boolean pass =  validate(request,bodyString);
-        if (!pass){
-            throw new CustomException("签名失败");
-        }
+//        if (!pass){
+//            throw new CustomException("签名失败");
+//        }
         String resourceString = getSourString(filmWxpayDTO);
         log.info(resourceString);
         JSONObject jsonObject = JSONObject.parseObject(resourceString);
@@ -93,31 +93,45 @@ public class NotifyController {
         return wxNotifyReturnDTO;
     }
 
-    private String getBodyString(BufferedReader br) {
-        String inputLine;
-
-        String str = "";
-
-        try {
-            while ((inputLine = br.readLine()) != null) {
-                str += inputLine;
-
+    private String getBodyString(HttpServletRequest request) {
+            BufferedReader br = null;
+            StringBuilder sb = new StringBuilder("");
+            try
+            {
+                br = request.getReader();
+                String str;
+                while ((str = br.readLine()) != null)
+                {
+                    sb.append(str);
+                }
+                br.close();
             }
+            catch (IOException e)
+            {
+                e.printStackTrace();
+            }
+            finally
+            {
+                if (null != br)
+                {
+                    try
+                    {
+                        br.close();
+                    }
+                    catch (IOException e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            }
+            return sb.toString();
 
-            br.close();
-
-        } catch (IOException e) {
-            System.out.println("IOException: " + e);
-
-        }
-        return str;
     }
 
     private Boolean validate(HttpServletRequest request, String bodyString) throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
         String sign = request.getHeader("Wechatpay-Signature");
         String timestamp = request.getHeader("Wechatpay-Timestamp");
         String nonce = request.getHeader("Wechatpay-Nonce");
-        log.info("");
 
         StringBuffer sb = new StringBuffer();
         sb.append(timestamp + "\n");
@@ -130,7 +144,7 @@ public class NotifyController {
         Signature signature = Signature.getInstance("SHA256withRSA");
         signature.initSign(privateKey);
         Boolean result = signature.verify(Base64Utils.decodeFromString(sign));
-        log.info(result.toString());
+        log.info("微信支付回调验签:"+result.toString());
         return result;
 
     }

+ 4 - 2
zzjs-admin/src/test/java/com/miaxis/test/NormalTest.java

@@ -20,8 +20,10 @@ public class NormalTest {
     private IRefundRecordService refundRecordService;
     @Test
     public void test1() throws Exception {
-        FilmOrder filmOrder = filmOrderService.getByOutTradeNo("12021051815555556348172644409486");
-        refundRecordService.refund(filmOrder,"12021051815333778448136985596487");
+        FilmOrder filmOrder = filmOrderService.getByOutTradeNo("12021052416003523348114349059153");
+        refundRecordService.refund(filmOrder,"12021051815333778448136985596488");
+        FilmOrder filmOrder1 = filmOrderService.getByOutTradeNo("12021052415260767148145493655617");
+        refundRecordService.refund(filmOrder1,"12021051815333778448136985596489");
     }