|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.template.annotation.PassToken;
|
|
import com.template.annotation.PassToken;
|
|
|
import com.template.api.HouseOrderAPI;
|
|
import com.template.api.HouseOrderAPI;
|
|
|
import com.template.common.utils.*;
|
|
import com.template.common.utils.*;
|
|
@@ -43,15 +45,21 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.BufferedWriter;
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.OutputStreamWriter;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.security.Signature;
|
|
import java.security.Signature;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -1643,10 +1651,10 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
|
|
|
|
|
HttpMethod httpMethod = HttpMethod.POST;
|
|
HttpMethod httpMethod = HttpMethod.POST;
|
|
|
String urlSuffix = "/v3/pay/transactions/jsapi";
|
|
String urlSuffix = "/v3/pay/transactions/jsapi";
|
|
|
-// String urlSuffix = "/v3/pay/transactions/h5";
|
|
|
|
|
- String certPath = wxPayV3Config.getCertPath();
|
|
|
|
|
- String platformCertPath = wxPayV3Config.getPlatformCertPath();
|
|
|
|
|
- String seriaNumber = SecurityUtil.getSerialNumber(certPath);
|
|
|
|
|
|
|
+//// String urlSuffix = "/v3/pay/transactions/h5";
|
|
|
|
|
+// String certPath = wxPayV3Config.getCertPath();
|
|
|
|
|
+// String platformCertPath = wxPayV3Config.getPlatformCertPath();
|
|
|
|
|
+// String seriaNumber = SecurityUtil.getSerialNumber(certPath);
|
|
|
// 签名,获取authStr
|
|
// 签名,获取authStr
|
|
|
// String authStr = WechatPayV3Util.buildAuthorization(httpMethod,
|
|
// String authStr = WechatPayV3Util.buildAuthorization(httpMethod,
|
|
|
// urlSuffix,
|
|
// urlSuffix,
|
|
@@ -1987,6 +1995,7 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
System.out.println("接收到支付结果通知:" + data.toJSONString());
|
|
System.out.println("接收到支付结果通知:" + data.toJSONString());
|
|
|
//解密resource中的通知数据
|
|
//解密resource中的通知数据
|
|
|
String resource = data.get("resource").toString();
|
|
String resource = data.get("resource").toString();
|
|
|
|
|
+
|
|
|
resourceMap = WechatPayApiV3Util.decryptFromResource(resource, "e10adc3949ba59abbe56e057f20f883e", 1);
|
|
resourceMap = WechatPayApiV3Util.decryptFromResource(resource, "e10adc3949ba59abbe56e057f20f883e", 1);
|
|
|
System.out.println("解析resource结果:" + resourceMap);
|
|
System.out.println("解析resource结果:" + resourceMap);
|
|
|
return resourceMap;
|
|
return resourceMap;
|
|
@@ -2262,24 +2271,31 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
public void returnRefund(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
public void returnRefund(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
String inputLine = "";
|
|
String inputLine = "";
|
|
|
String notityXml = "";
|
|
String notityXml = "";
|
|
|
|
|
+ String timestamp = request.getHeader("Wechatpay-Timestamp");
|
|
|
|
|
+ String nonce = request.getHeader("Wechatpay-Nonce");
|
|
|
|
|
+ String serialNo = request.getHeader("Wechatpay-Serial");
|
|
|
|
|
+ String signature = request.getHeader("Wechatpay-Signature");
|
|
|
try {
|
|
try {
|
|
|
while ((inputLine = request.getReader().readLine()) != null) {
|
|
while ((inputLine = request.getReader().readLine()) != null) {
|
|
|
notityXml += inputLine;
|
|
notityXml += inputLine;
|
|
|
}
|
|
}
|
|
|
//关闭流
|
|
//关闭流
|
|
|
request.getReader().close();
|
|
request.getReader().close();
|
|
|
- System.out.println("微信回调内容信息:" + notityXml);
|
|
|
|
|
//解析成json
|
|
//解析成json
|
|
|
JSONObject data = JSONObject.parseObject(notityXml);
|
|
JSONObject data = JSONObject.parseObject(notityXml);
|
|
|
//判断 支付是否成功
|
|
//判断 支付是否成功
|
|
|
|
|
+ log.info("退款回调入参"+timestamp+"==="+nonce+"===="+serialNo+"======"+signature+"======="+notityXml);
|
|
|
if ("REFUND.SUCCESS".equals(data.get("event_type"))) {
|
|
if ("REFUND.SUCCESS".equals(data.get("event_type"))) {
|
|
|
|
|
|
|
|
|
|
+ String plainText = WechatPayV3Util.verifyNotify(serialNo, notityXml, signature, nonce, timestamp,
|
|
|
|
|
+ wxPayV3Config.getApiKey3(), wxPayV3Config.getPlatformCertPath());
|
|
|
|
|
+ log.info("退款回调明文"+plainText);
|
|
|
// 在这里处理接收到的支付结果通知数据
|
|
// 在这里处理接收到的支付结果通知数据
|
|
|
- Map<String, Object> resourceMap = handlePaymentNotification(data);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ JSONObject resourceMap = JSONObject.parseObject(plainText);
|
|
|
// 获取 trade_state 值
|
|
// 获取 trade_state 值
|
|
|
- String tradeState = resourceMap.get("trade_state").toString();
|
|
|
|
|
|
|
+ String tradeState = resourceMap.get("refund_status").toString();
|
|
|
if (tradeState.equals("SUCCESS")) {
|
|
if (tradeState.equals("SUCCESS")) {
|
|
|
|
|
+
|
|
|
// 获取 amount 字段
|
|
// 获取 amount 字段
|
|
|
Map<String, Object> amountMap = (Map<String, Object>) resourceMap.get("amount");
|
|
Map<String, Object> amountMap = (Map<String, Object>) resourceMap.get("amount");
|
|
|
//获得 返回的商户订单号
|
|
//获得 返回的商户订单号
|
|
@@ -2297,7 +2313,7 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
String total_fee = amountMap.get("payer_refund").toString();
|
|
String total_fee = amountMap.get("payer_refund").toString();
|
|
|
//业务逻辑------------
|
|
//业务逻辑------------
|
|
|
LambdaQueryWrapper<HouseOrder> wrapperHo = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<HouseOrder> wrapperHo = new LambdaQueryWrapper<>();
|
|
|
- wrapperHo.eq(HouseOrder::getHouseOrderNumber, outTradeNo);
|
|
|
|
|
|
|
+ wrapperHo.eq(HouseOrder::getOrderNumber, outTradeNo);
|
|
|
HouseOrder rr = houseOrderService.getOne(wrapperHo);
|
|
HouseOrder rr = houseOrderService.getOne(wrapperHo);
|
|
|
if (ObjectUtils.isNotEmpty(rr)) {
|
|
if (ObjectUtils.isNotEmpty(rr)) {
|
|
|
LambdaQueryWrapper<RefundRecord> wrapperRr = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<RefundRecord> wrapperRr = new LambdaQueryWrapper<>();
|
|
@@ -2373,10 +2389,15 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
+// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
+// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+// jsonObject.put("code", "FAIL");
|
|
|
|
|
+// jsonObject.put("message", "失败");
|
|
|
|
|
+// response.getWriter().write(jsonObject.toJSONString());
|
|
|
|
|
+ response.setStatus(HttpServletResponse.SC_OK);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("code", "FAIL");
|
|
|
|
|
- jsonObject.put("message", "失败");
|
|
|
|
|
|
|
+ jsonObject.put("code", "SUCCESS");
|
|
|
|
|
+ jsonObject.put("message", "SUCCESS");
|
|
|
response.getWriter().write(jsonObject.toJSONString());
|
|
response.getWriter().write(jsonObject.toJSONString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2450,6 +2471,5 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|