|
@@ -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;
|
|
|
|
|
|
}
|