Commit d123ce1abbe54447bc64028d37a2a325efea33a1

Authored by huanggang
1 parent c09450ac

upgrade after testing

cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/CardPaymentHttpClient.java
... ... @@ -69,12 +69,18 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport {
69 69 HttpResult result = send(uri, payload);
70 70 if (result.statusCode == 200) {
71 71 LOG.debug("Received from card payment pipeline: {}", result.responseText);
72   - Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {});
  72 + Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {
  73 + });
73 74 if ("200".equals(response.get("code"))) {
74   - String outTradeNo = (String) response.get("data");
75   - return new CardPaymentResponse(request.getPaymentId(), outTradeNo,
76   - OutPaymentType.DILICARD, String.valueOf(request.getAccountId()), now,
77   - PaymentState.SUCCESS, "园区卡支付成功");
  75 + Map<String, Object> data = (Map<String, Object>) response.get("data");
  76 + String outTradeNo = (String) data.get("outTradeNo");
  77 + Map<String, Object> payerId = new LinkedHashMap<>();
  78 + payerId.put("customerId", convertLong(data.get("customerId")));
  79 + payerId.put("accountId", convertLong(data.get("accountId")));
  80 + payerId.put("cardNo", data.get("cardNo"));
  81 + payerId.put("name", data.get("name"));
  82 + return new CardPaymentResponse(request.getPaymentId(), outTradeNo, OutPaymentType.DILICARD,
  83 + JsonUtils.toJsonString(payerId), now, PaymentState.SUCCESS, "园区卡支付成功");
78 84 } else {
79 85 throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "园区卡支付失败: " + response.get("message"));
80 86 }
... ... @@ -95,10 +101,11 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport {
95 101 HttpResult result = send(uri, payload);
96 102 if (result.statusCode == 200) {
97 103 LOG.debug("Received from card payment pipeline: {}", result.responseText);
98   - Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {});
  104 + Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {
  105 + });
99 106 if ("200".equals(response.get("code"))) {
100 107 return new OnlineRefundResponse(request.getRefundId(), null, now,
101   - PaymentState.SUCCESS, "园区卡退款成功");
  108 + PaymentState.SUCCESS, "园区卡退款成功");
102 109 } else {
103 110 throw new PaymentPipelineException(ErrorCode.SERVICE_ACCESS_ERROR, "园区卡支付退款失败: " + response.get("message"));
104 111 }
... ... @@ -117,16 +124,18 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport {
117 124 HttpResult result = send(uri, payload);
118 125 if (result.statusCode == 200) {
119 126 LOG.debug("Received from card payment pipeline: {}", result.responseText);
120   - Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {});
  127 + Map<String, Object> response = JsonUtils.fromJsonString(result.responseText, new TypeReference<>() {
  128 + });
121 129 if ("200".equals(response.get("code"))) {
122 130 List<UserCardDTO> userCards = new ArrayList<>();
123 131 Object data = response.get("data");
124 132 if (data != null) {
125   - List<Map<String, Object>> cardList = JsonUtils.convertValue(data, new TypeReference<>() {});
  133 + List<Map<String, Object>> cardList = JsonUtils.convertValue(data, new TypeReference<>() {
  134 + });
126 135 for (Map<String, Object> card : cardList) {
127 136 UserCardDTO userCard = new UserCardDTO(convertLong(card.get("customerId")),
128   - convertLong(card.get("accountId")), (String) card.get("cardNo"),
129   - (String) card.get("customerName"), convertLong(card.get("amount")));
  137 + convertLong(card.get("accountId")), (String) card.get("cardNo"),
  138 + (String) card.get("customerName"), convertLong(card.get("amount")));
130 139 userCards.add(userCard);
131 140 }
132 141 }
... ... @@ -142,4 +151,4 @@ public class CardPaymentHttpClient extends ServiceEndpointSupport {
142 151 private Long convertLong(Object value) {
143 152 return value != null ? ((Number) value).longValue() : null;
144 153 }
145 154 -}
  155 +}
