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