Commit dd5fc334327eeb180bdf09038fa12c74b520ce5b
1 parent
1e1c5f65
fix redirectUrl issue
Showing
11 changed files
with
78 additions
and
65 deletions
cashier-boss/src/main/java/com/diligrp/cashier/boss/controller/CashierDeskController.java
| @@ -35,7 +35,6 @@ public class CashierDeskController { | @@ -35,7 +35,6 @@ public class CashierDeskController { | ||
| 35 | AssertUtils.notNull(request.getAmount(), "amount missed"); | 35 | AssertUtils.notNull(request.getAmount(), "amount missed"); |
| 36 | AssertUtils.isTrue(request.getAmount() > 0, "Invalid amount"); | 36 | AssertUtils.isTrue(request.getAmount() > 0, "Invalid amount"); |
| 37 | AssertUtils.notEmpty(request.getOutTradeNo(), "outTradeNo missed"); | 37 | AssertUtils.notEmpty(request.getOutTradeNo(), "outTradeNo missed"); |
| 38 | - AssertUtils.notEmpty(request.getRedirectUrl(), "redirectUrl missed"); | ||
| 39 | 38 | ||
| 40 | CashierOrder cashierOrder = CashierOrderConverter.INSTANCE.convert(request); | 39 | CashierOrder cashierOrder = CashierOrderConverter.INSTANCE.convert(request); |
| 41 | Merchant merchant = merchantService.loadCashierMerchant(request.getMchId()); | 40 | Merchant merchant = merchantService.loadCashierMerchant(request.getMchId()); |
cashier-boss/src/main/java/com/diligrp/cashier/boss/domain/CashierOrderVO.java
| @@ -5,6 +5,10 @@ import com.diligrp.cashier.pipeline.type.ChannelType; | @@ -5,6 +5,10 @@ import com.diligrp.cashier.pipeline.type.ChannelType; | ||
| 5 | import java.util.List; | 5 | import java.util.List; |
| 6 | 6 | ||
| 7 | public class CashierOrderVO { | 7 | public class CashierOrderVO { |
| 8 | + // 商户号 | ||
| 9 | + private final Long mchId; | ||
| 10 | + // 商户名称 | ||
| 11 | + private final String mchName; | ||
| 8 | // 交易号 | 12 | // 交易号 |
| 9 | private final String tradeId; | 13 | private final String tradeId; |
| 10 | // 业务系统用户标识 | 14 | // 业务系统用户标识 |
| @@ -18,8 +22,10 @@ public class CashierOrderVO { | @@ -18,8 +22,10 @@ public class CashierOrderVO { | ||
| 18 | // 支付通道 | 22 | // 支付通道 |
| 19 | private final List<PaymentPipeline> pipelines; | 23 | private final List<PaymentPipeline> pipelines; |
| 20 | 24 | ||
| 21 | - public CashierOrderVO(String tradeId, String userId, String goods, Long amount, | 25 | + public CashierOrderVO(Long mchId, String mchName, String tradeId, String userId, String goods, Long amount, |
| 22 | String redirectUrl, List<PaymentPipeline> pipelines) { | 26 | String redirectUrl, List<PaymentPipeline> pipelines) { |
| 27 | + this.mchId = mchId; | ||
| 28 | + this.mchName = mchName; | ||
| 23 | this.tradeId = tradeId; | 29 | this.tradeId = tradeId; |
| 24 | this.userId = userId; | 30 | this.userId = userId; |
| 25 | this.goods = goods; | 31 | this.goods = goods; |
| @@ -28,6 +34,14 @@ public class CashierOrderVO { | @@ -28,6 +34,14 @@ public class CashierOrderVO { | ||
| 28 | this.pipelines = pipelines; | 34 | this.pipelines = pipelines; |
| 29 | } | 35 | } |
| 30 | 36 | ||
| 37 | + public Long getMchId() { | ||
| 38 | + return mchId; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public String getMchName() { | ||
| 42 | + return mchName; | ||
| 43 | + } | ||
| 44 | + | ||
| 31 | public String getTradeId() { | 45 | public String getTradeId() { |
| 32 | return tradeId; | 46 | return tradeId; |
| 33 | } | 47 | } |
cashier-boss/src/main/java/com/diligrp/cashier/boss/service/impl/CashierDeskManager.java
| @@ -37,7 +37,6 @@ public class CashierDeskManager implements ICashierDeskManager { | @@ -37,7 +37,6 @@ public class CashierDeskManager implements ICashierDeskManager { | ||
| 37 | AssertUtils.notNull(request.getAmount(), "amount missed"); | 37 | AssertUtils.notNull(request.getAmount(), "amount missed"); |
| 38 | AssertUtils.isTrue(request.getAmount() > 0, "Invalid amount"); | 38 | AssertUtils.isTrue(request.getAmount() > 0, "Invalid amount"); |
| 39 | AssertUtils.notEmpty(request.getOutTradeNo(), "outTradeNo missed"); | 39 | AssertUtils.notEmpty(request.getOutTradeNo(), "outTradeNo missed"); |
| 40 | - AssertUtils.notEmpty(request.getRedirectUrl(), "redirectUrl missed"); | ||
| 41 | 40 | ||
| 42 | CashierOrder cashierOrder = CashierOrderConverter2.INSTANCE.convert(request); | 41 | CashierOrder cashierOrder = CashierOrderConverter2.INSTANCE.convert(request); |
| 43 | Merchant merchant = merchantService.loadCashierMerchant(request.getMchId()); | 42 | Merchant merchant = merchantService.loadCashierMerchant(request.getMchId()); |
cashier-boss/src/main/java/com/diligrp/cashier/boss/service/impl/CashierDeskServiceImpl.java
| @@ -7,6 +7,7 @@ import com.diligrp.cashier.boss.domain.CashierOrderVO; | @@ -7,6 +7,7 @@ import com.diligrp.cashier.boss.domain.CashierOrderVO; | ||
| 7 | import com.diligrp.cashier.boss.domain.CashierPaymentUrl; | 7 | import com.diligrp.cashier.boss.domain.CashierPaymentUrl; |
| 8 | import com.diligrp.cashier.boss.exception.BossServiceException; | 8 | import com.diligrp.cashier.boss.exception.BossServiceException; |
| 9 | import com.diligrp.cashier.boss.service.ICashierDeskService; | 9 | import com.diligrp.cashier.boss.service.ICashierDeskService; |
| 10 | +import com.diligrp.cashier.boss.service.IMerchantService; | ||
| 10 | import com.diligrp.cashier.pipeline.core.PaymentPipeline; | 11 | import com.diligrp.cashier.pipeline.core.PaymentPipeline; |
| 11 | import com.diligrp.cashier.pipeline.domain.OnlinePaymentStatus; | 12 | import com.diligrp.cashier.pipeline.domain.OnlinePaymentStatus; |
| 12 | import com.diligrp.cashier.pipeline.service.IPaymentPipelineManager; | 13 | import com.diligrp.cashier.pipeline.service.IPaymentPipelineManager; |
| @@ -35,6 +36,9 @@ public class CashierDeskServiceImpl implements ICashierDeskService { | @@ -35,6 +36,9 @@ public class CashierDeskServiceImpl implements ICashierDeskService { | ||
| 35 | private ITradeAssistantService tradeAssistantService; | 36 | private ITradeAssistantService tradeAssistantService; |
| 36 | 37 | ||
| 37 | @Resource | 38 | @Resource |
| 39 | + private IMerchantService merchantService; | ||
| 40 | + | ||
| 41 | + @Resource | ||
| 38 | private IPaymentPipelineManager paymentPipelineManager; | 42 | private IPaymentPipelineManager paymentPipelineManager; |
| 39 | 43 | ||
| 40 | @Resource | 44 | @Resource |
| @@ -83,11 +87,12 @@ public class CashierDeskServiceImpl implements ICashierDeskService { | @@ -83,11 +87,12 @@ public class CashierDeskServiceImpl implements ICashierDeskService { | ||
| 83 | if (TradeState.isFinished(trade.getState())) { | 87 | if (TradeState.isFinished(trade.getState())) { |
| 84 | throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "收银台订单已完成,不能进行支付"); | 88 | throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "收银台订单已完成,不能进行支付"); |
| 85 | } | 89 | } |
| 90 | + Merchant merchant = merchantService.loadCashierMerchant(trade.getMchId()); | ||
| 86 | List<PaymentPipeline> pipelines = paymentPipelineManager.listPipelines(orderToken.getMchId(), PaymentPipeline.class); | 91 | List<PaymentPipeline> pipelines = paymentPipelineManager.listPipelines(orderToken.getMchId(), PaymentPipeline.class); |
| 87 | List<CashierOrderVO.PaymentPipeline> pipelineList = pipelines.stream().map(pipeline -> | 92 | List<CashierOrderVO.PaymentPipeline> pipelineList = pipelines.stream().map(pipeline -> |
| 88 | new CashierOrderVO.PaymentPipeline(pipeline.pipelineId(), pipeline.supportedChannel())).toList(); | 93 | new CashierOrderVO.PaymentPipeline(pipeline.pipelineId(), pipeline.supportedChannel())).toList(); |
| 89 | - return new CashierOrderVO(orderToken.getTradeId(), orderToken.getUserId(), trade.getGoods(), trade.getMaxAmount(), | ||
| 90 | - orderToken.getRedirectUrl(), pipelineList); | 94 | + return new CashierOrderVO(merchant.getMchId(), merchant.getName(), orderToken.getTradeId(), orderToken.getUserId(), |
| 95 | + trade.getGoods(), trade.getMaxAmount(), orderToken.getRedirectUrl(), pipelineList); | ||
| 91 | } | 96 | } |
| 92 | 97 | ||
| 93 | /** | 98 | /** |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/CardPaymentHttpClient.java
| @@ -11,7 +11,6 @@ import com.diligrp.cashier.pipeline.type.PaymentState; | @@ -11,7 +11,6 @@ import com.diligrp.cashier.pipeline.type.PaymentState; | ||
| 11 | import com.diligrp.cashier.shared.ErrorCode; | 11 | import com.diligrp.cashier.shared.ErrorCode; |
| 12 | import com.diligrp.cashier.shared.service.ServiceEndpointSupport; | 12 | import com.diligrp.cashier.shared.service.ServiceEndpointSupport; |
| 13 | import com.diligrp.cashier.shared.type.SourceType; | 13 | import com.diligrp.cashier.shared.type.SourceType; |
| 14 | -import com.diligrp.cashier.shared.util.CurrencyUtils; | ||
| 15 | import com.diligrp.cashier.shared.util.JsonUtils; | 14 | import com.diligrp.cashier.shared.util.JsonUtils; |
| 16 | import com.fasterxml.jackson.core.type.TypeReference; | 15 | import com.fasterxml.jackson.core.type.TypeReference; |
| 17 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| @@ -65,11 +64,11 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | @@ -65,11 +64,11 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | ||
| 65 | } | 64 | } |
| 66 | String payload = JsonUtils.toJsonString(params); | 65 | String payload = JsonUtils.toJsonString(params); |
| 67 | 66 | ||
| 68 | - LOG.debug("Sending card payment request: {}", payload); | 67 | + LOG.info("Sending card payment request: {}\n{}", request.getPaymentId(), payload); |
| 69 | LocalDateTime now = LocalDateTime.now(); | 68 | LocalDateTime now = LocalDateTime.now(); |
| 70 | HttpResult result = send(uri, payload); | 69 | HttpResult result = send(uri, payload); |
| 71 | if (result.statusCode == 200) { | 70 | if (result.statusCode == 200) { |
| 72 | - LOG.debug("Received from card payment pipeline: {}", result.responseText); | 71 | + LOG.debug("Received from card payment pipeline: {}\n{}", request.getPaymentId(), result.responseText); |
| 73 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 72 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 74 | if ("200".equals(response.get("code"))) { | 73 | if ("200".equals(response.get("code"))) { |
| 75 | Map<String, Object> data = (Map<String, Object>) response.get("data"); | 74 | Map<String, Object> data = (Map<String, Object>) response.get("data"); |
| @@ -80,7 +79,7 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | @@ -80,7 +79,7 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | ||
| 80 | payerId.put("cardNo", data.get("cardNo")); | 79 | payerId.put("cardNo", data.get("cardNo")); |
| 81 | payerId.put("name", data.get("customerName")); | 80 | payerId.put("name", data.get("customerName")); |
| 82 | return new CardPaymentResponse(request.getPaymentId(), outTradeNo, OutPaymentType.DILICARD, | 81 | return new CardPaymentResponse(request.getPaymentId(), outTradeNo, OutPaymentType.DILICARD, |
| 83 | - JsonUtils.toJsonString(payerId), now, PaymentState.SUCCESS, "园区卡支付成功"); | 82 | + JsonUtils.toJsonString(payerId), now, PaymentState.SUCCESS, "园区卡支付成功"); |
| 84 | } else { | 83 | } else { |
| 85 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "园区卡支付失败: " + response.get("message")); | 84 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "园区卡支付失败: " + response.get("message")); |
| 86 | } | 85 | } |
| @@ -96,11 +95,11 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | @@ -96,11 +95,11 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | ||
| 96 | params.put("amount", request.getAmount()); | 95 | params.put("amount", request.getAmount()); |
| 97 | String payload = JsonUtils.toJsonString(params); | 96 | String payload = JsonUtils.toJsonString(params); |
| 98 | 97 | ||
| 99 | - LOG.debug("Sending card refund request: {}", payload); | 98 | + LOG.info("Sending card refund request: {}\n{}", request.getRefundId(), payload); |
| 100 | LocalDateTime now = LocalDateTime.now(); | 99 | LocalDateTime now = LocalDateTime.now(); |
| 101 | HttpResult result = send(uri, payload); | 100 | HttpResult result = send(uri, payload); |
| 102 | if (result.statusCode == 200) { | 101 | if (result.statusCode == 200) { |
| 103 | - LOG.debug("Received from card payment pipeline: {}", result.responseText); | 102 | + LOG.debug("Received from card payment pipeline: {}\n", request.getRefundId(), result.responseText); |
| 104 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 103 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 105 | if ("200".equals(response.get("code"))) { | 104 | if ("200".equals(response.get("code"))) { |
| 106 | return new OnlineRefundResponse(request.getRefundId(), null, now, | 105 | return new OnlineRefundResponse(request.getRefundId(), null, now, |
| @@ -119,10 +118,10 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | @@ -119,10 +118,10 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | ||
| 119 | params.put("customerId", Long.parseLong(userId)); | 118 | params.put("customerId", Long.parseLong(userId)); |
| 120 | String payload = JsonUtils.toJsonString(params); | 119 | String payload = JsonUtils.toJsonString(params); |
| 121 | 120 | ||
| 122 | - LOG.debug("Sending list user card request: {}", payload); | 121 | + LOG.debug("Sending list user card request: {}\n{}", userId, payload); |
| 123 | HttpResult result = send(uri, payload); | 122 | HttpResult result = send(uri, payload); |
| 124 | if (result.statusCode == 200) { | 123 | if (result.statusCode == 200) { |
| 125 | - LOG.debug("Received from card payment pipeline: {}", result.responseText); | 124 | + LOG.debug("Received from card payment pipeline: {}\n{}", userId, result.responseText); |
| 126 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 125 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 127 | if ("200".equals(response.get("code"))) { | 126 | if ("200".equals(response.get("code"))) { |
| 128 | List<UserCardDTO> userCards = new ArrayList<>(); | 127 | List<UserCardDTO> userCards = new ArrayList<>(); |
| @@ -130,10 +129,9 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | @@ -130,10 +129,9 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport { | ||
| 130 | if (data != null) { | 129 | if (data != null) { |
| 131 | List<Map<String, Object>> cardList = JsonUtils.convertValue(data, new TypeReference<>() {}); | 130 | List<Map<String, Object>> cardList = JsonUtils.convertValue(data, new TypeReference<>() {}); |
| 132 | for (Map<String, Object> card : cardList) { | 131 | for (Map<String, Object> card : cardList) { |
| 133 | - String amount = CurrencyUtils.toNoSymbolCurrency(convertLong(card.get("amount"))); | ||
| 134 | UserCardDTO userCard = new UserCardDTO(convertLong(card.get("customerId")), | 132 | UserCardDTO userCard = new UserCardDTO(convertLong(card.get("customerId")), |
| 135 | convertLong(card.get("accountId")), (String) card.get("cardNo"), | 133 | convertLong(card.get("accountId")), (String) card.get("cardNo"), |
| 136 | - (String) card.get("customerName"), amount); | 134 | + (String) card.get("customerName"), convertLong(card.get("amount"))); |
| 137 | userCards.add(userCard); | 135 | userCards.add(userCard); |
| 138 | } | 136 | } |
| 139 | } | 137 | } |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/RcbOnlineHttpClient.java
| @@ -9,10 +9,7 @@ | @@ -9,10 +9,7 @@ | ||
| 9 | import com.diligrp.cashier.shared.ErrorCode; | 9 | import com.diligrp.cashier.shared.ErrorCode; |
| 10 | import com.diligrp.cashier.shared.exception.ServiceAccessException; | 10 | import com.diligrp.cashier.shared.exception.ServiceAccessException; |
| 11 | import com.diligrp.cashier.shared.service.ServiceEndpointSupport; | 11 | import com.diligrp.cashier.shared.service.ServiceEndpointSupport; |
| 12 | - import com.diligrp.cashier.shared.util.DateUtils; | ||
| 13 | - import com.diligrp.cashier.shared.util.JsonUtils; | ||
| 14 | - import com.diligrp.cashier.shared.util.ObjectUtils; | ||
| 15 | - import com.diligrp.cashier.shared.util.RandomUtils; | 12 | + import com.diligrp.cashier.shared.util.*; |
| 16 | import com.fasterxml.jackson.core.type.TypeReference; | 13 | import com.fasterxml.jackson.core.type.TypeReference; |
| 17 | import jakarta.annotation.Resource; | 14 | import jakarta.annotation.Resource; |
| 18 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
| @@ -58,8 +55,7 @@ public class RcbOnlineHttpClient extends ServiceEndpointSupport { | @@ -58,8 +55,7 @@ public class RcbOnlineHttpClient extends ServiceEndpointSupport { | ||
| 58 | 55 | ||
| 59 | private final String appId; | 56 | private final String appId; |
| 60 | 57 | ||
| 61 | - @Resource | ||
| 62 | - private StringRedisTemplate stringRedisTemplate; | 58 | + private final StringRedisTemplate stringRedisTemplate; |
| 63 | 59 | ||
| 64 | public RcbOnlineHttpClient(String uri, String merchantNo, String terminalNo, String key, String appId) { | 60 | public RcbOnlineHttpClient(String uri, String merchantNo, String terminalNo, String key, String appId) { |
| 65 | this.uri = uri; | 61 | this.uri = uri; |
| @@ -67,6 +63,7 @@ public class RcbOnlineHttpClient extends ServiceEndpointSupport { | @@ -67,6 +63,7 @@ public class RcbOnlineHttpClient extends ServiceEndpointSupport { | ||
| 67 | this.terminalNo = terminalNo; | 63 | this.terminalNo = terminalNo; |
| 68 | this.key = key; | 64 | this.key = key; |
| 69 | this.appId = appId; | 65 | this.appId = appId; |
| 66 | + this.stringRedisTemplate = SpringContextUtils.getBean(StringRedisTemplate.class); | ||
| 70 | } | 67 | } |
| 71 | 68 | ||
| 72 | public String sendMiniProPrepayRequest(MiniProPrepayRequest request, String notifyUrl) { | 69 | public String sendMiniProPrepayRequest(MiniProPrepayRequest request, String notifyUrl) { |
| @@ -86,13 +83,13 @@ public class RcbOnlineHttpClient extends ServiceEndpointSupport { | @@ -86,13 +83,13 @@ public class RcbOnlineHttpClient extends ServiceEndpointSupport { | ||
| 86 | params.put("sign", RcbSignatureUtils.sign(params, key)); | 83 | params.put("sign", RcbSignatureUtils.sign(params, key)); |
| 87 | 84 | ||
| 88 | String payload = JsonUtils.toJsonString(params); | 85 | String payload = JsonUtils.toJsonString(params); |
| 89 | - LOG.debug("Sending rcb minipro prepay request: {}", payload); | 86 | + LOG.info("Sending rcb minipro prepay request: {}\n{}", request.getPaymentId(), payload); |
| 90 | HttpResult result = send(uri + "/cposp/pay/unifiedorder", payload); | 87 | HttpResult result = send(uri + "/cposp/pay/unifiedorder", payload); |
| 91 | if (result.statusCode != STATUS_OK) { | 88 | if (result.statusCode != STATUS_OK) { |
| 92 | LOG.error("Failed to send rcb minipro prepay, statusCode: {}", result.statusCode); | 89 | LOG.error("Failed to send rcb minipro prepay, statusCode: {}", result.statusCode); |
| 93 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "调用小程序预支付接口失败: " + result.statusCode); | 90 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "调用小程序预支付接口失败: " + result.statusCode); |
| 94 | } | 91 | } |
| 95 | - LOG.debug("Received rcb mini pro prepay response: {}", result.responseText); | 92 | + LOG.debug("Received rcb minipro prepay response: {}", result.responseText); |
| 96 | 93 | ||
| 97 | Map<String, String> data = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 94 | Map<String, String> data = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 98 | String resultCode = data.get("resultCode"); | 95 | String resultCode = data.get("resultCode"); |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/WechatDirectHttpClient.java
| @@ -63,7 +63,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -63,7 +63,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 63 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 63 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 64 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 64 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 65 | 65 | ||
| 66 | - LOG.info("Sending wechat native prepay request..."); | 66 | + LOG.info("Sending wechat native prepay request: {}", request.getPaymentId()); |
| 67 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 67 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 68 | HttpResult result = send(wechatBaseUri + NATIVE_PREPAY, headers, payload); | 68 | HttpResult result = send(wechatBaseUri + NATIVE_PREPAY, headers, payload); |
| 69 | verifyHttpResult(result); | 69 | verifyHttpResult(result); |
| @@ -71,7 +71,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -71,7 +71,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 71 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 71 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 72 | return NativePrepayResponse.of(request.getPaymentId(), (String) response.get("code_url")); | 72 | return NativePrepayResponse.of(request.getPaymentId(), (String) response.get("code_url")); |
| 73 | } else { | 73 | } else { |
| 74 | - LOG.error("Wechat native prepay failed: {}\n{}", result.statusCode, result.responseText); | 74 | + LOG.error("Failed to send wechat native prepay request: {}\n{}", request.getPaymentId(), result.responseText); |
| 75 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 75 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 76 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); | 76 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); |
| 77 | } | 77 | } |
| @@ -91,7 +91,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -91,7 +91,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 91 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 91 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 92 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 92 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 93 | 93 | ||
| 94 | - LOG.info("Sending wechat jsapi prepay request..."); | 94 | + LOG.info("Sending wechat jsapi prepay request: {}", request.getPaymentId()); |
| 95 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 95 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 96 | HttpResult result = send(wechatBaseUri + JSAPI_PREPAY, headers, payload); | 96 | HttpResult result = send(wechatBaseUri + JSAPI_PREPAY, headers, payload); |
| 97 | verifyHttpResult(result); | 97 | verifyHttpResult(result); |
| @@ -99,7 +99,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -99,7 +99,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 99 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 99 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 100 | return (String) response.get("prepay_id"); | 100 | return (String) response.get("prepay_id"); |
| 101 | } else { | 101 | } else { |
| 102 | - LOG.error("Wechat jsapi prepay failed: {}\n{}", result.statusCode, result.responseText); | 102 | + LOG.error("Failed to send wechat jsapi prepay request: {}\n{}", request.getPaymentId(), result.responseText); |
| 103 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 103 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 104 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); | 104 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); |
| 105 | } | 105 | } |
| @@ -109,9 +109,9 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -109,9 +109,9 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 109 | * 查询微信预支付订单状态 | 109 | * 查询微信预支付订单状态 |
| 110 | */ | 110 | */ |
| 111 | @Override | 111 | @Override |
| 112 | - public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder order) throws Exception { | 112 | + public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder request) throws Exception { |
| 113 | // 获取认证信息和签名信息 | 113 | // 获取认证信息和签名信息 |
| 114 | - String uri = String.format(TRANSACTION_QUERY, order.getPaymentId(), wechatConfig.getMchId()); | 114 | + String uri = String.format(TRANSACTION_QUERY, request.getPaymentId(), wechatConfig.getMchId()); |
| 115 | String authorization = WechatSignatureUtils.authorization(wechatConfig.getMchId(), WechatConstants.HTTP_GET, uri, | 115 | String authorization = WechatSignatureUtils.authorization(wechatConfig.getMchId(), WechatConstants.HTTP_GET, uri, |
| 116 | wechatConfig.getPrivateKey(), wechatConfig.getSerialNo()); | 116 | wechatConfig.getPrivateKey(), wechatConfig.getSerialNo()); |
| 117 | 117 | ||
| @@ -120,7 +120,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -120,7 +120,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 120 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) | 120 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) |
| 121 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) | 121 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) |
| 122 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 122 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 123 | - LOG.info("Sending wechat query merchant order request..."); | 123 | + LOG.info("Sending wechat query prepay order state request: {}", request.getPaymentId()); |
| 124 | LOG.debug("Authorization: {}\n", authorization); | 124 | LOG.debug("Authorization: {}\n", authorization); |
| 125 | HttpResult result = execute(httpRequest.GET().build()); | 125 | HttpResult result = execute(httpRequest.GET().build()); |
| 126 | verifyHttpResult(result); | 126 | verifyHttpResult(result); |
| @@ -134,7 +134,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -134,7 +134,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 134 | return new OnlinePaymentResponse((String) response.get("out_trade_no"), (String) response.get("transaction_id"), | 134 | return new OnlinePaymentResponse((String) response.get("out_trade_no"), (String) response.get("transaction_id"), |
| 135 | OutPaymentType.WXPAY, openId, when, state, (String) response.get("trade_state_desc")); | 135 | OutPaymentType.WXPAY, openId, when, state, (String) response.get("trade_state_desc")); |
| 136 | } else { | 136 | } else { |
| 137 | - LOG.info("Wechat query transaction status failed: {}", result.statusCode); | 137 | + LOG.error("Failed to query wechat prepay order state: {}\n{}", request.getPaymentId(), result.responseText); |
| 138 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 138 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 139 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信订单查询失败: " + message.getMessage()); | 139 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信订单查询失败: " + message.getMessage()); |
| 140 | } | 140 | } |
| @@ -159,12 +159,12 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -159,12 +159,12 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 159 | headers[0] = HttpHeader.create(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 159 | headers[0] = HttpHeader.create(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 160 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 160 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 161 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 161 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 162 | - LOG.info("Sending close wechat prepay order request..."); | 162 | + LOG.info("Sending close wechat prepay order request: {}", request.getPaymentId()); |
| 163 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 163 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 164 | HttpResult result = send(wechatBaseUri + uri, headers, payload); | 164 | HttpResult result = send(wechatBaseUri + uri, headers, payload); |
| 165 | verifyHttpResult(result); | 165 | verifyHttpResult(result); |
| 166 | - LOG.info("Close wechat prepay order statusCode: {}", result.statusCode); | ||
| 167 | if (result.statusCode != 200 && result.statusCode != 204) { | 166 | if (result.statusCode != 200 && result.statusCode != 204) { |
| 167 | + LOG.error("Failed to close wechat prepay order: {}\n{}", request.getPaymentId(), result.responseText); | ||
| 168 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 168 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 169 | throw new PaymentPipelineException(ErrorCode.INVALID_OBJECT_STATE, "关闭微信订单失败: " + message.getMessage()); | 169 | throw new PaymentPipelineException(ErrorCode.INVALID_OBJECT_STATE, "关闭微信订单失败: " + message.getMessage()); |
| 170 | } | 170 | } |
| @@ -184,7 +184,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -184,7 +184,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 184 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 184 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 185 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 185 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 186 | 186 | ||
| 187 | - LOG.info("Sending wechat payment refund request..."); | 187 | + LOG.info("Sending wechat payment refund request: {}", request.getPaymentId()); |
| 188 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 188 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 189 | HttpResult result = send(wechatBaseUri + TRANSACTION_REFUND, headers, payload); | 189 | HttpResult result = send(wechatBaseUri + TRANSACTION_REFUND, headers, payload); |
| 190 | verifyHttpResult(result); | 190 | verifyHttpResult(result); |
| @@ -195,7 +195,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -195,7 +195,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 195 | return new OnlineRefundResponse((String) response.get("out_refund_no"), (String) response.get("refund_id"), | 195 | return new OnlineRefundResponse((String) response.get("out_refund_no"), (String) response.get("refund_id"), |
| 196 | when, state, (String) response.get("status")); | 196 | when, state, (String) response.get("status")); |
| 197 | } else { | 197 | } else { |
| 198 | - LOG.info("send wechat refund failed: {}", result.statusCode); | 198 | + LOG.error("Failed to send wechat refund request: {}\n{}", request.getPaymentId(), result.responseText); |
| 199 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 199 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 200 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信退款失败: " + message.getMessage()); | 200 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信退款失败: " + message.getMessage()); |
| 201 | } | 201 | } |
| @@ -215,7 +215,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -215,7 +215,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 215 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) | 215 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) |
| 216 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) | 216 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) |
| 217 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 217 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 218 | - LOG.info("Sending wechat refund query request..."); | 218 | + LOG.info("Sending query wechat refund state: {}", request.getRefundId()); |
| 219 | LOG.debug("Authorization: {}\n", authorization); | 219 | LOG.debug("Authorization: {}\n", authorization); |
| 220 | HttpResult result = execute(httpRequest.GET().build()); | 220 | HttpResult result = execute(httpRequest.GET().build()); |
| 221 | verifyHttpResult(result); | 221 | verifyHttpResult(result); |
| @@ -228,7 +228,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | @@ -228,7 +228,7 @@ public class WechatDirectHttpClient extends WechatHttpClient { | ||
| 228 | } else if (result.statusCode == 404) { | 228 | } else if (result.statusCode == 404) { |
| 229 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "发起微信退款查询失败: 退款单不存在"); | 229 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "发起微信退款查询失败: 退款单不存在"); |
| 230 | } else { | 230 | } else { |
| 231 | - LOG.info("Wechat refund query failed: {}", result.statusCode); | 231 | + LOG.error("Failed to send wechat refund state: {}\n{}", request.getRefundId(), result.responseText); |
| 232 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 232 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 233 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "微信退款查询失败: " + message.getMessage()); | 233 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "微信退款查询失败: " + message.getMessage()); |
| 234 | } | 234 | } |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/WechatHttpClient.java
| @@ -164,18 +164,18 @@ public class WechatHttpClient extends ServiceEndpointSupport { | @@ -164,18 +164,18 @@ public class WechatHttpClient extends ServiceEndpointSupport { | ||
| 164 | .version(HttpClient.Version.HTTP_2).timeout(Duration.ofMillis(MAX_REQUEST_TIMEOUT_TIME)) | 164 | .version(HttpClient.Version.HTTP_2).timeout(Duration.ofMillis(MAX_REQUEST_TIMEOUT_TIME)) |
| 165 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) | 165 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) |
| 166 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 166 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 167 | - LOG.info("Requesting MiniPro login authorization info: {}\n{}", code, uri); | 167 | + LOG.info("Requesting wechat MiniPro login authorization info: {}\n{}", code, uri); |
| 168 | HttpResult result = execute(request.GET().build()); | 168 | HttpResult result = execute(request.GET().build()); |
| 169 | if (result.statusCode == 200) { | 169 | if (result.statusCode == 200) { |
| 170 | - LOG.debug("MiniPro login authorization info response\n{}", result.responseText); | 170 | + LOG.debug("Wechat MiniPro login authorization info response\n{}", result.responseText); |
| 171 | AuthorizationSession session = JsonUtils.fromJsonString(result.responseText, AuthorizationSession.class); | 171 | AuthorizationSession session = JsonUtils.fromJsonString(result.responseText, AuthorizationSession.class); |
| 172 | if (session.getErrcode() != null && session.getErrcode() != 0) { | 172 | if (session.getErrcode() != null && session.getErrcode() != 0) { |
| 173 | - LOG.error("Request MiniPro login authorization info failed: {}", session.getErrmsg()); | 173 | + LOG.error("Failed to request wechat MiniPro login authorization info: {}", session.getErrmsg()); |
| 174 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "获取小程序登录授权信息失败: " + session.getErrmsg()); | 174 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "获取小程序登录授权信息失败: " + session.getErrmsg()); |
| 175 | } | 175 | } |
| 176 | return session.getOpenid(); | 176 | return session.getOpenid(); |
| 177 | } else { | 177 | } else { |
| 178 | - LOG.error("Request MiniPro login authorization info failed: {}", result.statusCode); | 178 | + LOG.error("Failed to request wechat MiniPro login authorization info: {}", result.statusCode); |
| 179 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "获取小程序登录授权信息失败"); | 179 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "获取小程序登录授权信息失败"); |
| 180 | } | 180 | } |
| 181 | } | 181 | } |
| @@ -195,14 +195,14 @@ public class WechatHttpClient extends ServiceEndpointSupport { | @@ -195,14 +195,14 @@ public class WechatHttpClient extends ServiceEndpointSupport { | ||
| 195 | params.put("secret", appSecret); | 195 | params.put("secret", appSecret); |
| 196 | params.put("force_refresh", Boolean.FALSE); | 196 | params.put("force_refresh", Boolean.FALSE); |
| 197 | String payload = JsonUtils.toJsonString(params); | 197 | String payload = JsonUtils.toJsonString(params); |
| 198 | - LOG.debug("Request MiniPro Api access token: {}", payload); | 198 | + LOG.info("Requesting wechat MiniPro Api access token: {}", payload); |
| 199 | HttpResult result = send(ACCESS_TOKEN_URL, payload); | 199 | HttpResult result = send(ACCESS_TOKEN_URL, payload); |
| 200 | if (result.statusCode == 200) { | 200 | if (result.statusCode == 200) { |
| 201 | - LOG.debug("MiniPro Api access token response: {}", result.responseText); | 201 | + LOG.debug("Wechat MiniPro Api access token response: {}", result.responseText); |
| 202 | Map<String, Object> data = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 202 | Map<String, Object> data = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 203 | return WechatAccessToken.of((String)data.get("access_token"), (Integer) data.get("expires_in")); | 203 | return WechatAccessToken.of((String)data.get("access_token"), (Integer) data.get("expires_in")); |
| 204 | } else { | 204 | } else { |
| 205 | - LOG.error("Request MiniPro Api access token failed: {}", result.statusCode); | 205 | + LOG.error("Failed to request MiniPro Api access token: {}", result.statusCode); |
| 206 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "获取微信接口调用凭证失败"); | 206 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "获取微信接口调用凭证失败"); |
| 207 | } | 207 | } |
| 208 | } | 208 | } |
| @@ -234,7 +234,7 @@ public class WechatHttpClient extends ServiceEndpointSupport { | @@ -234,7 +234,7 @@ public class WechatHttpClient extends ServiceEndpointSupport { | ||
| 234 | params.put("payer", payer); | 234 | params.put("payer", payer); |
| 235 | 235 | ||
| 236 | String payload = JsonUtils.toJsonString(params); | 236 | String payload = JsonUtils.toJsonString(params); |
| 237 | - LOG.debug("Request wechat upload shipping: {}", payload); | 237 | + LOG.info("Requesting wechat upload shipping: {}", payload); |
| 238 | HttpResult result = send(uri, payload); | 238 | HttpResult result = send(uri, payload); |
| 239 | if (result.statusCode == 200) { | 239 | if (result.statusCode == 200) { |
| 240 | LOG.debug("Wechat upload shipping response: {}", result.responseText); | 240 | LOG.debug("Wechat upload shipping response: {}", result.responseText); |
| @@ -245,7 +245,7 @@ public class WechatHttpClient extends ServiceEndpointSupport { | @@ -245,7 +245,7 @@ public class WechatHttpClient extends ServiceEndpointSupport { | ||
| 245 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "微信发货信息录入失败: " + errorMessage); | 245 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "微信发货信息录入失败: " + errorMessage); |
| 246 | } | 246 | } |
| 247 | } else { | 247 | } else { |
| 248 | - LOG.error("Request wechat upload shipping failed: {}", result.statusCode); | 248 | + LOG.error("Failed to request wechat upload shipping: {}", result.statusCode); |
| 249 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "调用微信发货信息录入接口失败"); | 249 | throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "调用微信发货信息录入接口失败"); |
| 250 | } | 250 | } |
| 251 | } | 251 | } |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/WechatPartnerHttpClient.java
| @@ -64,7 +64,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -64,7 +64,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 64 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 64 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 65 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 65 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 66 | 66 | ||
| 67 | - LOG.info("Sending wechat native prepay request..."); | 67 | + LOG.info("Sending wechat native prepay request: {}", request.getPaymentId()); |
| 68 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 68 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 69 | HttpResult result = send(wechatBaseUri + NATIVE_PREPAY, headers, payload); | 69 | HttpResult result = send(wechatBaseUri + NATIVE_PREPAY, headers, payload); |
| 70 | verifyHttpResult(result); | 70 | verifyHttpResult(result); |
| @@ -72,7 +72,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -72,7 +72,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 72 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 72 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 73 | return NativePrepayResponse.of(request.getPaymentId(), (String) response.get("code_url")); | 73 | return NativePrepayResponse.of(request.getPaymentId(), (String) response.get("code_url")); |
| 74 | } else { | 74 | } else { |
| 75 | - LOG.error("Wechat native prepay failed: {}\n{}", result.statusCode, result.responseText); | 75 | + LOG.error("Failed to send wechat native prepay request: {}\n{}", request.getPaymentId(), result.responseText); |
| 76 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 76 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 77 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); | 77 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); |
| 78 | } | 78 | } |
| @@ -92,7 +92,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -92,7 +92,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 92 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 92 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 93 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 93 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 94 | 94 | ||
| 95 | - LOG.info("Sending wechat JsApI prepay request..."); | 95 | + LOG.info("Sending wechat jsapi prepay request: {}", request.getPaymentId()); |
| 96 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 96 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 97 | HttpResult result = send(wechatBaseUri + JSAPI_PREPAY, headers, payload); | 97 | HttpResult result = send(wechatBaseUri + JSAPI_PREPAY, headers, payload); |
| 98 | verifyHttpResult(result); | 98 | verifyHttpResult(result); |
| @@ -100,7 +100,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -100,7 +100,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 100 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); | 100 | Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {}); |
| 101 | return (String) response.get("prepay_id"); | 101 | return (String) response.get("prepay_id"); |
| 102 | } else { | 102 | } else { |
| 103 | - LOG.error("Wechat JsApI prepay failed: {}\n{}", result.statusCode, result.responseText); | 103 | + LOG.error("Failed to send wechat jsapi prepay request: {}\n{}", request.getPaymentId(), result.responseText); |
| 104 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 104 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 105 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); | 105 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败: " + message.getMessage()); |
| 106 | } | 106 | } |
| @@ -110,12 +110,12 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -110,12 +110,12 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 110 | * 查询微信预支付订单状态 | 110 | * 查询微信预支付订单状态 |
| 111 | */ | 111 | */ |
| 112 | @Override | 112 | @Override |
| 113 | - public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder order) throws Exception { | ||
| 114 | - String subMchId = order.getString(Constants.PARAM_MCH_ID); | 113 | + public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder request) throws Exception { |
| 114 | + String subMchId = request.getString(Constants.PARAM_MCH_ID); | ||
| 115 | AssertUtils.notEmpty(subMchId, "参数错误: 服务商模式下缺失子商户号"); | 115 | AssertUtils.notEmpty(subMchId, "参数错误: 服务商模式下缺失子商户号"); |
| 116 | 116 | ||
| 117 | // 获取认证信息和签名信息 | 117 | // 获取认证信息和签名信息 |
| 118 | - String uri = String.format(TRANSACTION_QUERY, order.getPaymentId(), wechatConfig.getMchId(), subMchId); | 118 | + String uri = String.format(TRANSACTION_QUERY, request.getPaymentId(), wechatConfig.getMchId(), subMchId); |
| 119 | String authorization = WechatSignatureUtils.authorization(wechatConfig.getMchId(), WechatConstants.HTTP_GET, uri, | 119 | String authorization = WechatSignatureUtils.authorization(wechatConfig.getMchId(), WechatConstants.HTTP_GET, uri, |
| 120 | wechatConfig.getPrivateKey(), wechatConfig.getSerialNo()); | 120 | wechatConfig.getPrivateKey(), wechatConfig.getSerialNo()); |
| 121 | 121 | ||
| @@ -124,7 +124,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -124,7 +124,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 124 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) | 124 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) |
| 125 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) | 125 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) |
| 126 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 126 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 127 | - LOG.info("Sending wechat query merchant order request..."); | 127 | + LOG.info("Sending wechat query prepay order state request: {}", request.getPaymentId()); |
| 128 | LOG.debug("Authorization: {}\n", authorization); | 128 | LOG.debug("Authorization: {}\n", authorization); |
| 129 | HttpResult result = execute(httpRequest.GET().build()); | 129 | HttpResult result = execute(httpRequest.GET().build()); |
| 130 | verifyHttpResult(result); | 130 | verifyHttpResult(result); |
| @@ -138,7 +138,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -138,7 +138,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 138 | return new OnlinePaymentResponse((String) response.get("out_trade_no"), (String) response.get("transaction_id"), | 138 | return new OnlinePaymentResponse((String) response.get("out_trade_no"), (String) response.get("transaction_id"), |
| 139 | OutPaymentType.WXPAY, openId, when, state, (String) response.get("trade_state_desc")); | 139 | OutPaymentType.WXPAY, openId, when, state, (String) response.get("trade_state_desc")); |
| 140 | } else { | 140 | } else { |
| 141 | - LOG.info("Wechat query transaction status failed: {}", result.statusCode); | 141 | + LOG.error("Failed to query wechat prepay order state: {}\n{}", request.getPaymentId(), result.responseText); |
| 142 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 142 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 143 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信订单查询失败: " + message.getMessage()); | 143 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信订单查询失败: " + message.getMessage()); |
| 144 | } | 144 | } |
| @@ -167,11 +167,11 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -167,11 +167,11 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 167 | headers[0] = HttpHeader.create(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 167 | headers[0] = HttpHeader.create(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 168 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 168 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 169 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 169 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 170 | - LOG.info("Sending close wechat prepay order request..."); | 170 | + LOG.info("Sending close wechat prepay order request: {}", request.getPaymentId()); |
| 171 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 171 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 172 | HttpResult result = send(wechatBaseUri + uri, headers, payload); | 172 | HttpResult result = send(wechatBaseUri + uri, headers, payload); |
| 173 | verifyHttpResult(result); | 173 | verifyHttpResult(result); |
| 174 | - LOG.info("Close wechat prepay order statusCode: {}", result.statusCode); | 174 | + LOG.error("Failed to close wechat prepay order: {}\n{}", request.getPaymentId(), result.responseText); |
| 175 | if (result.statusCode != 200 && result.statusCode != 204) { | 175 | if (result.statusCode != 200 && result.statusCode != 204) { |
| 176 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 176 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 177 | throw new PaymentPipelineException(ErrorCode.INVALID_OBJECT_STATE, "关闭微信订单失败: " + message.getMessage()); | 177 | throw new PaymentPipelineException(ErrorCode.INVALID_OBJECT_STATE, "关闭微信订单失败: " + message.getMessage()); |
| @@ -192,7 +192,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -192,7 +192,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 192 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); | 192 | headers[1] = HttpHeader.create(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON); |
| 193 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); | 193 | headers[2] = HttpHeader.create(WechatConstants.HEADER_AUTHORIZATION, authorization); |
| 194 | 194 | ||
| 195 | - LOG.info("Sending wechat payment refund request..."); | 195 | + LOG.info("Sending wechat payment refund request: {}", request.getPaymentId()); |
| 196 | LOG.debug("Authorization: {}\n{}", authorization, payload); | 196 | LOG.debug("Authorization: {}\n{}", authorization, payload); |
| 197 | HttpResult result = send(wechatBaseUri + NATIVE_REFUND, headers, payload); | 197 | HttpResult result = send(wechatBaseUri + NATIVE_REFUND, headers, payload); |
| 198 | verifyHttpResult(result); | 198 | verifyHttpResult(result); |
| @@ -203,7 +203,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -203,7 +203,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 203 | return new OnlineRefundResponse((String) response.get("out_refund_no"), (String) response.get("refund_id"), | 203 | return new OnlineRefundResponse((String) response.get("out_refund_no"), (String) response.get("refund_id"), |
| 204 | when, state, (String) response.get("status")); | 204 | when, state, (String) response.get("status")); |
| 205 | } else { | 205 | } else { |
| 206 | - LOG.info("send wechat payment refund failed: {}", result.statusCode); | 206 | + LOG.error("Failed to send wechat refund request: {}\n{}", request.getPaymentId(), result.responseText); |
| 207 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 207 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 208 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信退款失败: " + message.getMessage()); | 208 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信退款失败: " + message.getMessage()); |
| 209 | } | 209 | } |
| @@ -226,7 +226,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -226,7 +226,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 226 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) | 226 | .header(CONTENT_TYPE, CONTENT_TYPE_JSON).header(WechatConstants.HEADER_AUTHORIZATION, authorization) |
| 227 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) | 227 | .header(WechatConstants.HEADER_ACCEPT, WechatConstants.ACCEPT_JSON) |
| 228 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); | 228 | .header(WechatConstants.HEADER_USER_AGENT, WechatConstants.USER_AGENT); |
| 229 | - LOG.info("Sending wechat refund query request..."); | 229 | + LOG.info("Sending query wechat refund state: {}", request.getRefundId()); |
| 230 | LOG.debug("Authorization: {}\n", authorization); | 230 | LOG.debug("Authorization: {}\n", authorization); |
| 231 | HttpResult result = execute(httpRequest.GET().build()); | 231 | HttpResult result = execute(httpRequest.GET().build()); |
| 232 | verifyHttpResult(result); | 232 | verifyHttpResult(result); |
| @@ -239,7 +239,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | @@ -239,7 +239,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient { | ||
| 239 | } else if (result.statusCode == 404) { | 239 | } else if (result.statusCode == 404) { |
| 240 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "发起微信退款查询失败: 退款单不存在"); | 240 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "发起微信退款查询失败: 退款单不存在"); |
| 241 | } else { | 241 | } else { |
| 242 | - LOG.info("Wechat query mch refund failed: {}", result.statusCode); | 242 | + LOG.error("Failed to send wechat refund state: {}\n{}", request.getRefundId(), result.responseText); |
| 243 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); | 243 | ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class); |
| 244 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "微信退款查询失败: " + message.getMessage()); | 244 | throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "微信退款查询失败: " + message.getMessage()); |
| 245 | } | 245 | } |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/domain/card/UserCardDTO.java
| @@ -13,12 +13,12 @@ public class UserCardDTO { | @@ -13,12 +13,12 @@ public class UserCardDTO { | ||
| 13 | // 持卡人名称 | 13 | // 持卡人名称 |
| 14 | private String name; | 14 | private String name; |
| 15 | // 卡余额 | 15 | // 卡余额 |
| 16 | - private String amount; | 16 | + private Long amount; |
| 17 | 17 | ||
| 18 | public UserCardDTO() { | 18 | public UserCardDTO() { |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | - public UserCardDTO(Long customerId, Long accountId, String cardNo, String name, String amount) { | 21 | + public UserCardDTO(Long customerId, Long accountId, String cardNo, String name, Long amount) { |
| 22 | this.customerId = customerId; | 22 | this.customerId = customerId; |
| 23 | this.accountId = accountId; | 23 | this.accountId = accountId; |
| 24 | this.cardNo = cardNo; | 24 | this.cardNo = cardNo; |
| @@ -58,11 +58,11 @@ public class UserCardDTO { | @@ -58,11 +58,11 @@ public class UserCardDTO { | ||
| 58 | this.name = name; | 58 | this.name = name; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | - public String getAmount() { | 61 | + public Long getAmount() { |
| 62 | return amount; | 62 | return amount; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | - public void setAmount(String amount) { | 65 | + public void setAmount(Long amount) { |
| 66 | this.amount = amount; | 66 | this.amount = amount; |
| 67 | } | 67 | } |
| 68 | } | 68 | } |
cashier-trade/src/main/java/com/diligrp/cashier/trade/service/impl/TradeAssistantServiceImpl.java
| @@ -65,6 +65,7 @@ public class TradeAssistantServiceImpl implements ITradeAssistantService { | @@ -65,6 +65,7 @@ public class TradeAssistantServiceImpl implements ITradeAssistantService { | ||
| 65 | List<OnlinePayment> onlinePayments = onlinePaymentDao.listOnlinePayments(trade.getTradeId(), TradeType.TRADE.getCode(), null); | 65 | List<OnlinePayment> onlinePayments = onlinePaymentDao.listOnlinePayments(trade.getTradeId(), TradeType.TRADE.getCode(), null); |
| 66 | for (OnlinePayment payment : onlinePayments) { | 66 | for (OnlinePayment payment : onlinePayments) { |
| 67 | if (!PaymentState.isFinished(payment.getState())) { | 67 | if (!PaymentState.isFinished(payment.getState())) { |
| 68 | + LOG.info("Trying to close payment order in process: {}", payment.getPaymentId()); | ||
| 68 | PaymentPipeline<?> pipeline = paymentPipelineManager.findPipelineById(payment.getPipelineId(), PaymentPipeline.class); | 69 | PaymentPipeline<?> pipeline = paymentPipelineManager.findPipelineById(payment.getPipelineId(), PaymentPipeline.class); |
| 69 | if (pipeline instanceof OnlinePipeline<?> onlinePipeline) { | 70 | if (pipeline instanceof OnlinePipeline<?> onlinePipeline) { |
| 70 | // 理论上只存在一条支付中的支付记录,否则后面的支付通道关闭失败时,会回滚前面支付记录的状态修改 | 71 | // 理论上只存在一条支付中的支付记录,否则后面的支付通道关闭失败时,会回滚前面支付记录的状态修改 |