146 156 \ No newline at end of file
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatDirectPipeline.java
... ... @@ -4,7 +4,14 @@ import com.diligrp.cashier.pipeline.Constants;
4 4 import com.diligrp.cashier.pipeline.client.WechatDirectHttpClient;
5 5 import com.diligrp.cashier.pipeline.client.WechatHttpClient;
6 6 import com.diligrp.cashier.pipeline.domain.*;
  7 +import com.diligrp.cashier.pipeline.exception.PaymentPipelineException;
  8 +import com.diligrp.cashier.pipeline.util.WechatConstants;
  9 +import com.diligrp.cashier.pipeline.util.WechatSignatureUtils;
  10 +import com.diligrp.cashier.shared.ErrorCode;
7 11 import com.diligrp.cashier.shared.util.AssertUtils;
  12 +import com.diligrp.cashier.shared.util.RandomUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
8 15  
9 16 /**
10 17 * 微信支付通道抽象模型-直联模式
... ... @@ -13,6 +20,9 @@ import com.diligrp.cashier.shared.util.AssertUtils;
13 20 * upay_wechat_param需配置商户API接口所需配置信息
14 21 */
15 22 public class WechatDirectPipeline extends WechatPipeline<WechatDirectPipeline.DirectWechatParams> {
  23 +
  24 + private static final Logger LOG = LoggerFactory.getLogger(WechatDirectPipeline.class);
  25 +
16 26 private final ScanTimeStrategy strategy;
17 27  
18 28 // 直联模式下的微信客户端
... ... @@ -41,11 +51,27 @@ public class WechatDirectPipeline extends WechatPipeline&lt;WechatDirectPipeline.Di
41 51 return super.sendNativePrepayRequest(request);
42 52 }
43 53  
44   - @Override
45 54 public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) {
46   - // 直连模式下,外部商户号设置为微信商户号
47   - request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
48   - return super.sendMiniProPrepayRequest(request);
  55 + try {
  56 + // 直连模式下,外部商户号设置为微信商户号
  57 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  58 + String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params().getNotifyUrl(), request.getPaymentId());
  59 + String prepayId = getClient().sendMiniProPrepayRequest(request, notifyUri);
  60 +
  61 + String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
  62 + String nonceStr = RandomUtils.randomString(32);
  63 + String packet = "prepay_id=" + prepayId;
  64 + String appId = getClient().getWechatConfig().getAppId();
  65 + String message = String.format("%s\n%s\n%s\n%s\n", appId, timeStamp, nonceStr, packet);
  66 + String paySign = WechatSignatureUtils.signature(message, getClient().getWechatConfig().getPrivateKey());
  67 + String signType = WechatConstants.RSA_ALGORITHM;
  68 + return MiniProPrepayResponse.of(request.getPaymentId(), prepayId, prepayId, timeStamp, nonceStr, signType, paySign);
  69 + } catch (PaymentPipelineException | IllegalArgumentException pse) {
  70 + throw pse;
  71 + } catch (Exception ex) {
  72 + LOG.error("Send wechat mini pro prepay request exception", ex);
  73 + throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败");
  74 + }
49 75 }
50 76  
51 77 @Override
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatPartnerPipeline.java
... ... @@ -4,7 +4,14 @@ import com.diligrp.cashier.pipeline.Constants;
4 4 import com.diligrp.cashier.pipeline.client.WechatHttpClient;
5 5 import com.diligrp.cashier.pipeline.client.WechatPartnerHttpClient;
6 6 import com.diligrp.cashier.pipeline.domain.*;
  7 +import com.diligrp.cashier.pipeline.exception.PaymentPipelineException;
  8 +import com.diligrp.cashier.pipeline.util.WechatConstants;
  9 +import com.diligrp.cashier.pipeline.util.WechatSignatureUtils;
  10 +import com.diligrp.cashier.shared.ErrorCode;
7 11 import com.diligrp.cashier.shared.util.AssertUtils;
  12 +import com.diligrp.cashier.shared.util.RandomUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
