|
@@ -2,19 +2,18 @@ package com.llisoft.pay.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.util.Enumeration;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.util.StreamUtils;
|
|
import org.springframework.util.StreamUtils;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
-import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import com.llisoft.pay.service.ApiService;
|
|
import com.llisoft.pay.service.ApiService;
|
|
@@ -36,8 +35,8 @@ public class CallbackWxPayController {
|
|
|
|
|
|
@ApiOperation(value="异步通知 栋科")
|
|
@ApiOperation(value="异步通知 栋科")
|
|
@PostMapping(value="/dongke/{pid}")
|
|
@PostMapping(value="/dongke/{pid}")
|
|
- public ResponseEntity.BodyBuilder dongke(@PathVariable String pid, @RequestHeader HttpHeaders headers, HttpServletRequest request) throws Exception {
|
|
|
|
- if(apiService.wxNotifyDongke(pid, this.notify(headers, request))) {
|
|
|
|
|
|
+ public ResponseEntity.BodyBuilder dongke(@PathVariable String pid, HttpServletRequest request) throws Exception {
|
|
|
|
+ if(apiService.wxNotifyDongke(pid, this.notify(request))) {
|
|
return ResponseEntity.ok();
|
|
return ResponseEntity.ok();
|
|
}
|
|
}
|
|
return ResponseEntity.badRequest();
|
|
return ResponseEntity.badRequest();
|
|
@@ -45,19 +44,33 @@ public class CallbackWxPayController {
|
|
|
|
|
|
@ApiOperation(value="异步通知 青谷")
|
|
@ApiOperation(value="异步通知 青谷")
|
|
@PostMapping(value="/qinggu/{pid}")
|
|
@PostMapping(value="/qinggu/{pid}")
|
|
- public ResponseEntity.BodyBuilder qinggu(@PathVariable String pid, @RequestHeader HttpHeaders headers, HttpServletRequest request) throws Exception {
|
|
|
|
- if(apiService.wxNotifyQinggu(pid, this.notify(headers, request))) {
|
|
|
|
|
|
+ public ResponseEntity.BodyBuilder qinggu(@PathVariable String pid, HttpServletRequest request) throws Exception {
|
|
|
|
+ if(apiService.wxNotifyQinggu(pid, this.notify(request))) {
|
|
return ResponseEntity.ok();
|
|
return ResponseEntity.ok();
|
|
}
|
|
}
|
|
return ResponseEntity.badRequest();
|
|
return ResponseEntity.badRequest();
|
|
}
|
|
}
|
|
|
|
|
|
// https://github.com/wechatpay-apiv3/wechatpay-java/README.md
|
|
// https://github.com/wechatpay-apiv3/wechatpay-java/README.md
|
|
- private RequestParam notify(@RequestHeader HttpHeaders headers, HttpServletRequest request) throws IOException {
|
|
|
|
- String signature = headers.getFirst("Wechatpay-Signature"); // - HTTP 头 `Wechatpay-Signature`。应答的微信支付签名。
|
|
|
|
- String serial = headers.getFirst("Wechatpay-Serial"); // - HTTP 头 `Wechatpay-Serial`。微信支付平台证书的序列号,验签必须使用序列号对应的微信支付平台证书。
|
|
|
|
- String nonce = headers.getFirst("Wechatpay-Nonce"); // - HTTP 头 `Wechatpay-Nonce`。签名中的随机数。
|
|
|
|
- String timestamp = headers.getFirst("Wechatpay-Timestamp"); // - HTTP 头 `Wechatpay-Timestamp`。签名中的时间戳。
|
|
|
|
|
|
+ private RequestParam notify(HttpServletRequest request) throws IOException {
|
|
|
|
+
|
|
|
|
+ System.out.println();
|
|
|
|
+ System.out.println("*************************************************");
|
|
|
|
+ System.out.println();
|
|
|
|
+ Enumeration<String> headerNames = request.getHeaderNames();//获得 n个键名,放回一个Enumeration<String>类型的数据
|
|
|
|
+ while(headerNames.hasMoreElements()){//.hasMoreElements()返回的是布尔类型的数据
|
|
|
|
+ String headerName = headerNames.nextElement();//获得键
|
|
|
|
+ String headerValue = request.getHeader(headerName);//获得值
|
|
|
|
+ System.out.println(headerName+":"+headerValue);
|
|
|
|
+ }
|
|
|
|
+ System.out.println();
|
|
|
|
+ System.out.println("*************************************************");
|
|
|
|
+ System.out.println();
|
|
|
|
+
|
|
|
|
+ String signature = request.getHeader("Wechatpay-Signature"); // - HTTP 头 `Wechatpay-Signature`。应答的微信支付签名。
|
|
|
|
+ String serial = request.getHeader("Wechatpay-Serial"); // - HTTP 头 `Wechatpay-Serial`。微信支付平台证书的序列号,验签必须使用序列号对应的微信支付平台证书。
|
|
|
|
+ String nonce = request.getHeader("Wechatpay-Nonce"); // - HTTP 头 `Wechatpay-Nonce`。签名中的随机数。
|
|
|
|
+ String timestamp = request.getHeader("Wechatpay-Timestamp"); // - HTTP 头 `Wechatpay-Timestamp`。签名中的时间戳。
|
|
// String signatureType = headers.getFirst("Wechatpay-Signature-Type"); // - HTTP 头 `Wechatpay-Signature-Type`。签名类型。
|
|
// String signatureType = headers.getFirst("Wechatpay-Signature-Type"); // - HTTP 头 `Wechatpay-Signature-Type`。签名类型。
|
|
// **切记使用原始报文**,不要用 JSON 对象序列化后的字符串,避免验签的 body 和原文不一致。
|
|
// **切记使用原始报文**,不要用 JSON 对象序列化后的字符串,避免验签的 body 和原文不一致。
|
|
String body = StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8);
|
|
String body = StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8);
|