|
|
@@ -430,6 +430,238 @@ public class WxPayScoreStrategy implements PayScoreStrategy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public PayScoreResult modifyServiceOrder(PayScoreModifyRequest request) {
|
|
|
+ log.info("[微信支付分] 修改订单金额 - 订单号: {}, 新金额: {}元", request.getOutOrderNo(), request.getTotalAmount());
|
|
|
+
|
|
|
+ PayScoreResult checkResult = checkServiceAvailable();
|
|
|
+ if (checkResult != null) {
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ ObjectNode body = objectMapper.createObjectNode();
|
|
|
+ body.put("appid", wxPayConfig.getAppId());
|
|
|
+ body.put("service_id", wxPayConfig.getServiceId());
|
|
|
+
|
|
|
+ if (request.getPostPayments() != null && !request.getPostPayments().isEmpty()) {
|
|
|
+ ArrayNode postPayments = objectMapper.createArrayNode();
|
|
|
+ for (PayScoreModifyRequest.PostPayment payment : request.getPostPayments()) {
|
|
|
+ ObjectNode paymentObj = objectMapper.createObjectNode();
|
|
|
+ paymentObj.put("name", payment.getName());
|
|
|
+ paymentObj.put("amount", yuanToFen(payment.getAmount()));
|
|
|
+ if (payment.getDescription() != null) {
|
|
|
+ paymentObj.put("description", payment.getDescription());
|
|
|
+ }
|
|
|
+ if (payment.getCount() != null) {
|
|
|
+ paymentObj.put("count", payment.getCount());
|
|
|
+ }
|
|
|
+ postPayments.add(paymentObj);
|
|
|
+ }
|
|
|
+ body.set("post_payments", postPayments);
|
|
|
+ }
|
|
|
+
|
|
|
+ body.put("total_amount", yuanToFen(request.getTotalAmount()));
|
|
|
+ body.put("reason", request.getReason() != null ? request.getReason() : "金额调整");
|
|
|
+
|
|
|
+ String requestBody = objectMapper.writeValueAsString(body);
|
|
|
+ String url = PAY_SCORE_BASE_URL + "/" + request.getOutOrderNo() + "/modify";
|
|
|
+ log.info("[微信支付分] 修改金额请求: url={}, body={}", url, requestBody);
|
|
|
+
|
|
|
+ HttpRequest httpRequest = new HttpRequest.Builder()
|
|
|
+ .httpMethod(HttpMethod.POST)
|
|
|
+ .url(url)
|
|
|
+ .body(new JsonRequestBody.Builder().body(requestBody).build())
|
|
|
+ .addHeader("Content-Type", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .addHeader("Accept", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = wxPayHttpClient.execute(httpRequest, String.class);
|
|
|
+ String responseBody = response.getServiceResponse();
|
|
|
+ log.info("[微信支付分] 修改金额响应: body={}", responseBody);
|
|
|
+
|
|
|
+ JsonNode respJson = objectMapper.readTree(responseBody);
|
|
|
+ String outOrderNo = getJsonString(respJson, "out_order_no");
|
|
|
+ String state = getJsonString(respJson, "state");
|
|
|
+
|
|
|
+ return PayScoreResult.success(outOrderNo, state);
|
|
|
+
|
|
|
+ } catch (HttpException e) {
|
|
|
+ log.error("[微信支付分] 修改金额HTTP异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("NETWORK_ERROR", "网络请求异常: " + e.getMessage());
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("[微信支付分] 修改金额业务异常: code={}, msg={}", e.getErrorCode(), e.getErrorMessage(), e);
|
|
|
+ return PayScoreResult.fail(e.getErrorCode(), e.getErrorMessage());
|
|
|
+ } catch (MalformedMessageException e) {
|
|
|
+ log.error("[微信支付分] 修改金额消息解析异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("MESSAGE_ERROR", "消息解析异常: " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[微信支付分] 修改金额未知异常", e);
|
|
|
+ return PayScoreResult.fail("UNKNOWN_ERROR", "修改金额失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PayScoreResult syncServiceOrder(PayScoreSyncRequest request) {
|
|
|
+ log.info("[微信支付分] 同步订单信息 - 订单号: {}, 类型: {}", request.getOutOrderNo(), request.getType());
|
|
|
+
|
|
|
+ PayScoreResult checkResult = checkServiceAvailable();
|
|
|
+ if (checkResult != null) {
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ ObjectNode body = objectMapper.createObjectNode();
|
|
|
+ body.put("appid", wxPayConfig.getAppId());
|
|
|
+ body.put("service_id", wxPayConfig.getServiceId());
|
|
|
+ body.put("type", request.getType() != null ? request.getType() : "ORDER_PAID");
|
|
|
+ if (request.getDetail() != null) {
|
|
|
+ body.put("detail", request.getDetail());
|
|
|
+ }
|
|
|
+
|
|
|
+ String requestBody = objectMapper.writeValueAsString(body);
|
|
|
+ String url = PAY_SCORE_BASE_URL + "/" + request.getOutOrderNo() + "/sync";
|
|
|
+ log.info("[微信支付分] 同步订单请求: url={}, body={}", url, requestBody);
|
|
|
+
|
|
|
+ HttpRequest httpRequest = new HttpRequest.Builder()
|
|
|
+ .httpMethod(HttpMethod.POST)
|
|
|
+ .url(url)
|
|
|
+ .body(new JsonRequestBody.Builder().body(requestBody).build())
|
|
|
+ .addHeader("Content-Type", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .addHeader("Accept", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = wxPayHttpClient.execute(httpRequest, String.class);
|
|
|
+ String responseBody = response.getServiceResponse();
|
|
|
+ log.info("[微信支付分] 同步订单响应: body={}", responseBody);
|
|
|
+
|
|
|
+ JsonNode respJson = objectMapper.readTree(responseBody);
|
|
|
+ String outOrderNo = getJsonString(respJson, "out_order_no");
|
|
|
+ String state = getJsonString(respJson, "state");
|
|
|
+
|
|
|
+ return PayScoreResult.success(outOrderNo, state);
|
|
|
+
|
|
|
+ } catch (HttpException e) {
|
|
|
+ log.error("[微信支付分] 同步订单HTTP异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("NETWORK_ERROR", "网络请求异常: " + e.getMessage());
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("[微信支付分] 同步订单业务异常: code={}, msg={}", e.getErrorCode(), e.getErrorMessage(), e);
|
|
|
+ return PayScoreResult.fail(e.getErrorCode(), e.getErrorMessage());
|
|
|
+ } catch (MalformedMessageException e) {
|
|
|
+ log.error("[微信支付分] 同步订单消息解析异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("MESSAGE_ERROR", "消息解析异常: " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[微信支付分] 同步订单未知异常", e);
|
|
|
+ return PayScoreResult.fail("UNKNOWN_ERROR", "同步订单失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PayScoreResult refundServiceOrder(PayScoreRefundRequest request) {
|
|
|
+ log.info("[微信支付分] 申请退款 - 订单号: {}, 金额: {}元", request.getOutOrderNo(), request.getRefundAmount());
|
|
|
+
|
|
|
+ PayScoreResult checkResult = checkServiceAvailable();
|
|
|
+ if (checkResult != null) {
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ ObjectNode body = objectMapper.createObjectNode();
|
|
|
+ body.put("appid", wxPayConfig.getAppId());
|
|
|
+ body.put("service_id", wxPayConfig.getServiceId());
|
|
|
+ body.put("reason", request.getReason() != null ? request.getReason() : "用户申请退款");
|
|
|
+ body.put("amount", yuanToFen(request.getRefundAmount()));
|
|
|
+
|
|
|
+ String requestBody = objectMapper.writeValueAsString(body);
|
|
|
+ String url = PAY_SCORE_BASE_URL + "/" + request.getOutOrderNo() + "/pay/refund";
|
|
|
+ log.info("[微信支付分] 退款请求: url={}, body={}", url, requestBody);
|
|
|
+
|
|
|
+ HttpRequest httpRequest = new HttpRequest.Builder()
|
|
|
+ .httpMethod(HttpMethod.POST)
|
|
|
+ .url(url)
|
|
|
+ .body(new JsonRequestBody.Builder().body(requestBody).build())
|
|
|
+ .addHeader("Content-Type", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .addHeader("Accept", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = wxPayHttpClient.execute(httpRequest, String.class);
|
|
|
+ String responseBody = response.getServiceResponse();
|
|
|
+ log.info("[微信支付分] 退款响应: body={}", responseBody);
|
|
|
+
|
|
|
+ JsonNode respJson = objectMapper.readTree(responseBody);
|
|
|
+ String outOrderNo = getJsonString(respJson, "out_order_no");
|
|
|
+ String refundId = getJsonString(respJson, "refund_id");
|
|
|
+
|
|
|
+ PayScoreResult result = PayScoreResult.success(outOrderNo, null);
|
|
|
+ result.setPackageStr(refundId);
|
|
|
+ return result;
|
|
|
+
|
|
|
+ } catch (HttpException e) {
|
|
|
+ log.error("[微信支付分] 退款HTTP异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("NETWORK_ERROR", "网络请求异常: " + e.getMessage());
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("[微信支付分] 退款业务异常: code={}, msg={}", e.getErrorCode(), e.getErrorMessage(), e);
|
|
|
+ return PayScoreResult.fail(e.getErrorCode(), e.getErrorMessage());
|
|
|
+ } catch (MalformedMessageException e) {
|
|
|
+ log.error("[微信支付分] 退款消息解析异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("MESSAGE_ERROR", "消息解析异常: " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[微信支付分] 退款未知异常", e);
|
|
|
+ return PayScoreResult.fail("UNKNOWN_ERROR", "退款失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PayScoreResult queryRefund(String outOrderNo, String outRefundNo) {
|
|
|
+ log.info("[微信支付分] 查询退款 - 订单号: {}, 退款单号: {}", outOrderNo, outRefundNo);
|
|
|
+
|
|
|
+ PayScoreResult checkResult = checkServiceAvailable();
|
|
|
+ if (checkResult != null) {
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String url = PAY_SCORE_BASE_URL + "/" + outOrderNo + "/pay/refund/" + outRefundNo
|
|
|
+ + "?service_id=" + wxPayConfig.getServiceId()
|
|
|
+ + "&appid=" + wxPayConfig.getAppId();
|
|
|
+ log.info("[微信支付分] 查询退款请求: url={}", url);
|
|
|
+
|
|
|
+ HttpRequest httpRequest = new HttpRequest.Builder()
|
|
|
+ .httpMethod(HttpMethod.GET)
|
|
|
+ .url(url)
|
|
|
+ .addHeader("Accept", MediaType.APPLICATION_JSON.getValue())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = wxPayHttpClient.execute(httpRequest, String.class);
|
|
|
+ String responseBody = response.getServiceResponse();
|
|
|
+ log.info("[微信支付分] 查询退款响应: body={}", responseBody);
|
|
|
+
|
|
|
+ JsonNode respJson = objectMapper.readTree(responseBody);
|
|
|
+ String status = getJsonString(respJson, "status");
|
|
|
+
|
|
|
+ PayScoreResult result = PayScoreResult.success(outOrderNo, status);
|
|
|
+
|
|
|
+ if (respJson.has("amount") && !respJson.get("amount").isNull()) {
|
|
|
+ result.setTotalAmount(fenToYuan(respJson.get("amount").asInt()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+ } catch (HttpException e) {
|
|
|
+ log.error("[微信支付分] 查询退款HTTP异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("NETWORK_ERROR", "网络请求异常: " + e.getMessage());
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("[微信支付分] 查询退款业务异常: code={}, msg={}", e.getErrorCode(), e.getErrorMessage(), e);
|
|
|
+ return PayScoreResult.fail(e.getErrorCode(), e.getErrorMessage());
|
|
|
+ } catch (MalformedMessageException e) {
|
|
|
+ log.error("[微信支付分] 查询退款消息解析异常: {}", e.getMessage(), e);
|
|
|
+ return PayScoreResult.fail("MESSAGE_ERROR", "消息解析异常: " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[微信支付分] 查询退款未知异常", e);
|
|
|
+ return PayScoreResult.fail("UNKNOWN_ERROR", "查询退款失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PayScoreCallbackResult parseCallback(Map<String, Object> params) {
|
|
|
log.info("[微信支付分] 解析回调通知 - 参数Keys: {}", params.keySet());
|