8 15  
9 16 /**
10 17 * 微信支付通道抽象模型-服务商模式
... ... @@ -15,6 +22,8 @@ import com.diligrp.cashier.shared.util.AssertUtils;
15 22 */
16 23 public class WechatPartnerPipeline extends WechatPipeline<WechatPartnerPipeline.PartnerWechatParams> {
17 24  
  25 + private static final Logger LOG = LoggerFactory.getLogger(WechatPartnerPipeline.class);
  26 +
18 27 private final ScanTimeStrategy strategy;
19 28  
20 29 // 服务商模式下的微信客户端
... ... @@ -49,9 +58,27 @@ public class WechatPartnerPipeline extends WechatPipeline&lt;WechatPartnerPipeline.
49 58  
50 59 @Override
51 60 public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) {
52   - // 服务商模式下,外部商户号默认设置为特约子商户
53   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
54   - return super.sendMiniProPrepayRequest(request);
  61 + try {
  62 + // 服务商模式下,外部商户号默认设置为特约子商户
  63 + PartnerWechatParams params = params();
  64 + request.put(Constants.PARAM_MCH_ID, params.getSubMchId());
  65 + String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params.getNotifyUrl(), request.getPaymentId());
  66 + String prepayId = getClient().sendMiniProPrepayRequest(request, notifyUri);
  67 +
  68 + String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
  69 + String nonceStr = RandomUtils.randomString(32);
  70 + String packet = "prepay_id=" + prepayId;
  71 + String message = String.format("%s\n%s\n%s\n%s\n", params.getSubAppId(), timeStamp, nonceStr, packet);
  72 + // 签名时需要使用配置的subAppId
  73 + String paySign = WechatSignatureUtils.signature(message, getClient().getWechatConfig().getPrivateKey());
  74 + String signType = WechatConstants.RSA_ALGORITHM;
  75 + return MiniProPrepayResponse.of(request.getPaymentId(), prepayId, prepayId, timeStamp, nonceStr, signType, paySign);
  76 + } catch (PaymentPipelineException | IllegalArgumentException pse) {
  77 + throw pse;
  78 + } catch (Exception ex) {
  79 + LOG.error("Send wechat mini pro prepay request exception", ex);
  80 + throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败");
  81 + }
55 82 }
56 83  
57 84 @Override
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatPipeline.java
... ... @@ -8,11 +8,9 @@ import com.diligrp.cashier.pipeline.domain.wechat.WechatConfig;
8 8 import com.diligrp.cashier.pipeline.exception.PaymentPipelineException;
9 9 import com.diligrp.cashier.pipeline.type.ChannelType;
10 10 import com.diligrp.cashier.pipeline.util.WechatConstants;
11   -import com.diligrp.cashier.pipeline.util.WechatSignatureUtils;
12 11 import com.diligrp.cashier.shared.ErrorCode;
13 12 import com.diligrp.cashier.shared.security.RsaCipher;
14 13 import com.diligrp.cashier.shared.util.AssertUtils;
15   -import com.diligrp.cashier.shared.util.RandomUtils;
16 14 import org.slf4j.Logger;
17 15 import org.slf4j.LoggerFactory;
18 16  
... ... @@ -100,24 +98,7 @@ public abstract class WechatPipeline&lt;T extends WechatPipeline.WechatParams&gt; exte
100 98 * 小程序预支付下单
101 99 */
102 100 public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) {
103   - try {
104   - String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params().getNotifyUrl(), request.getPaymentId());
105   - String prepayId = getClient().sendMiniProPrepayRequest(request, notifyUri);
106   -
107   - String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
108   - String nonceStr = RandomUtils.randomString(32);
109   - String packet = "prepay_id=" + prepayId;
110   - String appId = getClient().getWechatConfig().getAppId();
111   - String message = String.format("%s\n%s\n%s\n%s\n", appId, timeStamp, nonceStr, packet);
112   - String paySign = WechatSignatureUtils.signature(message, getClient().getWechatConfig().getPrivateKey());
113   - String signType = WechatConstants.RSA_ALGORITHM;
114   - return MiniProPrepayResponse.of(request.getPaymentId(), prepayId, prepayId, timeStamp, nonceStr, signType, paySign);
115   - } catch (PaymentPipelineException | IllegalArgumentException pse) {
116   - throw pse;
117   - } catch (Exception ex) {
118   - LOG.error("Send wechat mini pro prepay request exception", ex);
119   - throw new PaymentPipelineException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "发起微信预支付失败");
120   - }
  101 + return super.sendMiniProPrepayRequest(request);
121 102 }
122 103  
123 104 /**
... ...