|
|
@@ -215,6 +215,43 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
return new Object[]{requestParam, parser, no};
|
|
|
}
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
+ Object[] handleWxNotify2(HttpServletRequest request,String body) {
|
|
|
+ var no = RandomUtil.randomInt(1000, 9999);
|
|
|
+ var signature = request.getHeader("Wechatpay-Signature");
|
|
|
+ var serial = request.getHeader("Wechatpay-Serial");
|
|
|
+ var nonce = request.getHeader("Wechatpay-Nonce");
|
|
|
+ var timestamp = request.getHeader("Wechatpay-Timestamp");
|
|
|
+ var signatureType = request.getHeader("Wechatpay-Signature-Type");
|
|
|
+
|
|
|
+ LOGGER.info("微信支付回调{}:\n Request参数:\n signature:{},serial:{},nonce:{},timestamp:{},signatureType:{}", no, signature, serial, nonce, timestamp, signatureType);
|
|
|
+
|
|
|
+ ServletInputStream inputStream = request.getInputStream();
|
|
|
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ for (int lenght; (lenght = inputStream.read(buffer)) != -1; ) {
|
|
|
+ result.write(buffer, 0, lenght);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ LOGGER.info("微信支付回调{}:\nBody数据:\n{}", no, result);
|
|
|
+
|
|
|
+ // 构造 RequestParam
|
|
|
+ RequestParam requestParam = new RequestParam.Builder()
|
|
|
+ .serialNumber(serial)
|
|
|
+ .nonce(nonce) // 随机数
|
|
|
+ .signature(signature)
|
|
|
+ .timestamp(timestamp)
|
|
|
+ .body(body)
|
|
|
+ .build();
|
|
|
+ LOGGER.info("微信支付回调{}:构造 RequestParam完毕", no);
|
|
|
+
|
|
|
+ // 如果已经初始化了 RSAAutoCertificateConfig,可直接使用
|
|
|
+ // 初始化 NotificationParser
|
|
|
+ NotificationParser parser = new NotificationParser((NotificationConfig) config);
|
|
|
+ return new Object[]{requestParam, parser, no};
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* JSAPI支付下单
|
|
|
*/
|
|
|
@@ -661,11 +698,11 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* 处理发票抬头填写完成通知
|
|
|
* event_type为FAPIAO.USER_APPLIED
|
|
|
*
|
|
|
- * @param request
|
|
|
+ * @param notifyRes
|
|
|
+ * @param body
|
|
|
*/
|
|
|
@Override
|
|
|
- public void titleWriteNotice(HttpServletRequest request) {
|
|
|
- var notifyRes = handleWxNotify(request);
|
|
|
+ public void titleWriteNotice(Object[] notifyRes) {
|
|
|
try {
|
|
|
// TitleWriteNotification titleWriteNotification = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], TitleWriteNotification.class);
|
|
|
Map<String,Object> titleWriteNotification = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], Map.class);
|
|
|
@@ -819,8 +856,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public void wxInvoiceNotify(HttpServletRequest request) {
|
|
|
- var notifyRes = handleWxNotify(request);
|
|
|
+ public void wxInvoiceNotify(Object[] notifyRes) {
|
|
|
try {
|
|
|
InvoiceNotification invoiceNotification = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], InvoiceNotification.class);
|
|
|
LOGGER.info("微信开具发票结果通知回调{}:验签解密完毕,数据:\n{}", notifyRes[2], invoiceNotification);
|
|
|
@@ -842,19 +878,20 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* 接收电子发票相关回调通知
|
|
|
*
|
|
|
* @param request
|
|
|
+ * @param body
|
|
|
*/
|
|
|
@Override
|
|
|
- public void invoiceNotify(HttpServletRequest request) {
|
|
|
- var notifyRes = handleWxNotify(request);
|
|
|
+ public void invoiceNotify(HttpServletRequest request, String body) {
|
|
|
+ var notifyRes = handleWxNotify2(request,body);
|
|
|
var requestParam = (RequestParam) notifyRes[0];
|
|
|
Notification notification = JSONObject.parseObject(requestParam.getBody(), Notification.class);
|
|
|
switch (notification.getEventType()) {
|
|
|
// 发票抬头填写完成
|
|
|
case "FAPIAO.USER_APPLIED":
|
|
|
- titleWriteNotice(request);
|
|
|
+ titleWriteNotice(notifyRes);
|
|
|
// 发票开具结果
|
|
|
case "FAPIAO.ISSUED":
|
|
|
- wxInvoiceNotify(request);
|
|
|
+ wxInvoiceNotify(notifyRes);
|
|
|
default:
|
|
|
throw new IllegalStateException("Unexpected value: " + notification.getEventType());
|
|
|
}
|