Commit ea665fba683c65887e7a23658b354472b9bbd69a

Authored by huanggang
1 parent 173ef84e

bugfix after testing

cashier-boss/src/main/java/com/diligrp/cashier/boss/controller/CashierDeskController.java
... ... @@ -51,7 +51,7 @@ public class CashierDeskController {
51 51 @RequestMapping("/orderPayment")
52 52 public Message<?> orderPayment(@RequestBody CashierPayment request) {
53 53 // 基本参数校验
54   - AssertUtils.notEmpty(request.getTradeId(), "paymentId missed");
  54 + AssertUtils.notEmpty(request.getTradeId(), "tradeId missed");
55 55 AssertUtils.notNull(request.getPipelineId(), "pipelineId missed");
56 56  
57 57 OnlinePaymentStatus paymentStatus = cashierDeskService.doPayment(request);
... ...
cashier-boss/src/main/java/com/diligrp/cashier/boss/controller/WechatPaymentController.java
... ... @@ -82,7 +82,7 @@ public class WechatPaymentController {
82 82  
83 83 try {
84 84 OnlinePayment payment = tradeAssistantService.findByPaymentId(paymentId);
85   - WechatPipeline pipeline = paymentPipelineManager.findPipelineById(payment.getPipelineId(), WechatPipeline.class);
  85 + WechatPipeline<?> pipeline = paymentPipelineManager.findPipelineById(payment.getPipelineId(), WechatPipeline.class);
86 86 if (dataVerify(request, pipeline, payload)) {
87 87 WechatNotifyResponse response = JsonUtils.fromJsonString(payload, WechatNotifyResponse.class);
88 88 OnlinePaymentResponse paymentResponse = paymentResponse(pipeline, response);
... ... @@ -101,20 +101,20 @@ public class WechatPaymentController {
101 101 }
102 102 }
103 103  
104   - /*@RequestMapping(value = "/refund/{refundId}/notify.do")
  104 + @RequestMapping(value = "/refund/{refundId}/notify.do")
105 105 public ResponseEntity<NotifyResult> refundNotify(HttpServletRequest request, @PathVariable("refundId") String refundId) {
106 106 LOG.info("Receiving wechat refund result notify for {}", refundId);
107 107 String payload = HttpUtils.httpBody(request);
108 108  
109 109 try {
110   - OnlinePayment refund = onlinePaymentService.findByRefundId(refundId);
111   - WechatPipeline pipeline = paymentPipelineManager.findPipelineById(refund.getPipelineId(), WechatPipeline.class);
  110 + OnlinePayment refund = tradeAssistantService.findByRefundId(refundId);
  111 + WechatPipeline<?> pipeline = paymentPipelineManager.findPipelineById(refund.getPipelineId(), WechatPipeline.class);
112 112  
113 113 if (dataVerify(request, pipeline, payload)) {
114 114 WechatNotifyResponse notifyResponse = JsonUtils.fromJsonString(payload, WechatNotifyResponse.class);
115 115 if (WechatConstants.REFUND_EVENT_TYPE.equals(notifyResponse.getEvent_type())) {
116 116 OnlineRefundResponse refundResponse = refundResponse(pipeline, notifyResponse);
117   - onlinePaymentService.notifyRefundResult(refundResponse);
  117 + cashierPaymentService.notifyRefundResult(refundResponse);
118 118 }
119 119 return ResponseEntity.ok(NotifyResult.success());
120 120 } else {
... ... @@ -126,9 +126,9 @@ public class WechatPaymentController {
126 126 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
127 127 .body(NotifyResult.failure("Process wechat refund result notify exception"));
128 128 }
129   - }*/
  129 + }
130 130  
131   - private OnlinePaymentResponse paymentResponse(WechatPipeline pipeline, WechatNotifyResponse notifyResponse) throws Exception {
  131 + private OnlinePaymentResponse paymentResponse(WechatPipeline<?> pipeline, WechatNotifyResponse notifyResponse) throws Exception {
132 132 WechatNotifyResponse.Resource resource = notifyResponse.getResource();
133 133 String payload = WechatSignatureUtils.decrypt(resource.getCiphertext(), resource.getNonce(),
134 134 resource.getAssociated_data(), pipeline.getClient().getWechatConfig().getApiV3Key());
... ... @@ -138,7 +138,7 @@ public class WechatPaymentController {
138 138 String payer = response.getPayer() == null ? null : response.getPayer().getSp_openid();
139 139 PaymentState paymentState = WechatStateUtils.getPaymentState(response.getTrade_state());
140 140 return new OnlinePaymentResponse(response.getOut_trade_no(), response.getTransaction_id(), OutPaymentType.WXPAY,
141   - payer, when, paymentState, response.getTrade_state_desc());
  141 + payer, when, paymentState, response.getTrade_state_desc());
142 142 } else {
143 143 DirectPaymentResponse response = JsonUtils.fromJsonString(payload, DirectPaymentResponse.class);
144 144 LocalDateTime when = DateUtils.parseDateTime(response.getSuccess_time(), WechatConstants.RFC3339_FORMAT);
... ... @@ -149,7 +149,7 @@ public class WechatPaymentController {
149 149 }
150 150 }
151 151  
152   - private OnlineRefundResponse refundResponse(WechatPipeline pipeline, WechatNotifyResponse notifyResponse) throws Exception {
  152 + private OnlineRefundResponse refundResponse(WechatPipeline<?> pipeline, WechatNotifyResponse notifyResponse) throws Exception {
153 153 WechatNotifyResponse.Resource resource = notifyResponse.getResource();
154 154 String payload = WechatSignatureUtils.decrypt(resource.getCiphertext(), resource.getNonce(),
155 155 resource.getAssociated_data(), pipeline.getClient().getWechatConfig().getApiV3Key());
... ... @@ -157,10 +157,10 @@ public class WechatPaymentController {
157 157 LocalDateTime when = DateUtils.parseDateTime(response.getSuccess_time(), WechatConstants.RFC3339_FORMAT);
158 158 PaymentState refundState = WechatStateUtils.getRefundState(response.getRefund_status());
159 159 return OnlineRefundResponse.of(response.getOut_refund_no(), response.getRefund_id(), when,
160   - refundState.getCode(), response.getRefund_status());
  160 + refundState, response.getRefund_status());
161 161 }
162 162  
163   - private boolean dataVerify(HttpServletRequest request, WechatPipeline pipeline, String payload) {
  163 + private boolean dataVerify(HttpServletRequest request, WechatPipeline<?> pipeline, String payload) {
164 164 String serialNo = request.getHeader(WechatConstants.HEADER_SERIAL_NO);
165 165 String timestamp = request.getHeader(WechatConstants.HEADER_TIMESTAMP);
166 166 String nonce = request.getHeader(WechatConstants.HEADER_NONCE);
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/WechatDirectHttpClient.java
... ... @@ -193,7 +193,7 @@ public class WechatDirectHttpClient extends WechatHttpClient {
193 193 LocalDateTime when = DateUtils.parseDateTime((String) response.get("success_time"), WechatConstants.RFC3339_FORMAT);
194 194 PaymentState state = WechatStateUtils.getRefundState((String) response.get("status"));
195 195 return OnlineRefundResponse.of((String) response.get("out_refund_no"), (String) response.get("refund_id"),
196   - when, state.getCode(), (String) response.get("status"));
  196 + when, state, (String) response.get("status"));
197 197 } else {
198 198 LOG.info("send wechat refund failed: {}", result.statusCode);
199 199 ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class);
... ... @@ -224,7 +224,7 @@ public class WechatDirectHttpClient extends WechatHttpClient {
224 224 LocalDateTime when = DateUtils.parseDateTime((String) response.get("success_time"), WechatConstants.RFC3339_FORMAT);
225 225 PaymentState state = WechatStateUtils.getRefundState((String) response.get("status"));
226 226 return OnlineRefundResponse.of((String) response.get("out_refund_no"), (String) response.get("refund_id"),
227   - when, state.getCode(), (String) response.get("user_received_account"));
  227 + when, state, (String) response.get("user_received_account"));
228 228 } else if (result.statusCode == 404) {
229 229 throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "发起微信退款查询失败: 退款单不存在");
230 230 } else {
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/WechatPartnerHttpClient.java
... ... @@ -201,7 +201,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient {
201 201 LocalDateTime when = DateUtils.parseDateTime((String) response.get("success_time"), WechatConstants.RFC3339_FORMAT);
202 202 PaymentState state = WechatStateUtils.getRefundState((String) response.get("status"));
203 203 return OnlineRefundResponse.of((String) response.get("out_refund_no"), (String) response.get("refund_id"),
204   - when, state.getCode(), (String) response.get("status"));
  204 + when, state, (String) response.get("status"));
205 205 } else {
206 206 LOG.info("send wechat payment refund failed: {}", result.statusCode);
207 207 ErrorMessage message = JsonUtils.fromJsonString(result.responseText, ErrorMessage.class);
... ... @@ -235,7 +235,7 @@ public class WechatPartnerHttpClient extends WechatHttpClient {
235 235 LocalDateTime when = DateUtils.parseDateTime((String) response.get("success_time"), WechatConstants.RFC3339_FORMAT);
236 236 PaymentState state = WechatStateUtils.getRefundState((String) response.get("status"));
237 237 return OnlineRefundResponse.of((String) response.get("out_refund_no"), (String) response.get("refund_id"),
238   - when, state.getCode(), (String) response.get("user_received_account"));
  238 + when, state, (String) response.get("user_received_account"));
239 239 } else if (result.statusCode == 404) {
240 240 throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "发起微信退款查询失败: 退款单不存在");
241 241 } else {
... ... @@ -286,8 +286,9 @@ public class WechatPartnerHttpClient extends WechatHttpClient {
286 286 amount.put("currency", "CNY");
287 287 params.put("amount", amount);
288 288 Map<String, Object> payer = new LinkedHashMap<>();
289   - // 传入微信用户在服务商APPID下的openid,如果是子商户APPID下的openid,则应该使用sub_appid
290   - payer.put("sp_openid", request.getOpenId());
  289 + // 如果是服务商APPID下的openid则使用sp_openid; 如果是子商户APPID下的openid, 则使用sub_openid
  290 +// payer.put("sp_openid", request.getOpenId());
  291 + payer.put("sub_openid", request.getOpenId());
291 292 params.put("payer", payer);
292 293 return JsonUtils.toJsonString(params);
293 294 }
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/DiliCardPipeline.java
1 1 package com.diligrp.cashier.pipeline.core;
2 2  
  3 +import com.diligrp.cashier.pipeline.Constants;
3 4 import com.diligrp.cashier.pipeline.client.CardPaymentHttpClient;
4 5 import com.diligrp.cashier.pipeline.domain.OnlinePrepayOrder;
5 6 import com.diligrp.cashier.pipeline.domain.OnlineRefundRequest;
... ... @@ -34,6 +35,8 @@ public class DiliCardPipeline extends PaymentPipeline&lt;DiliCardPipeline.CardParam
34 35 */
35 36 public CardPaymentResponse sendPaymentRequest(CardPaymentRequest request) {
36 37 try {
  38 + // 外部商户号设置为市场ID
  39 + request.put(Constants.PARAM_MCH_ID, params().outMchId);
37 40 return client.sendPaymentRequest(request);
38 41 } catch (PaymentPipelineException | IllegalArgumentException pse) {
39 42 throw pse;
... ... @@ -46,9 +49,11 @@ public class DiliCardPipeline extends PaymentPipeline&lt;DiliCardPipeline.CardParam
46 49 /**
47 50 * 查询支付订单状态
48 51 */
49   - public CardPaymentResponse queryPaymentResponse(OnlinePrepayOrder order) {
  52 + public CardPaymentResponse queryPaymentResponse(OnlinePrepayOrder request) {
50 53 try {
51   - return client.queryPaymentResponse(order);
  54 + // 外部商户号设置为市场ID
  55 + request.put(Constants.PARAM_MCH_ID, params().outMchId);
  56 + return client.queryPaymentResponse(request);
52 57 } catch (PaymentPipelineException | IllegalArgumentException pse) {
53 58 throw pse;
54 59 } catch (Exception ex) {
... ... @@ -58,17 +63,12 @@ public class DiliCardPipeline extends PaymentPipeline&lt;DiliCardPipeline.CardParam
58 63 }
59 64  
60 65 /**
61   - * 关闭预支付订单
62   - */
63   - public void closePrepayOrder(OnlinePrepayOrder request) {
64   - // 不调用远程关单接口
65   - }
66   -
67   - /**
68 66 * 退款申请
69 67 */
70 68 public OnlineRefundResponse sendRefundRequest(OnlineRefundRequest request) {
71 69 try {
  70 + // 外部商户号设置为市场ID
  71 + request.put(Constants.PARAM_MCH_ID, params().outMchId);
72 72 return client.sendRefundRequest(request);
73 73 } catch (PaymentPipelineException | IllegalArgumentException pse) {
74 74 throw pse;
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatDirectPipeline.java
1 1 package com.diligrp.cashier.pipeline.core;
2 2  
  3 +import com.diligrp.cashier.pipeline.Constants;
3 4 import com.diligrp.cashier.pipeline.client.WechatDirectHttpClient;
4 5 import com.diligrp.cashier.pipeline.client.WechatHttpClient;
  6 +import com.diligrp.cashier.pipeline.domain.*;
5 7 import com.diligrp.cashier.shared.util.AssertUtils;
6 8  
7 9 /**
... ... @@ -33,6 +35,55 @@ public class WechatDirectPipeline extends WechatPipeline&lt;WechatDirectPipeline.Di
33 35 }
34 36  
35 37 @Override
  38 + public NativePrepayResponse sendNativePrepayRequest(NativePrepayRequest request) {
  39 + // 直连模式下,外部商户号设置为微信商户号
  40 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  41 + return super.sendNativePrepayRequest(request);
  42 + }
  43 +
  44 + @Override
  45 + public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) {
  46 + // 直连模式下,外部商户号设置为微信商户号
  47 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  48 + return super.sendMiniProPrepayRequest(request);
  49 + }
  50 +
  51 + @Override
  52 + public OnlinePaymentResponse sendQrCodePaymentRequest(QrCodePaymentRequest request) {
  53 + // 直连模式下,外部商户号设置为微信商户号
  54 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  55 + return super.sendQrCodePaymentRequest(request);
  56 + }
  57 +
  58 + @Override
  59 + public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder request) {
  60 + // 直连模式下,外部商户号设置为微信商户号
  61 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  62 + return super.queryPrepayResponse(request);
  63 + }
  64 +
  65 + @Override
  66 + public void closePrepayOrder(OnlinePrepayOrder request) {
  67 + // 直连模式下,外部商户号设置为微信商户号
  68 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  69 + super.closePrepayOrder(request);
  70 + }
  71 +
  72 + @Override
  73 + public OnlineRefundResponse sendRefundRequest(OnlineRefundRequest request) {
  74 + // 直连模式下,外部商户号设置为微信商户号
  75 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  76 + return super.sendRefundRequest(request);
  77 + }
  78 +
  79 + @Override
  80 + public OnlineRefundResponse queryRefundResponse(OnlineRefundOrder request) {
  81 + // 直连模式下,外部商户号设置为微信商户号
  82 + request.put(Constants.PARAM_MCH_ID, wechatConfig.getMchId());
  83 + return super.queryRefundResponse(request);
  84 + }
  85 +
  86 + @Override
36 87 public Class<DirectWechatParams> paramClass() {
37 88 return DirectWechatParams.class;
38 89 }
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatPartnerPipeline.java
... ... @@ -42,64 +42,50 @@ public class WechatPartnerPipeline extends WechatPipeline&lt;WechatPartnerPipeline.
42 42  
43 43 @Override
44 44 public NativePrepayResponse sendNativePrepayRequest(NativePrepayRequest request) {
45   - // 业务没有传递子商户则使用默认配置
46   - if (request.getString(Constants.PARAM_MCH_ID) == null) {
47   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
48   - }
  45 + // 服务商模式下,外部商户号默认设置为特约子商户
  46 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
49 47 return super.sendNativePrepayRequest(request);
50 48 }
51 49  
52 50 @Override
53 51 public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) {
54   - // 业务没有传递子商户则使用默认配置
55   - if (request.getString(Constants.PARAM_MCH_ID) == null) {
56   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
57   - }
  52 + // 服务商模式下,外部商户号默认设置为特约子商户
  53 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
58 54 return super.sendMiniProPrepayRequest(request);
59 55 }
60 56  
61 57 @Override
62 58 public OnlinePaymentResponse sendQrCodePaymentRequest(QrCodePaymentRequest request) {
63   - // 业务没有传递子商户则使用默认配置
64   - if (request.getString(Constants.PARAM_MCH_ID) == null) {
65   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
66   - }
  59 + // 服务商模式下,外部商户号默认设置为特约子商户
  60 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
67 61 return super.sendQrCodePaymentRequest(request);
68 62 }
69 63  
70 64 @Override
71   - public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder order) {
72   - // 业务没有传递子商户则使用默认配置
73   - if (order.getString(Constants.PARAM_MCH_ID) == null) {
74   - order.put(Constants.PARAM_MCH_ID, params().getSubMchId());
75   - }
76   - return super.queryPrepayResponse(order);
  65 + public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder request) {
  66 + // 服务商模式下,外部商户号默认设置为特约子商户
  67 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
  68 + return super.queryPrepayResponse(request);
77 69 }
78 70  
79 71 @Override
80 72 public void closePrepayOrder(OnlinePrepayOrder request) {
81   - // 业务没有传递子商户则使用默认配置
82   - if (request.getString(Constants.PARAM_MCH_ID) == null) {
83   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
84   - }
  73 + // 服务商模式下,外部商户号默认设置为特约子商户
  74 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
85 75 super.closePrepayOrder(request);
86 76 }
87 77  
88 78 @Override
89 79 public OnlineRefundResponse sendRefundRequest(OnlineRefundRequest request) {
90   - // 业务没有传递子商户则使用默认配置
91   - if (request.getString(Constants.PARAM_MCH_ID) == null) {
92   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
93   - }
  80 + // 服务商模式下,外部商户号默认设置为特约子商户
  81 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
94 82 return super.sendRefundRequest(request);
95 83 }
96 84  
97 85 @Override
98 86 public OnlineRefundResponse queryRefundResponse(OnlineRefundOrder request) {
99   - // 业务没有传递子商户则使用默认配置
100   - if (request.getString(Constants.PARAM_MCH_ID) == null) {
101   - request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
102   - }
  87 + // 服务商模式下,外部商户号默认设置为特约子商户
  88 + request.put(Constants.PARAM_MCH_ID, params().getSubMchId());
103 89 return super.queryRefundResponse(request);
104 90 }
105 91  
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/domain/OnlineRefundResponse.java
1 1 package com.diligrp.cashier.pipeline.domain;
2 2  
  3 +import com.diligrp.cashier.pipeline.type.PaymentState;
  4 +
3 5 import java.time.LocalDateTime;
4 6  
5 7 /**
... ... @@ -7,25 +9,27 @@ import java.time.LocalDateTime;
7 9 */
8 10 public class OnlineRefundResponse {
9 11 // 商户退款单号
10   - private String refundId;
  12 + private final String refundId;
11 13 // 通道退款订单号
12   - private String outTradeNo;
  14 + private final String outTradeNo;
13 15 // 退款完成时间
14   - private LocalDateTime when;
  16 + private final LocalDateTime when;
15 17 // 退款状态
16   - private Integer state;
  18 + private final Integer state;
17 19 // 交易备注
18   - private String message;
  20 + private final String message;
19 21  
20 22 public static OnlineRefundResponse of(String refundId, String outTradeNo, LocalDateTime when,
21   - Integer state, String message) {
22   - OnlineRefundResponse response = new OnlineRefundResponse();
23   - response.refundId = refundId;
24   - response.outTradeNo = outTradeNo;
25   - response.when = when;
26   - response.state = state;
27   - response.message = message;
28   - return response;
  23 + PaymentState state, String message) {
  24 + return new OnlineRefundResponse(refundId, outTradeNo, when, state.getCode(), message);
  25 + }
  26 +
  27 + public OnlineRefundResponse(String refundId, String outTradeNo, LocalDateTime when, Integer state, String message) {
  28 + this.refundId = refundId;
  29 + this.outTradeNo = outTradeNo;
  30 + this.when = when;
  31 + this.state = state;
  32 + this.message = message;
29 33 }
30 34  
31 35 public String getRefundId() {
... ...
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/service/impl/WechatPaymentServiceImpl.java
... ... @@ -5,7 +5,6 @@ import com.diligrp.cashier.pipeline.core.WechatPartnerPipeline;
5 5 import com.diligrp.cashier.pipeline.core.WechatPipeline;
6 6 import com.diligrp.cashier.pipeline.domain.wechat.UploadShippingRequest;
7 7 import com.diligrp.cashier.pipeline.domain.wechat.WechatAccessToken;
8   -import com.diligrp.cashier.pipeline.domain.wechat.WechatConfig;
9 8 import com.diligrp.cashier.pipeline.service.IPaymentPipelineManager;
10 9 import com.diligrp.cashier.pipeline.service.IWechatPaymentService;
11 10 import jakarta.annotation.Resource;
... ... @@ -24,11 +23,11 @@ public class WechatPaymentServiceImpl implements IWechatPaymentService {
24 23 public String openIdByCode(Long pipelineId, String code) {
25 24 WechatPipeline<?> pipeline = paymentPipelineManager.findPipelineById(pipelineId, WechatPipeline.class);
26 25 if (pipeline instanceof WechatPartnerPipeline partnerPipeline) {
27   - // 服务商模式下subMchId和subAppId配置upay_payment_pipeline.params,对应的appSecret配置在upay_wechat_param.app_secret
  26 + // 服务商模式下使用WechatParams配置的信息获取openId
28 27 WechatPartnerPipeline.PartnerWechatParams params = partnerPipeline.params();
29   - WechatConfig config = pipeline.getClient().getWechatConfig();
30   - return pipeline.getClient().loginAuthorization(params.getSubAppId(), config.getAppSecret(), code);
  28 + return pipeline.getClient().loginAuthorization(params.getSubAppId(), params.getAppSecret(), code);
31 29 } else {
  30 + // 直连模式直接使用WebConfig配置的信息获取openId
32 31 return pipeline.getClient().loginAuthorization(code);
33 32 }
34 33 }
... ...
cashier-trade/src/main/java/com/diligrp/cashier/trade/domain/CashierPayment.java
... ... @@ -7,8 +7,6 @@ public class CashierPayment {
7 7 private String tradeId;
8 8 // 选择的支付通道
9 9 private Long pipelineId;
10   - // 用户标识
11   - private Long userId;
12 10 // 支付参数
13 11 private Map<String, Object> params;
14 12  
... ... @@ -28,14 +26,6 @@ public class CashierPayment {
28 26 this.pipelineId = pipelineId;
29 27 }
30 28  
31   - public Long getUserId() {
32   - return userId;
33   - }
34   -
35   - public void setUserId(Long userId) {
36   - this.userId = userId;
37   - }
38   -
39 29 public Map<String, Object> getParams() {
40 30 return params;
41 31 }
... ...
cashier-trade/src/main/java/com/diligrp/cashier/trade/service/impl/CashierPaymentServiceImpl.java
... ... @@ -148,8 +148,7 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService {
148 148 .state(response.getState()).version(0).createdTime(now).modifiedTime(now).build();
149 149 onlinePaymentDao.insertOnlinePayment(payment);
150 150 return response;
151   - }
152   - if (pipeline instanceof DiliCardPipeline cardPipeline) { // 园区卡支付通道
  151 + } else if (pipeline instanceof DiliCardPipeline cardPipeline) { // 园区卡支付通道
153 152 // 园区卡支付通道: 所有的收银台类型使用的是同一种园区卡支付流程
154 153 CardPaymentRequest request = new CardPaymentConverter(trade, paymentId, now).convert(cashierPayment);
155 154 // 修改支付状态为支付中,防止重复支付
... ... @@ -157,13 +156,13 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService {
157 156 // 支付成功插入支付记录并修改交易订单状态,失败可以继续支付
158 157 if (response.getState() == PaymentState.SUCCESS) {
159 158 // 园区卡支付通道outMchId为市场ID
160   - String outMchId = cardPipeline.params().getOutMchId();
  159 + String outMchId = request.getString(com.diligrp.cashier.pipeline.Constants.PARAM_MCH_ID);
161 160 OnlinePayment payment = OnlinePayment.builder().outMchId(outMchId).tradeId(trade.getTradeId())
162 161 .type(TradeType.TRADE).paymentId(paymentId).channelId(cardPipeline.supportedChannel())
163 162 .payType(PaymentType.DIRECT).pipelineId(cardPipeline.pipelineId()).goods(trade.getGoods())
164 163 .amount(trade.getAmount()).payerId(response.getPayerId())
165 164 .finishTime(response.getWhen()).outTradeNo(response.getOutTradeNo())
166   - .outPayType(OutPaymentType.DILICARD).state(response.getState()).notifyUrl(trade.getNotifyUrl())
  165 + .outPayType(response.getOutPayType()).state(response.getState()).notifyUrl(trade.getNotifyUrl())
167 166 .description(response.getMessage()).version(0).createdTime(now).modifiedTime(now).build();
168 167 onlinePaymentDao.insertOnlinePayment(payment);
169 168  
... ... @@ -355,11 +354,19 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService {
355 354 LocalDateTime now = LocalDateTime.now().withNano(0);
356 355 KeyGenerator refundIdKey = snowflakeKeyManager.getKeyGenerator(SnowflakeKey.PAYMENT_ID);
357 356 String refundId = refundIdKey.nextId();
358   - OnlinePipeline<?> pipeline = paymentPipelineManager.findPipelineById(payment.getPipelineId(), OnlinePipeline.class);
  357 + PaymentPipeline<?> pipeline = paymentPipelineManager.findPipelineById(payment.getPipelineId(), PaymentPipeline.class);
359 358 OnlineRefundRequest refundRequest = OnlineRefundRequest.of(refundId, payment.getPaymentId(), payment.getOutTradeNo(),
360 359 trade.getMaxAmount(), request.getAmount(), request.getDescription(), now);
361   - refundRequest.attach(com.diligrp.cashier.pipeline.Constants.PARAM_MCH_ID, payment.getOutMchId()); // 用于微信服务商模式下,微信子商户信息
362   - OnlineRefundResponse response = pipeline.sendRefundRequest(refundRequest);
  360 + // 微信支付外部商户号为微信商户号或特约子商户; 园区卡支付外部商户号为市场ID
  361 + refundRequest.put(com.diligrp.cashier.pipeline.Constants.PARAM_MCH_ID, payment.getOutMchId());
  362 + OnlineRefundResponse response;
  363 + if (pipeline instanceof OnlinePipeline<?> onlinePipeline) {
  364 + response = onlinePipeline.sendRefundRequest(refundRequest);
  365 + } else if (pipeline instanceof DiliCardPipeline cardPipeline) {
  366 + response = cardPipeline.sendRefundRequest(refundRequest);
  367 + } else {
  368 + throw new TradePaymentException(ErrorCode.OPERATION_NOT_ALLOWED, "不支持的支付通道");
  369 + }
363 370  
364 371 OnlinePayment refund = OnlinePayment.builder().outMchId(payment.getOutMchId()).tradeId(payment.getTradeId())
365 372 .type(TradeType.REFUND).paymentId(refundId).channelId(payment.getChannelId())
... ...
cashier-trade/src/main/resources/com/diligrp/cashier/dao/mapper/IOnlinePaymentDao.xml
... ... @@ -33,7 +33,7 @@
33 33 state, notify_url, description, version, created_time, modified_time)
34 34 VALUES
35 35 (#{outMchId}, #{tradeId}, #{type}, #{paymentId}, #{channelId}, #{payType}, #{pipelineId},
36   - #{goods}, #{amount}, #{objectId}, #{payerId}, #{finishTime}, #{outTradeNo}, #{outPayType}
  36 + #{goods}, #{amount}, #{objectId}, #{payerId}, #{finishTime}, #{outTradeNo}, #{outPayType},
37 37 #{state}, #{notifyUrl}, #{description}, #{version}, #{createdTime}, #{modifiedTime})
38 38 </insert>
39 39  
... ...