Commit 761c27c102de84b31496937d020a9c656304a4b4
1 parent
37d8d3a5
upgrade after testing
Showing
10 changed files
with
173 additions
and
32 deletions
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/client/WechatHttpClient.java
| @@ -67,7 +67,7 @@ public class WechatHttpClient extends ServiceEndpointSupport { | @@ -67,7 +67,7 @@ public class WechatHttpClient extends ServiceEndpointSupport { | ||
| 67 | /** | 67 | /** |
| 68 | * 查询微信预支付订单状态 | 68 | * 查询微信预支付订单状态 |
| 69 | */ | 69 | */ |
| 70 | - public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder order) throws Exception { | 70 | + public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder request) throws Exception { |
| 71 | throw new PaymentPipelineException(ErrorCode.OPERATION_NOT_ALLOWED, "支付通道不支持此操作"); | 71 | throw new PaymentPipelineException(ErrorCode.OPERATION_NOT_ALLOWED, "支付通道不支持此操作"); |
| 72 | } | 72 | } |
| 73 | 73 |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatDirectPipeline.java
| @@ -6,8 +6,11 @@ import com.diligrp.cashier.shared.util.AssertUtils; | @@ -6,8 +6,11 @@ import com.diligrp.cashier.shared.util.AssertUtils; | ||
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * 微信支付通道抽象模型-直联模式 | 8 | * 微信支付通道抽象模型-直联模式 |
| 9 | + * | ||
| 10 | + * 直连模式upay_payment_pipeline.params只需配置notifyUrl | ||
| 11 | + * upay_wechat_param需配置商户API接口所需配置信息 | ||
| 9 | */ | 12 | */ |
| 10 | -public class WechatDirectPipeline extends WechatPipeline { | 13 | +public class WechatDirectPipeline extends WechatPipeline<WechatDirectPipeline.DirectWechatParams> { |
| 11 | private final ScanTimeStrategy strategy; | 14 | private final ScanTimeStrategy strategy; |
| 12 | 15 | ||
| 13 | // 直联模式下的微信客户端 | 16 | // 直联模式下的微信客户端 |
| @@ -30,6 +33,17 @@ public class WechatDirectPipeline extends WechatPipeline { | @@ -30,6 +33,17 @@ public class WechatDirectPipeline extends WechatPipeline { | ||
| 30 | } | 33 | } |
| 31 | 34 | ||
| 32 | @Override | 35 | @Override |
| 36 | + public Class<DirectWechatParams> paramClass() { | ||
| 37 | + return DirectWechatParams.class; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static class DirectWechatParams extends WechatParams { | ||
| 41 | + public DirectWechatParams(String params) { | ||
| 42 | + super(params); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 33 | public WechatHttpClient getClient() { | 47 | public WechatHttpClient getClient() { |
| 34 | AssertUtils.notNull(client, "微信支付通道客户端未配置"); | 48 | AssertUtils.notNull(client, "微信支付通道客户端未配置"); |
| 35 | return client; | 49 | return client; |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatPartnerPipeline.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.WechatHttpClient; | 4 | import com.diligrp.cashier.pipeline.client.WechatHttpClient; |
| 4 | import com.diligrp.cashier.pipeline.client.WechatPartnerHttpClient; | 5 | import com.diligrp.cashier.pipeline.client.WechatPartnerHttpClient; |
| 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 | /** |
| 8 | * 微信支付通道抽象模型-服务商模式 | 10 | * 微信支付通道抽象模型-服务商模式 |
| 11 | + * | ||
| 12 | + * 服务商模式需要额外配置subMchId和subAppId, subMchId可以由业务系统传递,否则使用通道配置的subMchId | ||
| 13 | + * upay_payment_pipeline.params需配置subMchId, subAppId, appSecret和notifyUrl | ||
| 14 | + * upay_wechat_param需配置服务商API接口所需配置信息 | ||
| 9 | */ | 15 | */ |
| 10 | -public class WechatPartnerPipeline extends WechatPipeline { | 16 | +public class WechatPartnerPipeline extends WechatPipeline<WechatPartnerPipeline.PartnerWechatParams> { |
| 11 | 17 | ||
| 12 | private final ScanTimeStrategy strategy; | 18 | private final ScanTimeStrategy strategy; |
| 13 | 19 | ||
| @@ -16,6 +22,10 @@ public class WechatPartnerPipeline extends WechatPipeline { | @@ -16,6 +22,10 @@ public class WechatPartnerPipeline extends WechatPipeline { | ||
| 16 | 22 | ||
| 17 | public WechatPartnerPipeline(long mchId, long pipelineId, String name, String uri, String params) throws Exception { | 23 | public WechatPartnerPipeline(long mchId, long pipelineId, String name, String uri, String params) throws Exception { |
| 18 | super(mchId, pipelineId, name, uri, params); | 24 | super(mchId, pipelineId, name, uri, params); |
| 25 | + PartnerWechatParams config = params(); | ||
| 26 | + AssertUtils.notEmpty(config.getSubMchId(), "微信支付缺少参数配置: subMchId"); | ||
| 27 | + AssertUtils.notEmpty(config.getSubAppId(), "微信支付缺少参数配置: subAppId"); | ||
| 28 | + AssertUtils.notEmpty(config.getAppSecret(), "微信支付缺少参数配置: appSecret"); | ||
| 19 | this.strategy = new DefaultTimeStrategy(); | 29 | this.strategy = new DefaultTimeStrategy(); |
| 20 | } | 30 | } |
| 21 | 31 | ||
| @@ -31,6 +41,111 @@ public class WechatPartnerPipeline extends WechatPipeline { | @@ -31,6 +41,111 @@ public class WechatPartnerPipeline extends WechatPipeline { | ||
| 31 | } | 41 | } |
| 32 | 42 | ||
| 33 | @Override | 43 | @Override |
| 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 | + } | ||
| 49 | + return super.sendNativePrepayRequest(request); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + 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 | + } | ||
| 58 | + return super.sendMiniProPrepayRequest(request); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + 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 | + } | ||
| 67 | + return super.sendQrCodePaymentRequest(request); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @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); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + 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 | + } | ||
| 85 | + super.closePrepayOrder(request); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + 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 | + } | ||
| 94 | + return super.sendRefundRequest(request); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + 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 | + } | ||
| 103 | + return super.queryRefundResponse(request); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public Class<PartnerWechatParams> paramClass() { | ||
| 108 | + return PartnerWechatParams.class; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public static class PartnerWechatParams extends WechatParams { | ||
| 112 | + // 服务商模式下,子商户号 | ||
| 113 | + private String subMchId; | ||
| 114 | + // 服务商模式下,subAppId | ||
| 115 | + private String subAppId; | ||
| 116 | + // subAppId对应的appSecret | ||
| 117 | + private String appSecret; | ||
| 118 | + | ||
| 119 | + public PartnerWechatParams(String params) { | ||
| 120 | + super(params); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + public String getSubMchId() { | ||
| 124 | + return subMchId; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public void setSubMchId(String subMchId) { | ||
| 128 | + this.subMchId = subMchId; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public String getSubAppId() { | ||
| 132 | + return subAppId; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + public void setSubAppId(String subAppId) { | ||
| 136 | + this.subAppId = subAppId; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public String getAppSecret() { | ||
| 140 | + return appSecret; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public void setAppSecret(String appSecret) { | ||
| 144 | + this.appSecret = appSecret; | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 34 | public WechatHttpClient getClient() { | 149 | public WechatHttpClient getClient() { |
| 35 | AssertUtils.notNull(client, "微信支付通道客户端未配置"); | 150 | AssertUtils.notNull(client, "微信支付通道客户端未配置"); |
| 36 | return client; | 151 | return client; |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/core/WechatPipeline.java
| @@ -23,7 +23,7 @@ import java.security.PrivateKey; | @@ -23,7 +23,7 @@ import java.security.PrivateKey; | ||
| 23 | /** | 23 | /** |
| 24 | * 微信支付通道抽象模型 | 24 | * 微信支付通道抽象模型 |
| 25 | */ | 25 | */ |
| 26 | -public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.WechatParams> { | 26 | +public abstract class WechatPipeline<T extends WechatPipeline.WechatParams> extends OnlinePipeline<T> { |
| 27 | 27 | ||
| 28 | private static final Logger LOG = LoggerFactory.getLogger(WechatPipeline.class); | 28 | private static final Logger LOG = LoggerFactory.getLogger(WechatPipeline.class); |
| 29 | 29 | ||
| @@ -33,7 +33,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | @@ -33,7 +33,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | ||
| 33 | public WechatPipeline(long mchId, long pipelineId, String name, String uri, String params) throws Exception { | 33 | public WechatPipeline(long mchId, long pipelineId, String name, String uri, String params) throws Exception { |
| 34 | super(mchId, pipelineId, name, uri, params); | 34 | super(mchId, pipelineId, name, uri, params); |
| 35 | WechatParams config = params(); | 35 | WechatParams config = params(); |
| 36 | - AssertUtils.notEmpty(config.notifyUri, String.format("微信支付缺少参数配置: notifyBaseUri")); | 36 | + AssertUtils.notEmpty(config.getNotifyUrl(), "微信支付缺少参数配置: notifyUrl"); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| @@ -86,7 +86,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | @@ -86,7 +86,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | ||
| 86 | @Override | 86 | @Override |
| 87 | public NativePrepayResponse sendNativePrepayRequest(NativePrepayRequest request) { | 87 | public NativePrepayResponse sendNativePrepayRequest(NativePrepayRequest request) { |
| 88 | try { | 88 | try { |
| 89 | - String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params().notifyUri, request.getPaymentId()); | 89 | + String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params().getNotifyUrl(), request.getPaymentId()); |
| 90 | return getClient().sendNativePrepayRequest(request, notifyUri); | 90 | return getClient().sendNativePrepayRequest(request, notifyUri); |
| 91 | } catch (PaymentPipelineException | IllegalArgumentException pse) { | 91 | } catch (PaymentPipelineException | IllegalArgumentException pse) { |
| 92 | throw pse; | 92 | throw pse; |
| @@ -101,7 +101,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | @@ -101,7 +101,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | ||
| 101 | */ | 101 | */ |
| 102 | public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) { | 102 | public MiniProPrepayResponse sendMiniProPrepayRequest(MiniProPrepayRequest request) { |
| 103 | try { | 103 | try { |
| 104 | - String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params().notifyUri, request.getPaymentId()); | 104 | + String notifyUri = String.format(Constants.WECHAT_PAYMENT_NOTIFY_URI, params().getNotifyUrl(), request.getPaymentId()); |
| 105 | String prepayId = getClient().sendMiniProPrepayRequest(request, notifyUri); | 105 | String prepayId = getClient().sendMiniProPrepayRequest(request, notifyUri); |
| 106 | 106 | ||
| 107 | String timeStamp = String.valueOf(System.currentTimeMillis() / 1000); | 107 | String timeStamp = String.valueOf(System.currentTimeMillis() / 1000); |
| @@ -131,9 +131,9 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | @@ -131,9 +131,9 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | ||
| 131 | /** | 131 | /** |
| 132 | * 查询预支付订单状态 | 132 | * 查询预支付订单状态 |
| 133 | */ | 133 | */ |
| 134 | - public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder order) { | 134 | + public OnlinePaymentResponse queryPrepayResponse(OnlinePrepayOrder request) { |
| 135 | try { | 135 | try { |
| 136 | - return getClient().queryPrepayResponse(order); | 136 | + return getClient().queryPrepayResponse(request); |
| 137 | } catch (PaymentPipelineException | IllegalArgumentException pse) { | 137 | } catch (PaymentPipelineException | IllegalArgumentException pse) { |
| 138 | throw pse; | 138 | throw pse; |
| 139 | } catch (Exception ex) { | 139 | } catch (Exception ex) { |
| @@ -161,7 +161,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | @@ -161,7 +161,7 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | ||
| 161 | */ | 161 | */ |
| 162 | public OnlineRefundResponse sendRefundRequest(OnlineRefundRequest request) { | 162 | public OnlineRefundResponse sendRefundRequest(OnlineRefundRequest request) { |
| 163 | try { | 163 | try { |
| 164 | - String notifyUri = String.format(Constants.WECHAT_REFUND_NOTIFY_URI, params().notifyUri, request.getRefundId()); | 164 | + String notifyUri = String.format(Constants.WECHAT_REFUND_NOTIFY_URI, params().getNotifyUrl(), request.getRefundId()); |
| 165 | return getClient().sendRefundRequest(request, notifyUri); | 165 | return getClient().sendRefundRequest(request, notifyUri); |
| 166 | } catch (PaymentPipelineException | IllegalArgumentException pse) { | 166 | } catch (PaymentPipelineException | IllegalArgumentException pse) { |
| 167 | throw pse; | 167 | throw pse; |
| @@ -192,25 +192,21 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | @@ -192,25 +192,21 @@ public abstract class WechatPipeline extends OnlinePipeline<WechatPipeline.Wecha | ||
| 192 | return ChannelType.WXPAY; | 192 | return ChannelType.WXPAY; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | - @Override | ||
| 196 | - public Class<WechatParams> paramClass() { | ||
| 197 | - return WechatParams.class; | ||
| 198 | - } | 195 | + public static abstract class WechatParams extends PipelineParams { |
| 199 | 196 | ||
| 200 | - public static class WechatParams extends PipelineParams { | ||
| 201 | // 微信支付通知base地址,如: https://gateway.diligrp.com/pay-service | 197 | // 微信支付通知base地址,如: https://gateway.diligrp.com/pay-service |
| 202 | - private String notifyUri; | 198 | + private String notifyUrl; |
| 203 | 199 | ||
| 204 | public WechatParams(String params) { | 200 | public WechatParams(String params) { |
| 205 | super(params); | 201 | super(params); |
| 206 | } | 202 | } |
| 207 | 203 | ||
| 208 | - public String getNotifyUri() { | ||
| 209 | - return notifyUri; | 204 | + public String getNotifyUrl() { |
| 205 | + return notifyUrl; | ||
| 210 | } | 206 | } |
| 211 | 207 | ||
| 212 | - public void setNotifyUri(String notifyUri) { | ||
| 213 | - this.notifyUri = notifyUri; | 208 | + public void setNotifyUrl(String notifyUrl) { |
| 209 | + this.notifyUrl = notifyUrl; | ||
| 214 | } | 210 | } |
| 215 | } | 211 | } |
| 216 | } | 212 | } |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/service/impl/PaymentPipelineManagerImpl.java
| @@ -39,13 +39,13 @@ public class PaymentPipelineManagerImpl extends LifeCycle implements IPaymentPip | @@ -39,13 +39,13 @@ public class PaymentPipelineManagerImpl extends LifeCycle implements IPaymentPip | ||
| 39 | if (paramOpt.isPresent()) { | 39 | if (paramOpt.isPresent()) { |
| 40 | WechatParam param = paramOpt.get(); | 40 | WechatParam param = paramOpt.get(); |
| 41 | if (WechatPipelineType.DIRECT.equalTo(param.getType())) { | 41 | if (WechatPipelineType.DIRECT.equalTo(param.getType())) { |
| 42 | - WechatPipeline paymentPipeline = new WechatDirectPipeline(pipeline.getMchId(), pipeline.getPipelineId(), | 42 | + WechatPipeline<?> paymentPipeline = new WechatDirectPipeline(pipeline.getMchId(), pipeline.getPipelineId(), |
| 43 | pipeline.getName(), pipeline.getUri(), pipeline.getParam()); | 43 | pipeline.getName(), pipeline.getUri(), pipeline.getParam()); |
| 44 | paymentPipeline.configure(param.getMchId(), param.getAppId(), param.getAppSecret(), param.getSerialNo(), | 44 | paymentPipeline.configure(param.getMchId(), param.getAppId(), param.getAppSecret(), param.getSerialNo(), |
| 45 | param.getPrivateKey(), param.getWechatSerialNo(), param.getWechatPublicKey(), param.getApiV3Key()); | 45 | param.getPrivateKey(), param.getWechatSerialNo(), param.getWechatPublicKey(), param.getApiV3Key()); |
| 46 | registerPaymentPipeline(paymentPipeline); | 46 | registerPaymentPipeline(paymentPipeline); |
| 47 | } else if (WechatPipelineType.PARTNER.equalTo(param.getType())) { | 47 | } else if (WechatPipelineType.PARTNER.equalTo(param.getType())) { |
| 48 | - WechatPipeline paymentPipeline = new WechatPartnerPipeline(pipeline.getMchId(), pipeline.getPipelineId(), | 48 | + WechatPipeline<?> paymentPipeline = new WechatPartnerPipeline(pipeline.getMchId(), pipeline.getPipelineId(), |
| 49 | pipeline.getName(), pipeline.getUri(), pipeline.getParam()); | 49 | pipeline.getName(), pipeline.getUri(), pipeline.getParam()); |
| 50 | paymentPipeline.configure(param.getMchId(), param.getAppId(), param.getAppSecret(), param.getSerialNo(), | 50 | paymentPipeline.configure(param.getMchId(), param.getAppId(), param.getAppSecret(), param.getSerialNo(), |
| 51 | param.getPrivateKey(), param.getWechatSerialNo(), param.getWechatPublicKey(), param.getApiV3Key()); | 51 | param.getPrivateKey(), param.getWechatSerialNo(), param.getWechatPublicKey(), param.getApiV3Key()); |
| @@ -82,7 +82,7 @@ public class PaymentPipelineManagerImpl extends LifeCycle implements IPaymentPip | @@ -82,7 +82,7 @@ public class PaymentPipelineManagerImpl extends LifeCycle implements IPaymentPip | ||
| 82 | if (allPipelines.size() > 1) { | 82 | if (allPipelines.size() > 1) { |
| 83 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "该商户未配置支付路由"); | 83 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "该商户未配置支付路由"); |
| 84 | } | 84 | } |
| 85 | - return allPipelines.get(0); | 85 | + return allPipelines.getFirst(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | @Override | 88 | @Override |
| @@ -95,7 +95,7 @@ public class PaymentPipelineManagerImpl extends LifeCycle implements IPaymentPip | @@ -95,7 +95,7 @@ public class PaymentPipelineManagerImpl extends LifeCycle implements IPaymentPip | ||
| 95 | if (allPipelines.size() > 1) { | 95 | if (allPipelines.size() > 1) { |
| 96 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "该商户未配置支付路由"); | 96 | throw new PaymentPipelineException(ErrorCode.OBJECT_NOT_FOUND, "该商户未配置支付路由"); |
| 97 | } | 97 | } |
| 98 | - return allPipelines.get(0); | 98 | + return allPipelines.getFirst(); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | @Override | 101 | @Override |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/service/impl/WechatPaymentServiceImpl.java
| @@ -5,6 +5,7 @@ import com.diligrp.cashier.pipeline.core.WechatPartnerPipeline; | @@ -5,6 +5,7 @@ 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; | ||
| 8 | import com.diligrp.cashier.pipeline.service.IPaymentPipelineManager; | 9 | import com.diligrp.cashier.pipeline.service.IPaymentPipelineManager; |
| 9 | import com.diligrp.cashier.pipeline.service.IWechatPaymentService; | 10 | import com.diligrp.cashier.pipeline.service.IWechatPaymentService; |
| 10 | import jakarta.annotation.Resource; | 11 | import jakarta.annotation.Resource; |
| @@ -21,8 +22,15 @@ public class WechatPaymentServiceImpl implements IWechatPaymentService { | @@ -21,8 +22,15 @@ public class WechatPaymentServiceImpl implements IWechatPaymentService { | ||
| 21 | */ | 22 | */ |
| 22 | @Override | 23 | @Override |
| 23 | public String openIdByCode(Long pipelineId, String code) { | 24 | public String openIdByCode(Long pipelineId, String code) { |
| 24 | - WechatPipeline pipeline = paymentPipelineManager.findPipelineById(pipelineId, WechatPipeline.class); | ||
| 25 | - return pipeline.getClient().loginAuthorization(code); | 25 | + WechatPipeline<?> pipeline = paymentPipelineManager.findPipelineById(pipelineId, WechatPipeline.class); |
| 26 | + if (pipeline instanceof WechatPartnerPipeline partnerPipeline) { | ||
| 27 | + // 服务商模式下subMchId和subAppId配置upay_payment_pipeline.params,对应的appSecret配置在upay_wechat_param.app_secret | ||
| 28 | + WechatPartnerPipeline.PartnerWechatParams params = partnerPipeline.params(); | ||
| 29 | + WechatConfig config = pipeline.getClient().getWechatConfig(); | ||
| 30 | + return pipeline.getClient().loginAuthorization(params.getSubAppId(), config.getAppSecret(), code); | ||
| 31 | + } else { | ||
| 32 | + return pipeline.getClient().loginAuthorization(code); | ||
| 33 | + } | ||
| 26 | } | 34 | } |
| 27 | 35 | ||
| 28 | /** | 36 | /** |
cashier-pipeline/src/main/java/com/diligrp/cashier/pipeline/type/ChannelType.java
cashier-shared/src/main/java/com/diligrp/cashier/shared/spi/domain/RefundResultBO.java
| @@ -7,7 +7,7 @@ public class RefundResultBO { | @@ -7,7 +7,7 @@ public class RefundResultBO { | ||
| 7 | private final String refundId; | 7 | private final String refundId; |
| 8 | // 原支付ID | 8 | // 原支付ID |
| 9 | private final String tradeId; | 9 | private final String tradeId; |
| 10 | - // 支付状态 | 10 | + // 退款状态 |
| 11 | private final Integer state; | 11 | private final Integer state; |
| 12 | // 发生时间 | 12 | // 发生时间 |
| 13 | private final LocalDateTime when; | 13 | private final LocalDateTime when; |
cashier-trade/src/main/java/com/diligrp/cashier/trade/service/impl/CashierPaymentServiceImpl.java
| @@ -278,7 +278,6 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService { | @@ -278,7 +278,6 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService { | ||
| 278 | 278 | ||
| 279 | @Override | 279 | @Override |
| 280 | public OnlinePaymentResult queryPaymentState(String paymentId, String mode) { | 280 | public OnlinePaymentResult queryPaymentState(String paymentId, String mode) { |
| 281 | - // TODO: 支付成功后返回支付成功的页面地址 | ||
| 282 | OnlinePayment payment = tradeAssistantService.findByPaymentId(paymentId); | 281 | OnlinePayment payment = tradeAssistantService.findByPaymentId(paymentId); |
| 283 | TradeOrder trade = tradeAssistantService.findByTradeId(payment.getTradeId()); | 282 | TradeOrder trade = tradeAssistantService.findByTradeId(payment.getTradeId()); |
| 284 | 283 | ||
| @@ -422,7 +421,7 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService { | @@ -422,7 +421,7 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService { | ||
| 422 | LOG.debug("Query online refund order[{}-{}] state...", refundId, refund.getState()); | 421 | LOG.debug("Query online refund order[{}-{}] state...", refundId, refund.getState()); |
| 423 | // 微信支付通知较为及时和安全,非特殊情况可使用offline模式;一些本地状态与微信状态不一致的"异常订单"可使用online模式同步状态 | 422 | // 微信支付通知较为及时和安全,非特殊情况可使用offline模式;一些本地状态与微信状态不一致的"异常订单"可使用online模式同步状态 |
| 424 | if (!PaymentState.isFinished(refund.getState()) && "online".equalsIgnoreCase(mode)) { | 423 | if (!PaymentState.isFinished(refund.getState()) && "online".equalsIgnoreCase(mode)) { |
| 425 | - WechatPipeline pipeline = paymentPipelineManager.findPipelineById(refund.getPipelineId(), WechatPipeline.class); | 424 | + WechatPipeline<?> pipeline = paymentPipelineManager.findPipelineById(refund.getPipelineId(), WechatPipeline.class); |
| 426 | OnlineRefundOrder order = new OnlineRefundOrder(refundId, refund.getOutTradeNo()); | 425 | OnlineRefundOrder order = new OnlineRefundOrder(refundId, refund.getOutTradeNo()); |
| 427 | // 用于微信服务商模式下,微信子商户信息 | 426 | // 用于微信服务商模式下,微信子商户信息 |
| 428 | order.attach(com.diligrp.cashier.pipeline.Constants.PARAM_MCH_ID, refund.getOutMchId()); | 427 | order.attach(com.diligrp.cashier.pipeline.Constants.PARAM_MCH_ID, refund.getOutMchId()); |
scripts/cashier-data.sql
| 1 | -INSERT INTO upay_merchant(mch_id, name, param, address, linkman, telephone, state, created_time, modified_time) | ||
| 2 | -VALUES (1001, '安徽省中瑞农副产品有限责任公司', '{"cashier":{"miniProUrl": "https://cashier.pay.gszdtop.com/merchant/mp"}}', '安徽省濉溪县南环路中瑞农产品批发市场', '赵静', '0561-6863420', 1, now(), now()); | ||
| 3 | \ No newline at end of file | 1 | \ No newline at end of file |
| 2 | +INSERT INTO dili_cashier.upay_merchant(mch_id, name, param, address, linkman, telephone, state, created_time, modified_time) | ||
| 3 | +VALUES (1001, '安徽省中瑞农副产品有限责任公司', '{"cashier":{"miniProUrl": "https://cashier.pay.gszdtop.com/merchant/mp"}}', '安徽省濉溪县南环路中瑞农产品批发市场', '赵静', '0561-6863420', 1, now(), now()); | ||
| 4 | + | ||
| 5 | +-- 根据环境配置不同的回调地址 | ||
| 6 | +INSERT INTO `dili_cashier`.upay_payment_pipeline(mch_id, pipeline_id, channel_id, type, name, uri, param, state, created_time, modified_time) | ||
| 7 | +VALUES (1001, 10011, 10, 10, '中瑞微信服务商支付通道', 'https://api.mch.weixin.qq.com', '{"subMchId":"1679224186", "subAppId":"wxad27b69b888b6dc9", "appSecret":"9c254c0ab932b3c30292a05679a688f7", "notifyUrl": "https://cashier.test.gszdtop.com"}', 1, now(), now()); | ||
| 8 | +INSERT INTO `dili_cashier`.upay_wechat_param(pipeline_id, mch_id, app_id, app_secret, serial_no, private_key, wechat_serial_no, wechat_public_key, api_v3_key, type, created_time) | ||
| 9 | +VALUES(10011, '1679223106', 'wxca99d56a6ab15f29', '9c254c0ab932b3c30292a05679a688f7', '60C2877836D1D618D2E40186995BB00299D92F44','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', 'RSfFvEBBQiHz8GZyDcP2eSUlZJgKjdxk', 2, now()); | ||
| 10 | +-- 根据环境配置不同的uri | ||
| 11 | +INSERT INTO `dili_cashier`.upay_payment_pipeline(mch_id, pipeline_id, channel_id, type, name, uri, param, state, created_time, modified_time) | ||
| 12 | +VALUES (1001, 10012, 19, 2, '中瑞园区卡支付通道', 'http://10.28.3.9:8081', null, 1, now(), now()); |