From 49f8ff022fbef5a3b76de7422a513d1078c6af19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AA=E5=AF=92?= <2533659732@qq.com> Date: Wed, 18 Oct 2023 15:03:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8C=BB=E8=B7=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=BE=AE=E4=BF=A1=E5=95=86=E6=88=B7=E5=8F=B7=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=85=8D=E7=BD=AE=E5=92=8C=E4=B8=9A=E5=8A=A1=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 8 - .../resources/yiluyoupin_apiclient_key.pem | 28 --- .../config/YlypWeChatPaymentConfig.java | 27 -- .../config/YlypWeChatPaymentUtilConfig.java | 97 -------- .../WeChatPaymentController.java | 3 +- .../WeChatPaymentService.java | 20 -- .../WeChatRefundService.java | 6 +- .../impl/WeChatPayNotifyServiceImpl.java | 50 +--- .../impl/WeChatPaymentServiceImpl.java | 234 ++---------------- .../impl/WeChatRefundServiceImpl.java | 73 +----- .../quartz/service/RefundInfoTaskService.java | 4 +- .../impl/PaymentInfoTaskServiceImpl.java | 15 +- .../impl/RefundInfoTaskServiceImpl.java | 7 +- .../xinelu/quartz/task/RefundInfoTask.java | 4 +- 14 files changed, 48 insertions(+), 528 deletions(-) delete mode 100644 xinelu-admin/src/main/resources/yiluyoupin_apiclient_key.pem delete mode 100644 xinelu-common/src/main/java/com/xinelu/common/config/YlypWeChatPaymentConfig.java delete mode 100644 xinelu-framework/src/main/java/com/xinelu/framework/config/YlypWeChatPaymentUtilConfig.java diff --git a/xinelu-admin/src/main/resources/application.yml b/xinelu-admin/src/main/resources/application.yml index 54b1ee5..fb063b6 100644 --- a/xinelu-admin/src/main/resources/application.yml +++ b/xinelu-admin/src/main/resources/application.yml @@ -299,14 +299,6 @@ xyl-we-chat-config: xyl-payment-key: Xyl699003981qazVFR4xsw23edcASDFG xyl-wechat-notify-url: https://1608.xinelu.cn -# 医路优品微信商户号配置参数 -ylyp-we-chat-config: - ylyp-mch-id: 1633506981 - ylyp-mch-serial-no: 7840E8CE4B9B1F0F19D5DD2AB7BC159E007F9D90 - ylyp-private-key-path: yiluyoupin_apiclient_key.pem - ylyp-payment-key: Xyk699003981qazxsw23edcvfr4bgt56 - ylyp-we-chat-notify-url: https://1608.xinelu.cn - # 微信支付接口地址,包含小程序和App支付接口地址 we-chat-payment-url-config: jsapi-palce-order-url: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi diff --git a/xinelu-admin/src/main/resources/yiluyoupin_apiclient_key.pem b/xinelu-admin/src/main/resources/yiluyoupin_apiclient_key.pem deleted file mode 100644 index cf65f27..0000000 --- a/xinelu-admin/src/main/resources/yiluyoupin_apiclient_key.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC3rkr2Mp+Xb31y -xfTOJPSmjQkG5/Eko6cyJcb8e6fGrrtsPVM9kExpVIor61oWTS1gyKYLwCQ92xmh -qjKtazzd6KvqjKdxFknxxH9R1L+n7LnSEfK2KNaxIL17h2vdXOJatuinX0+7A9Ct -5ZnKb5O5HVctQH0xCca6C6yyuF0q11BFquKyGPVwhqVwQnt+qIeQ/VCKFD5AYf1r -ebkaHwKCg0rbzPFWeZfVI0z3j6M71DLxdIHV40xDn31ygQYlBeuTOUxFvKnri8m+ -BalcSUhocS9VAIyuPyDXCAdujm3hKz/WgqVtvgB3OOiIeGVppbgDlW+JWgR7lizM -TzMYfhjPAgMBAAECggEBAJbB6SjVOAO1MEOpklo4Hs0saMJQUK3/3FTeiMnmPDho -ZdBbLR0UeILjLl0J2HEBe0M6rH5sf9J9KDZ2WQ3ZPKXuOFxUgYHiB2L2IoHpmjyb -oZB3xrwYHM5Yzuy6o5+Wgvptsdrd8bTPVtHD50wt9BM1r72mdppvKbq9pksx4tYr -apw4WXfjO2zbdOngY4T5pCk5NZgXrlBfY0/vXsP/3SR+52KXGre/lSt35A4SjNe6 -voI1vZLDNlqzRaEZqBC0tLyvMH3NaYpRhwyEHtoABE9AQvVaQNt+fN1qhbhjtVdQ -lR64Dqdc6jjIhuUhs1umYswf2umA3duZox8RTLZo1UECgYEA4oM2gLsX7dVNiDI4 -bZsMBdm8cb+N3/npiZBlDL9UL4tWCzLQP8sR/HJH3OZHQ1iLk+7QXi2g0YR5VtNx -tLvECK1+Cd3sGt2zyFcrSpeYAnvbsMqB9F/K3grCCnvzKKmHJS27c9EVGr+sRTbx -6hSqQyEAYTP1yRLnLVmWzkCBXh8CgYEAz5eqFmfou3U7B04tK739HTJGAaHTxVAR -C4u4x0HGUP+NhPKZzySc70vWHoNgyP/QBUgzf5gTEnGCJ7Rk6Y2YZxCLyPksEDFc -meW9ENSOQMwTWM1PAF+XLr4wXbyojMqlI7vWimTMOPK7WMVt4jYCoaN9lBS+McYj -e1ZpB5yEj1ECgYEAiSXLXVxq2604GYvW0L59JBm22OSTwZZuycUs+e/qyDLEcVld -8BJDnKeRTXX8lhFJydNiRHO6GMHuOh0ijrzVsC9jzhOZvpaYIWhuJObuuipGVZ/3 -2YAatCCtZm2wR+GFm4Q6KKDi92QwqWPgS8whXy3fLfupCQsyACprfgxeiB8CgYBF -pfjm843d9wMK/GujVWbquMdMHONUO/y8BvDDyYmj+1mb1VlNaldM4gDA1AtQ5KMC -YqsEkB01/udQMvH4eg075w0/LHpgJG+RIsdAMlBX5SBIlvl+gpPSlvTbPkS+l+64 -AnmEjTUHlkjNC9BGKSDQ4m1rlVoKkROuedtbNmQzQQKBgQCQdmmWy2Nr9NRmy5+r -3FKymUVGujww+R7IiFGnFiBBhec8hUPaBp1xG5d8XVIcLt6nleOX5ZunXBwTOmp6 -XH6tQuup+hjFiNpRLmbVkTv8uQVy5sWEqiGp0i7Jhb+0QEOSEshOr8sQDDAFwWXl -FyCbC1amAeC1i1knzGrNOdppUw== ------END PRIVATE KEY----- diff --git a/xinelu-common/src/main/java/com/xinelu/common/config/YlypWeChatPaymentConfig.java b/xinelu-common/src/main/java/com/xinelu/common/config/YlypWeChatPaymentConfig.java deleted file mode 100644 index ea976a4..0000000 --- a/xinelu-common/src/main/java/com/xinelu/common/config/YlypWeChatPaymentConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xinelu.common.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * @Description 医路优品商户号微信支付参数配置类 - * @Author 纪寒 - * @Date 2022-10-17 16:55:04 - * @Version 1.0 - */ -@Data -@Component -@ConfigurationProperties(prefix = "ylyp-we-chat-config") -public class YlypWeChatPaymentConfig { - - private String ylypMchId; - - private String ylypMchSerialNo; - - private String ylypPrivateKeyPath; - - private String ylypPaymentKey; - - private String ylypWeChatNotifyUrl; -} diff --git a/xinelu-framework/src/main/java/com/xinelu/framework/config/YlypWeChatPaymentUtilConfig.java b/xinelu-framework/src/main/java/com/xinelu/framework/config/YlypWeChatPaymentUtilConfig.java deleted file mode 100644 index 0507f18..0000000 --- a/xinelu-framework/src/main/java/com/xinelu/framework/config/YlypWeChatPaymentUtilConfig.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.xinelu.framework.config; - -import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder; -import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner; -import com.wechat.pay.contrib.apache.httpclient.auth.Verifier; -import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials; -import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator; -import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager; -import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; -import com.xinelu.common.config.YlypWeChatPaymentConfig; -import com.xinelu.common.exception.ServiceException; -import lombok.extern.slf4j.Slf4j; -import org.apache.http.impl.client.CloseableHttpClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; - -import javax.annotation.Resource; -import java.nio.charset.StandardCharsets; -import java.security.PrivateKey; - -/** - * @Description 医路优品微信支付核心配置类 - * @Author 纪寒 - * @Date 2022-10-17 18:56:22 - * @Version 1.0 - */ -@Configuration -@Slf4j -public class YlypWeChatPaymentUtilConfig { - - @Resource - private YlypWeChatPaymentConfig ylypWeChatPaymentConfig; - - /** - * 获取新医路签名信息 - * - * @return 签名信息 - * @throws Exception 异常信息 - */ - @Bean(name = "ylypVerifier") - public Verifier getYlypVerifier() throws Exception { - PrivateKey privateKey = getPrivateKey(ylypWeChatPaymentConfig.getYlypPrivateKeyPath()); - PrivateKeySigner privateKeySigner = new PrivateKeySigner(ylypWeChatPaymentConfig.getYlypMchSerialNo(), privateKey); - WechatPay2Credentials wechatPay2Credentials = new WechatPay2Credentials(ylypWeChatPaymentConfig.getYlypMchId(), privateKeySigner); - CertificatesManager certificatesManager = CertificatesManager.getInstance(); - certificatesManager.putMerchant(ylypWeChatPaymentConfig.getYlypMchId(), wechatPay2Credentials, ylypWeChatPaymentConfig.getYlypPaymentKey().getBytes(StandardCharsets.UTF_8)); - return certificatesManager.getVerifier(ylypWeChatPaymentConfig.getYlypMchId()); - } - - /** - * 获取医路优品商户带有签名信息的http请求对象 - * - * @return CloseableHttpClient对象 - */ - @Bean(name = "yiLuYouPinWeChatPayClient") - public CloseableHttpClient getYiLuYouPinWeChatPayClient(Verifier ylypVerifier) { - PrivateKey privateKey = getPrivateKey(ylypWeChatPaymentConfig.getYlypPrivateKeyPath()); - CloseableHttpClient closeableHttpClient = null; - try { - closeableHttpClient = WechatPayHttpClientBuilder.create() - .withMerchant(ylypWeChatPaymentConfig.getYlypMchId(), ylypWeChatPaymentConfig.getYlypMchSerialNo(), privateKey) - .withValidator(new WechatPay2Validator(ylypVerifier)).build(); - } catch (Exception e) { - log.error("医路优品验证签名信息失败,失败信息:{}", e.getMessage()); - } - return closeableHttpClient; - } - - /** - * 获取HttpClient,无需进行应答签名验证,跳过验签的流程 - * - * @return CloseableHttpClient对象 - */ - @Bean(name = "yiLuYouPinWeChatPayNoSignClient") - public CloseableHttpClient getYiLuYouPinWeChatPayNoSignClient() { - PrivateKey privateKey = getPrivateKey(ylypWeChatPaymentConfig.getYlypPrivateKeyPath()); - return WechatPayHttpClientBuilder.create() - .withMerchant(ylypWeChatPaymentConfig.getYlypMchId(), ylypWeChatPaymentConfig.getYlypMchSerialNo(), privateKey) - .withValidator((response) -> true).build(); - } - - /** - * 获取商户的私钥文件 - * - * @param filename 获取商户的私钥文件 - * @return 商户私钥 - */ - private PrivateKey getPrivateKey(String filename) { - try { - return PemUtil.loadPrivateKey(new ClassPathResource(filename).getInputStream()); - } catch (Exception e) { - log.error("医路优品商户私钥文件不存在,错误原因:{}", e.getMessage()); - throw new ServiceException("医路优品商户私钥文件不存在,请联系管理员!"); - } - } -} diff --git a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/controller/wechatpaymentinfo/WeChatPaymentController.java b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/controller/wechatpaymentinfo/WeChatPaymentController.java index e40adef..bdc87e3 100644 --- a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/controller/wechatpaymentinfo/WeChatPaymentController.java +++ b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/controller/wechatpaymentinfo/WeChatPaymentController.java @@ -123,10 +123,9 @@ public class WeChatPaymentController extends BaseController { * * @param refundDTO 退款参数 * @return 退款申请结果 - * @throws Exception 异常信息 */ @PostMapping("/weChatRefundOrderApply") - public AjaxResult weChatRefundOrderApply(@Validated(Insert.class) @RequestBody RefundDTO refundDTO) throws Exception { + public AjaxResult weChatRefundOrderApply(@Validated(Insert.class) @RequestBody RefundDTO refundDTO) { return weChatRefundService.weChatRefundOrderApply(refundDTO); } diff --git a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatPaymentService.java b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatPaymentService.java index 75bdf05..94691b0 100644 --- a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatPaymentService.java +++ b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatPaymentService.java @@ -30,26 +30,6 @@ public interface WeChatPaymentService { */ AjaxResult appletAppointmentOrderPay(PaymentDTO paymentDTO) throws Exception; - /** - * 取消订单接口 - * - * @param orderNo 点单编号 - * @param buySource 购买来源 - * @return 取消结果信息 - * @throws Exception 异常信息 - */ - AjaxResult cancelOrderInfo(String orderNo, String buySource) throws Exception; - - /** - * 查询订单状态信息 - * - * @param orderNo 点单编号 - * @param buySource 购买来源 - * @return 结果信息 - * @throws Exception 异常信息 - */ - AjaxResult getOrderStatusInfo(String orderNo, String buySource) throws Exception; - /** * 微信关闭订单方法 * diff --git a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatRefundService.java b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatRefundService.java index 966dd61..dbab3cb 100644 --- a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatRefundService.java +++ b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/WeChatRefundService.java @@ -17,9 +17,8 @@ public interface WeChatRefundService { * * @param refundDTO 退款参数 * @return 返回信息 - * @throws Exception 异常信息 */ - AjaxResult weChatRefundOrderApply(RefundDTO refundDTO) throws Exception; + AjaxResult weChatRefundOrderApply(RefundDTO refundDTO); /** * 调用微信查询单笔退款接口查询预约订单状态信息 @@ -35,7 +34,6 @@ public interface WeChatRefundService { * @param refundNo 退单编号 * @param buySource 购买来源 * @return 退款信息 - * @throws Exception 异常信息 */ - WeChatRefundInfoVO queryGoodsOrderRefundStatus(String refundNo, String buySource) throws Exception; + WeChatRefundInfoVO queryGoodsOrderRefundStatus(String refundNo, String buySource); } diff --git a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPayNotifyServiceImpl.java b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPayNotifyServiceImpl.java index c530ea7..fb470d6 100644 --- a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPayNotifyServiceImpl.java +++ b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPayNotifyServiceImpl.java @@ -11,7 +11,6 @@ import com.xinelu.applet.service.wechatpaymentinfo.WeChatPayNotifyService; import com.xinelu.applet.vo.wechatpaymentinfo.vo.WeChatPayNotifyPlaintextVO; import com.xinelu.applet.vo.wechatpaymentinfo.vo.WeChatRefundNotifyVO; import com.xinelu.common.config.XylWeChatPaymentConfig; -import com.xinelu.common.config.YlypWeChatPaymentConfig; import com.xinelu.common.constant.Constants; import com.xinelu.common.enums.*; import com.xinelu.common.exception.ServiceException; @@ -67,8 +66,6 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService { @Resource private AppointmentOrderMapper appointmentOrderMapper; @Resource - private YlypWeChatPaymentConfig ylypWeChatPaymentConfig; - @Resource private PaymentInfoMapper paymentInfoMapper; @Resource private RedisDistributedLockUtils redisDistributedLockUtils; @@ -80,23 +77,11 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService { private RefundInfoMapper refundInfoMapper; @Resource(name = "xylVerifier") private Verifier xylVerifier; - @Resource(name = "ylypVerifier") - private Verifier ylypVerifier; @Resource private RedisTemplate redisTemplate; @Resource private PatientCouponReceiveMapper patientCouponReceiveMapper; - /** - * 新医路账户标识 - */ - private static final String XINYILU_ACCOUNT = "XINYILU"; - - /** - * 新医路账户标识 - */ - private static final String YILUYOUPIN_ACCOUNT = "YILUYOUPIN"; - /** * 支付回调标识 */ @@ -187,19 +172,10 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService { String timestamp = request.getHeader("Wechatpay-Timestamp"); String signature = request.getHeader("Wechatpay-Signature"); String serialNo = request.getHeader("Wechatpay-Serial"); - Notification notification = null; - if (XINYILU_ACCOUNT.equals(accountFlag)) { - NotificationRequest notificationRequest = new NotificationRequest.Builder().withSerialNumber(serialNo) - .withNonce(nonce).withTimestamp(timestamp).withSignature(signature).withBody(body).build(); - NotificationHandler handler = new NotificationHandler(xylVerifier, xylWeChatPaymentConfig.getXylPaymentKey().getBytes(StandardCharsets.UTF_8)); - notification = handler.parse(notificationRequest); - } - if (YILUYOUPIN_ACCOUNT.equals(accountFlag)) { - NotificationRequest notificationRequest = new NotificationRequest.Builder().withSerialNumber(serialNo) - .withNonce(nonce).withTimestamp(timestamp).withSignature(signature).withBody(body).build(); - NotificationHandler handler = new NotificationHandler(ylypVerifier, ylypWeChatPaymentConfig.getYlypPaymentKey().getBytes(StandardCharsets.UTF_8)); - notification = handler.parse(notificationRequest); - } + NotificationRequest notificationRequest = new NotificationRequest.Builder().withSerialNumber(serialNo) + .withNonce(nonce).withTimestamp(timestamp).withSignature(signature).withBody(body).build(); + NotificationHandler handler = new NotificationHandler(xylVerifier, xylWeChatPaymentConfig.getXylPaymentKey().getBytes(StandardCharsets.UTF_8)); + Notification notification = handler.parse(notificationRequest); if (Objects.isNull(notification)) { log.error(accountFlag + "微信通知验签失败,请求体 ====> {}", body); response.setStatus(500); @@ -210,15 +186,8 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService { String ciphertext = StringUtils.isBlank(notification.getResource().getCiphertext()) ? "" : notification.getResource().getCiphertext(); String nonceTwo = StringUtils.isBlank(notification.getResource().getNonce()) ? "" : notification.getResource().getNonce(); String associatedData = StringUtils.isBlank(notification.getResource().getAssociatedData()) ? "" : notification.getResource().getAssociatedData(); - String plainText = ""; - if (XINYILU_ACCOUNT.equals(accountFlag)) { - AesUtil aesUtil = new AesUtil(xylWeChatPaymentConfig.getXylPaymentKey().getBytes(StandardCharsets.UTF_8)); - plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8), nonceTwo.getBytes(StandardCharsets.UTF_8), ciphertext); - } - if (YILUYOUPIN_ACCOUNT.equals(accountFlag)) { - AesUtil aesUtil = new AesUtil(ylypWeChatPaymentConfig.getYlypPaymentKey().getBytes(StandardCharsets.UTF_8)); - plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8), nonceTwo.getBytes(StandardCharsets.UTF_8), ciphertext); - } + AesUtil aesUtil = new AesUtil(xylWeChatPaymentConfig.getXylPaymentKey().getBytes(StandardCharsets.UTF_8)); + String plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8), nonceTwo.getBytes(StandardCharsets.UTF_8), ciphertext); if (StringUtils.isBlank(plainText)) { response.setStatus(500); resultMap.put("code", "ERROR"); @@ -337,12 +306,7 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService { paymentInfo.setWechatTradeState(StringUtils.isBlank(notifyPlaintext.getTradeState()) ? "" : notifyPlaintext.getTradeState()); paymentInfo.setPayNotifyContent(plainText); paymentInfo.setPayTime(LocalDateTime.parse(StringUtils.isBlank(notifyPlaintext.getSuccessTime()) ? "" : notifyPlaintext.getSuccessTime(), DateTimeFormatter.ISO_DATE_TIME)); - if (notifyPlaintext.getMchid().equals(xylWeChatPaymentConfig.getXylMchId())) { - paymentInfo.setPaymentMerchantType(PaymentMerchantTypeEnum.XINYILU.getInfo()); - } - if (notifyPlaintext.getMchid().equals(ylypWeChatPaymentConfig.getYlypMchId())) { - paymentInfo.setPaymentMerchantType(PaymentMerchantTypeEnum.YILUYOUPIN.getInfo()); - } + paymentInfo.setPaymentMerchantType(PaymentMerchantTypeEnum.XINYILU.getInfo()); paymentInfo.setDelFlag(0); paymentInfo.setCreateTime(LocalDateTime.now()); return paymentInfo; diff --git a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPaymentServiceImpl.java b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPaymentServiceImpl.java index fcb03dd..8476b24 100644 --- a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPaymentServiceImpl.java +++ b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatPaymentServiceImpl.java @@ -11,10 +11,8 @@ import com.xinelu.applet.vo.wechatpaymentinfo.vo.WeChatQueryOrderVO; import com.xinelu.common.config.AppletChatConfig; import com.xinelu.common.config.WeChatPaymentUrlConfig; import com.xinelu.common.config.XylWeChatPaymentConfig; -import com.xinelu.common.config.YlypWeChatPaymentConfig; import com.xinelu.common.constant.Constants; import com.xinelu.common.core.domain.AjaxResult; -import com.xinelu.common.enums.BuySourceEnum; import com.xinelu.common.enums.GooodsOrderStatusEnum; import com.xinelu.common.enums.OrderStatusEnum; import com.xinelu.common.enums.WeChatTradeStateEnum; @@ -24,7 +22,6 @@ import com.xinelu.manage.domain.goodsOrder.GoodsOrder; import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper; import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -34,7 +31,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Base64Utils; import javax.annotation.Resource; @@ -42,7 +38,6 @@ import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.security.PrivateKey; import java.security.Signature; -import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -66,12 +61,8 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { private AppletChatConfig appletChatConfig; @Resource private XylWeChatPaymentConfig xylWeChatPaymentConfig; - @Resource - private YlypWeChatPaymentConfig ylypWeChatPaymentConfig; @Resource(name = "xinYiLuWeChatPayClient") private CloseableHttpClient xinYiLuWeChatPayClient; - @Resource(name = "yiLuYouPinWeChatPayClient") - private CloseableHttpClient yiLuYouPinWeChatPayClient; @Resource private WeChatPaymentUrlConfig weChatPaymentUrlConfig; @Resource @@ -84,11 +75,6 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { */ private static final String XIN_YI_LU_DESCRIPTION = "山东新医路信息科技有限公司"; - /** - * 医路优品支付商品描述 - */ - private static final String YI_LU_YOU_PIN_DESCRIPTION = "医路优品信息科技有限公司"; - /** * JsApi下单成功状态码 */ @@ -114,11 +100,6 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { */ private static final String XINYILU_WE_CHAT_NOTIFY_URL = "/nurseApp/weChatPayment/xylWeChatPayNotify"; - /** - * 医路优品支付回调接口地址 - */ - private static final String YINLUYOUPIN_WE_CHAT_NOTIFY_URL = "/nurseApp/weChatPayment/ylypWeChatPayNotify"; - /** * 微信小程序购买商品和健康咨询支付接口 * @@ -147,7 +128,7 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { } else { prepayId = redisTemplate.opsForValue().get(Constants.PREPAY_ID_KEY + paymentDTO.getOrderNo()); } - return AjaxResult.success(getSignInfo(prepayId, paymentDTO.getBuySource())); + return AjaxResult.success(getSignInfo(prepayId)); } /** @@ -173,97 +154,7 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { } else { prepayId = redisTemplate.opsForValue().get(Constants.PREPAY_ID_KEY + paymentDTO.getOrderNo()); } - return AjaxResult.success(getSignInfo(prepayId, paymentDTO.getBuySource())); - } - - /** - * 取消订单接口 - * - * @param orderNo 点单编号 - * @param buySource 购买来源 - * @return 取消结果信息 - */ - @Transactional(rollbackFor = Exception.class) - @Override - public AjaxResult cancelOrderInfo(String orderNo, String buySource) throws Exception { - GoodsOrder goodsOrderInfo = goodsOrderMapper.getGoodsOrderByOrderNo(orderNo); - AppointmentOrder appointmentOrderInfo = appointmentOrderMapper.getAppointmentOrderByOrderNo(orderNo); - if (Objects.isNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) { - return AjaxResult.error("当前订单信息不存在,请重新选择!"); - } - //商品订单 - if (Objects.nonNull(goodsOrderInfo)) { - if (StringUtils.isBlank(goodsOrderInfo.getOrderStatus()) - || !GooodsOrderStatusEnum.WAIT_PAY.getInfo().equals(goodsOrderInfo.getOrderStatus())) { - log.info("订单状态为:====> {}", StringUtils.isBlank(goodsOrderInfo.getOrderStatus()) ? "不存在" : goodsOrderInfo.getOrderStatus()); - return AjaxResult.error("当前订单状态异常,请联系管理员!"); - } - LocalDateTime tenAfterTime = goodsOrderInfo.getOrderTime().plusMinutes(10); - if (LocalDateTime.now().isBefore(tenAfterTime)) { - return AjaxResult.error("10分钟以后才能取消当前订单,请耐心等待!"); - } - OrderStatusInfoVO orderStatusInfoVO = new OrderStatusInfoVO(); - OrderStatusInfoVO vo = this.queryGoodsOrderStatus(goodsOrderInfo.getOrderNo(), orderStatusInfoVO, buySource); - if (BooleanUtils.isTrue(vo.getPayFlag())) { - int statusCode = this.closeWeChatOrderInfo(goodsOrderInfo.getOrderNo(), goodsOrderInfo.getBuySource()); - if (!(statusCode == HAVE_BODY_SUCCESS_CODE || statusCode == NO_HAVE_BODY_SUCCESS_CODE)) { - return AjaxResult.error("取消订单失败,请联系管理员!"); - } - goodsOrderMapper.updateGoodsOrderStatus(GooodsOrderStatusEnum.CANCEL.getInfo(), orderNo); - } - } - //预约服务订单信息 - if (Objects.nonNull(appointmentOrderInfo)) { - if (StringUtils.isBlank(appointmentOrderInfo.getOrderStatus()) - || !OrderStatusEnum.WAIT_PAY.getInfo().equals(appointmentOrderInfo.getOrderStatus())) { - log.info("订单状态为:====> {}", StringUtils.isBlank(appointmentOrderInfo.getOrderStatus()) ? "不存在" : appointmentOrderInfo.getOrderStatus()); - return AjaxResult.error("当前订单状态异常,请联系管理员!"); - } - LocalDateTime tenAfterTime = appointmentOrderInfo.getCreateTime().plusMinutes(10); - if (LocalDateTime.now().isBefore(tenAfterTime)) { - return AjaxResult.error("10分钟以后才能取消当前订单,请耐心等待!"); - } - OrderStatusInfoVO orderStatusInfoVO = new OrderStatusInfoVO(); - OrderStatusInfoVO vo = this.queryAppointmentOrderStatus(appointmentOrderInfo.getOrderNo(), orderStatusInfoVO); - if (BooleanUtils.isTrue(vo.getPayFlag())) { - int statusCode = this.closeWeChatOrderInfo(appointmentOrderInfo.getOrderNo(), BuySourceEnum.NURSE_STATION.getInfo()); - if (!(statusCode == HAVE_BODY_SUCCESS_CODE || statusCode == NO_HAVE_BODY_SUCCESS_CODE)) { - return AjaxResult.error("取消订单失败,请联系管理员!"); - } - appointmentOrderMapper.updateAppointmentOrderStatus(OrderStatusEnum.CANCEL.getInfo(), orderNo); - } - } - return AjaxResult.success("取消订单成功!"); - } - - /** - * 查询订单状态信息 - * - * @param orderNo 点单编号 - * @param buySource 购买来源 - * @return 结果信息 - * @throws Exception 异常信息 - */ - @Override - public AjaxResult getOrderStatusInfo(String orderNo, String buySource) throws Exception { - OrderStatusInfoVO vo = new OrderStatusInfoVO(); - GoodsOrder goodsOrder = goodsOrderMapper.getGoodsOrderByOrderNo(orderNo); - AppointmentOrder appointmentOrder = appointmentOrderMapper.getAppointmentOrderByOrderNo(orderNo); - if (Objects.isNull(goodsOrder) && Objects.isNull(appointmentOrder)) { - vo.setPayFlag(true); - return AjaxResult.success(vo); - } - //预约服务订单不为空,调用微信查单接口确认订单状态 - if (Objects.nonNull(appointmentOrder)) { - OrderStatusInfoVO order = new OrderStatusInfoVO(); - vo = this.queryAppointmentOrderStatus(appointmentOrder.getOrderNo(), order); - } - //商品订单不为空,调用微信查单接口确认订单状态 - if (Objects.nonNull(goodsOrder)) { - OrderStatusInfoVO order = new OrderStatusInfoVO(); - vo = this.queryGoodsOrderStatus(goodsOrder.getOrderNo(), order, buySource); - } - return AjaxResult.success(vo); + return AjaxResult.success(getSignInfo(prepayId)); } /** @@ -279,28 +170,13 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { String closeUrl = String.format(weChatPaymentUrlConfig.getCloseOrderUrl(), orderNo); HttpPost httpPost = new HttpPost(closeUrl); Map paramMap = new HashMap<>(); - String jsonParams; - CloseableHttpResponse response = null; - if (BuySourceEnum.NURSE_STATION.getInfo().equals(buySource)) { - paramMap.put("mchid", xylWeChatPaymentConfig.getXylMchId()); - jsonParams = JSON.toJSONString(paramMap); - StringEntity entity = new StringEntity(jsonParams, "utf-8"); - entity.setContentType("application/json"); - httpPost.setEntity(entity); - httpPost.setHeader("Accept", "application/json"); - response = xinYiLuWeChatPayClient.execute(httpPost); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(buySource) - || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(buySource) || BuySourceEnum.TRAINING.getInfo().equals(buySource)) { - paramMap.put("mchid", ylypWeChatPaymentConfig.getYlypMchId()); - jsonParams = JSON.toJSONString(paramMap); - StringEntity entity = new StringEntity(jsonParams, "utf-8"); - entity.setContentType("application/json"); - httpPost.setEntity(entity); - httpPost.setHeader("Accept", "application/json"); - response = yiLuYouPinWeChatPayClient.execute(httpPost); - } - try { + paramMap.put("mchid", xylWeChatPaymentConfig.getXylMchId()); + String jsonParams = JSON.toJSONString(paramMap); + StringEntity entity = new StringEntity(jsonParams, "utf-8"); + entity.setContentType("application/json"); + httpPost.setEntity(entity); + httpPost.setHeader("Accept", "application/json"); + try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpPost)) { if (response == null) { throw new ServiceException("获取微信HttpClient对象失败,请联系管理员!"); } @@ -316,10 +192,6 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { throw new ServiceException("微信关闭订单失败!"); } return statusCode; - } finally { - if (response != null) { - response.close(); - } } } @@ -363,27 +235,11 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { * @param vo 返回值信息 */ @Override - public OrderStatusInfoVO queryGoodsOrderStatus(String orderNo, OrderStatusInfoVO vo, - String buySource) throws Exception { - String requestUrl = ""; - if (BuySourceEnum.NURSE_STATION.getInfo().equals(buySource)) { - requestUrl = String.format(weChatPaymentUrlConfig.getQueryMchIdUrl(), orderNo).concat("?mchid=").concat(xylWeChatPaymentConfig.getXylMchId()); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(buySource) - || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(buySource) || BuySourceEnum.TRAINING.getInfo().equals(buySource)) { - requestUrl = String.format(weChatPaymentUrlConfig.getQueryMchIdUrl(), orderNo).concat("?mchid=").concat(ylypWeChatPaymentConfig.getYlypMchId()); - } + public OrderStatusInfoVO queryGoodsOrderStatus(String orderNo, OrderStatusInfoVO vo, String buySource) { + String requestUrl = String.format(weChatPaymentUrlConfig.getQueryMchIdUrl(), orderNo).concat("?mchid=").concat(xylWeChatPaymentConfig.getXylMchId()); HttpGet httpGet = new HttpGet(requestUrl); httpGet.setHeader("Accept", "application/json"); - CloseableHttpResponse response = null; - try { - if (BuySourceEnum.NURSE_STATION.getInfo().equals(buySource)) { - response = xinYiLuWeChatPayClient.execute(httpGet); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(buySource) - || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(buySource) || BuySourceEnum.TRAINING.getInfo().equals(buySource)) { - response = yiLuYouPinWeChatPayClient.execute(httpGet); - } + try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpGet)) { if (response == null) { throw new ServiceException("获取微信HttpClient对象失败,请联系管理员!"); } @@ -403,10 +259,6 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { } catch (Exception e) { log.error("请求微信查单接口异常,异常信息为 ====> {}", e.getMessage()); throw new ServiceException("查询商品订单状态失败,请联系管理员!"); - } finally { - if (response != null) { - response.close(); - } } } @@ -419,20 +271,11 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { */ private String buildGoodsOrderJsApiParams(PaymentDTO paymentDTO, GoodsOrder goodsOrderInfo) { Map paramMap = new LinkedHashMap<>(); - if (BuySourceEnum.NURSE_STATION.getInfo().equals(paymentDTO.getBuySource())) { - paramMap.put("mchid", xylWeChatPaymentConfig.getXylMchId()); - paramMap.put("out_trade_no", goodsOrderInfo.getOrderNo()); - paramMap.put("appid", appletChatConfig.getAppletId()); - paramMap.put("description", XIN_YI_LU_DESCRIPTION); - paramMap.put("notify_url", xylWeChatPaymentConfig.getXylWeChatNotifyUrl() + XINYILU_WE_CHAT_NOTIFY_URL); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(paymentDTO.getBuySource()) || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(paymentDTO.getBuySource())) { - paramMap.put("mchid", ylypWeChatPaymentConfig.getYlypMchId()); - paramMap.put("out_trade_no", goodsOrderInfo.getOrderNo()); - paramMap.put("appid", appletChatConfig.getAppletId()); - paramMap.put("description", YI_LU_YOU_PIN_DESCRIPTION); - paramMap.put("notify_url", ylypWeChatPaymentConfig.getYlypWeChatNotifyUrl() + YINLUYOUPIN_WE_CHAT_NOTIFY_URL); - } + paramMap.put("mchid", xylWeChatPaymentConfig.getXylMchId()); + paramMap.put("out_trade_no", goodsOrderInfo.getOrderNo()); + paramMap.put("appid", appletChatConfig.getAppletId()); + paramMap.put("description", XIN_YI_LU_DESCRIPTION); + paramMap.put("notify_url", xylWeChatPaymentConfig.getXylWeChatNotifyUrl() + XINYILU_WE_CHAT_NOTIFY_URL); Map amountParamMap = new LinkedHashMap<>(); int totalPrice = paymentDTO.getPaymentPrice().multiply(BigDecimal.valueOf(100)).intValue(); amountParamMap.put("total", totalPrice); @@ -451,30 +294,16 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { * @param paymentDTO 输入参数 * @param prepayId JsAp下单接口返回值 * @return 结果 - * @throws Exception 异常信息 */ - private String requestJsApiInterface(String jsApiParams, PaymentDTO paymentDTO, String prepayId) throws Exception { + private String requestJsApiInterface(String jsApiParams, PaymentDTO paymentDTO, String prepayId) { StringEntity stringEntity = new StringEntity(jsApiParams, StandardCharsets.UTF_8); stringEntity.setContentType("application/json"); HttpPost httpPost = new HttpPost(weChatPaymentUrlConfig.getJsapiPalceOrderUrl()); httpPost.setEntity(stringEntity); httpPost.setHeader("Accept", "application/json"); - CloseableHttpResponse response = null; - String payAccount = ""; - try { - if (BuySourceEnum.NURSE_STATION.getInfo().equals(paymentDTO.getBuySource())) { - response = xinYiLuWeChatPayClient.execute(httpPost); - payAccount = "山东新医路信息科技有限公司"; - } - //泉医会员小程序中的商城订单、健康咨询订单、泉医助手学习培训订单都使用医路优品账户进行支付 - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(paymentDTO.getBuySource()) - || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(paymentDTO.getBuySource()) - || BuySourceEnum.TRAINING.getInfo().equals(paymentDTO.getBuySource())) { - response = yiLuYouPinWeChatPayClient.execute(httpPost); - payAccount = "医路优品信息科技有限公司"; - } + try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpPost)) { if (Objects.isNull(response)) { - log.error("JsApi下单接口执行错误, 执行账户为 ====> {}", payAccount); + log.error("JsApi下单接口执行错误, 执行账户为 ====> 山东新医路信息科技有限公司"); throw new ServiceException("JsApi下单接口执行异常,请联系管理员!"); } int statusCode = response.getStatusLine().getStatusCode(); @@ -492,10 +321,6 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { } catch (Exception e) { log.error("JsApi下单失败,失败原因 =====> {}", e.getMessage()); throw new ServiceException("JsApi下单失败,请联系管理员!"); - } finally { - if (response != null) { - response.close(); - } } return prepayId; } @@ -503,27 +328,16 @@ public class WeChatPaymentServiceImpl implements WeChatPaymentService { /** * 构建微信小程序调起支付参数设置 * - * @param prepayId jsapi下单返回参数信息 - * @param buySource 购买来源 + * @param prepayId jsapi下单返回参数信息 * @return 参数信息 * @throws Exception 异常信息 */ - private WeChatAppletSignVO getSignInfo(String prepayId, String buySource) throws Exception { + private WeChatAppletSignVO getSignInfo(String prepayId) throws Exception { String appId = appletChatConfig.getAppletId(); String nonceStr = UUID.randomUUID().toString().replace("-", ""); String timestamp = String.valueOf(System.currentTimeMillis() / 1000); - PrivateKey privateKey = null; - //泉医到家小程序中的护理站模块的支付账户均使用新医路账户进行支付 - if (BuySourceEnum.NURSE_STATION.getInfo().equals(buySource)) { - privateKey = weChatUtil.getPrivateKey(xylWeChatPaymentConfig.getXylPrivateKeyPath()); - } - //泉医到家小程序中的商城模块和健康咨询模块以及泉医助手中的学习培训模块使用医路优品账户进行支付 - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(buySource) - || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(buySource) - || BuySourceEnum.TRAINING.getInfo().equals(buySource)) { - privateKey = weChatUtil.getPrivateKey(ylypWeChatPaymentConfig.getYlypPrivateKeyPath()); - } - if (privateKey == null) { + PrivateKey privateKey = weChatUtil.getPrivateKey(xylWeChatPaymentConfig.getXylPrivateKeyPath()); + if (Objects.isNull(privateKey)) { throw new ServiceException("获取商户私钥失败,请联系管理员!"); } prepayId = "prepay_id=" + prepayId; diff --git a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatRefundServiceImpl.java b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatRefundServiceImpl.java index c275f33..2413684 100644 --- a/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatRefundServiceImpl.java +++ b/xinelu-nurse-applet/src/main/java/com/xinelu/applet/service/wechatpaymentinfo/impl/WeChatRefundServiceImpl.java @@ -8,7 +8,6 @@ import com.xinelu.applet.vo.wechatpaymentinfo.dto.RefundDTO; import com.xinelu.applet.vo.wechatpaymentinfo.vo.WeChatRefundInfoVO; import com.xinelu.common.config.WeChatPaymentUrlConfig; import com.xinelu.common.config.XylWeChatPaymentConfig; -import com.xinelu.common.config.YlypWeChatPaymentConfig; import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.common.enums.*; import com.xinelu.common.exception.ServiceException; @@ -58,12 +57,8 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { private AppointmentOrderMapper appointmentOrderMapper; @Resource private XylWeChatPaymentConfig xylWeChatPaymentConfig; - @Resource - private YlypWeChatPaymentConfig ylypWeChatPaymentConfig; @Resource(name = "xinYiLuWeChatPayClient") private CloseableHttpClient xinYiLuWeChatPayClient; - @Resource(name = "yiLuYouPinWeChatPayClient") - private CloseableHttpClient yiLuYouPinWeChatPayClient; @Resource private WeChatPaymentUrlConfig weChatPaymentUrlConfig; @Resource @@ -90,21 +85,15 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { */ private static final String XINYILU_WE_CHAT_REFUND_URL = "/nurseApp/weChatPayment/xylWeChatRefundNotify"; - /** - * 医路优品退款回调接口地址 - */ - private static final String YINLUYOUPIN_WE_CHAT_REFUND_URL = "/nurseApp/weChatPayment/ylypWeChatRefundNotify"; - /** * 微信确认退款接口 * * @param refundDTO 退款参数 * @return 退款申请结果 - * @throws Exception 异常信息 */ @Transactional(rollbackFor = Exception.class) @Override - public AjaxResult weChatRefundOrderApply(RefundDTO refundDTO) throws Exception { + public AjaxResult weChatRefundOrderApply(RefundDTO refundDTO) { if (StringUtils.isNotBlank(refundDTO.getOrderType()) && StringUtils.equals(OrderTypeEnum.INTEGRAL_EXCHANGE.getInfo(), refundDTO.getOrderType())) { return refundPointsRedemption(refundDTO); } @@ -188,23 +177,14 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { * @param refundNo 退单编号 * @param buySource 购买来源 * @return 退款信息 - * @throws Exception 异常信息 */ @Override - public WeChatRefundInfoVO queryGoodsOrderRefundStatus(String refundNo, String buySource) throws Exception { + public WeChatRefundInfoVO queryGoodsOrderRefundStatus(String refundNo, String buySource) { WeChatRefundInfoVO weChatRefundInfoVO = new WeChatRefundInfoVO(); String requestUrl = String.format(weChatPaymentUrlConfig.getRefundQueryOrderUrl(), refundNo); HttpGet httpGet = new HttpGet(requestUrl); httpGet.setHeader("Accept", "application/json"); - CloseableHttpResponse response = null; - try { - if (BuySourceEnum.NURSE_STATION.getInfo().equals(buySource)) { - response = xinYiLuWeChatPayClient.execute(httpGet); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(buySource) - || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(buySource) || BuySourceEnum.TRAINING.getInfo().equals(buySource)) { - response = yiLuYouPinWeChatPayClient.execute(httpGet); - } + try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpGet)) { if (response == null) { throw new ServiceException("获取微信HttpClient对象失败,请联系管理员!"); } @@ -221,10 +201,6 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { } catch (Exception e) { log.error("请求微信查询单笔退款接口,异常信息为 ====> {}", e.getMessage()); throw new ServiceException("查询商品订单状态失败,请联系管理员!"); - } finally { - if (response != null) { - response.close(); - } } } @@ -261,21 +237,12 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { paramMap.put("out_trade_no", refundDTO.getOrderNo()); paramMap.put("out_refund_no", outRefundNo); Map amountMap = new LinkedHashMap<>(); - //回调通知地址和退款金额,预约订单使用新医路账户 + paramMap.put("notify_url", xylWeChatPaymentConfig.getXylWeChatNotifyUrl() + XINYILU_WE_CHAT_REFUND_URL); + amountMap.put("refund", refundDTO.getRefundPrice().multiply(BigDecimal.valueOf(100)).intValue()); if (Objects.nonNull(appointmentOrderInfo) && Objects.isNull(goodsOrderInfo)) { - paramMap.put("notify_url", xylWeChatPaymentConfig.getXylWeChatNotifyUrl() + XINYILU_WE_CHAT_REFUND_URL); - amountMap.put("refund", refundDTO.getRefundPrice().multiply(BigDecimal.valueOf(100)).intValue()); amountMap.put("total", appointmentOrderInfo.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue()); } - //护理站商品购买订单使用新医路账户,商城商品订单和健康咨询订单使用医路优品账户 if (Objects.nonNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) { - if (BuySourceEnum.NURSE_STATION.getInfo().equals(goodsOrderInfo.getBuySource())) { - paramMap.put("notify_url", xylWeChatPaymentConfig.getXylWeChatNotifyUrl() + XINYILU_WE_CHAT_REFUND_URL); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(goodsOrderInfo.getBuySource()) || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(goodsOrderInfo.getBuySource())) { - paramMap.put("notify_url", ylypWeChatPaymentConfig.getYlypWeChatNotifyUrl() + YINLUYOUPIN_WE_CHAT_REFUND_URL); - } - amountMap.put("refund", refundDTO.getRefundPrice().multiply(BigDecimal.valueOf(100)).intValue()); amountMap.put("total", goodsOrderInfo.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue()); } amountMap.put("currency", "CNY"); @@ -291,35 +258,17 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { * @param goodsOrderInfo 商品订单信息 * @param patientId 会员id * @param refundDTO 申请信息 - * @throws Exception 异常信息 */ - public void applyWeRefund(String refundParam, AppointmentOrder appointmentOrderInfo, GoodsOrder goodsOrderInfo, - Long patientId, RefundDTO refundDTO) throws Exception { + public void applyWeRefund(String refundParam, AppointmentOrder appointmentOrderInfo, + GoodsOrder goodsOrderInfo, Long patientId, RefundDTO refundDTO) { String requestUrl = weChatPaymentUrlConfig.getRefundApplyUrl(); HttpPost httpPost = new HttpPost(requestUrl); StringEntity entity = new StringEntity(refundParam, "utf-8"); entity.setContentType("application/json"); httpPost.setEntity(entity); httpPost.setHeader("Accept", "application/json"); - CloseableHttpResponse response = null; - String refundMerchantType = ""; - try { - //预约订单使用新医路账户 - if (Objects.nonNull(appointmentOrderInfo) && Objects.isNull(goodsOrderInfo)) { - response = xinYiLuWeChatPayClient.execute(httpPost); - refundMerchantType = PaymentMerchantTypeEnum.XINYILU.getInfo(); - } - //护理站商品购买订单使用新医路账户,商城商品订单和健康咨询订单使用医路优品账户 - if (Objects.nonNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) { - if (BuySourceEnum.NURSE_STATION.getInfo().equals(goodsOrderInfo.getBuySource())) { - response = xinYiLuWeChatPayClient.execute(httpPost); - refundMerchantType = PaymentMerchantTypeEnum.XINYILU.getInfo(); - } - if (BuySourceEnum.SHOPPING_MALL.getInfo().equals(goodsOrderInfo.getBuySource()) || BuySourceEnum.HEALTH_CONSULTATION.getInfo().equals(goodsOrderInfo.getBuySource())) { - response = yiLuYouPinWeChatPayClient.execute(httpPost); - refundMerchantType = PaymentMerchantTypeEnum.YILUYOUPIN.getInfo(); - } - } + String refundMerchantType = PaymentMerchantTypeEnum.XINYILU.getInfo(); + try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpPost)) { if (Objects.isNull(response)) { throw new ServiceException("获取httpclient对象失败!"); } @@ -345,10 +294,6 @@ public class WeChatRefundServiceImpl implements WeChatRefundService { } } catch (Exception e) { log.error("微信申请退款接口出错,原因:{}", e.getMessage()); - } finally { - if (response != null) { - response.close(); - } } } diff --git a/xinelu-quartz/src/main/java/com/xinelu/quartz/service/RefundInfoTaskService.java b/xinelu-quartz/src/main/java/com/xinelu/quartz/service/RefundInfoTaskService.java index 339a24f..4a028a5 100644 --- a/xinelu-quartz/src/main/java/com/xinelu/quartz/service/RefundInfoTaskService.java +++ b/xinelu-quartz/src/main/java/com/xinelu/quartz/service/RefundInfoTaskService.java @@ -11,8 +11,6 @@ public interface RefundInfoTaskService { /** * 自动处理退款状态定时任务, * 防止由于网络等其它原因未接受到退款回调通知进而导致的退款单状态修改不及时 - * - * @throws Exception 异常信息 */ - void automaticProcessRefundInfo() throws Exception; + void automaticProcessRefundInfo(); } diff --git a/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/PaymentInfoTaskServiceImpl.java b/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/PaymentInfoTaskServiceImpl.java index 57e9c87..1f0edbd 100644 --- a/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/PaymentInfoTaskServiceImpl.java +++ b/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/PaymentInfoTaskServiceImpl.java @@ -5,8 +5,6 @@ import com.xinelu.applet.service.goodstock.GoodsStockService; import com.xinelu.applet.service.wechatpaymentinfo.WeChatPaymentService; import com.xinelu.applet.vo.wechatpaymentinfo.vo.OrderStatusInfoVO; import com.xinelu.applet.vo.wechatpaymentinfo.vo.WeChatQueryOrderVO; -import com.xinelu.common.config.XylWeChatPaymentConfig; -import com.xinelu.common.config.YlypWeChatPaymentConfig; import com.xinelu.common.constant.Constants; import com.xinelu.common.enums.*; import com.xinelu.manage.domain.appointmentorder.AppointmentOrder; @@ -50,7 +48,6 @@ import java.util.stream.Collectors; @Slf4j @Service public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService { - @Resource private AppointmentOrderMapper appointmentOrderMapper; @Resource @@ -59,10 +56,6 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService { private WeChatPaymentService weChatPaymentService; @Resource private PaymentInfoMapper paymentInfoMapper; - @Resource - private XylWeChatPaymentConfig xylWeChatPaymentConfig; - @Resource - private YlypWeChatPaymentConfig ylypWeChatPaymentConfig; @Resource(name = "transactionManager") private DataSourceTransactionManager transactionManager; @Resource @@ -350,12 +343,7 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService { paymentInfo.setWechatTradeState(StringUtils.isBlank(weChatQueryOrderVO.getTradeState()) ? "" : weChatQueryOrderVO.getTradeState()); paymentInfo.setPayNotifyContent(JSON.toJSON(weChatQueryOrderVO).toString()); paymentInfo.setPayTime(LocalDateTime.parse(StringUtils.isBlank(weChatQueryOrderVO.getSuccessTime()) ? "" : weChatQueryOrderVO.getSuccessTime(), DateTimeFormatter.ISO_DATE_TIME)); - if (weChatQueryOrderVO.getMchid().equals(xylWeChatPaymentConfig.getXylMchId())) { - paymentInfo.setPaymentMerchantType(PaymentMerchantTypeEnum.XINYILU.getInfo()); - } - if (weChatQueryOrderVO.getMchid().equals(ylypWeChatPaymentConfig.getYlypMchId())) { - paymentInfo.setPaymentMerchantType(PaymentMerchantTypeEnum.YILUYOUPIN.getInfo()); - } + paymentInfo.setPaymentMerchantType(PaymentMerchantTypeEnum.XINYILU.getInfo()); paymentInfo.setDelFlag(0); paymentInfo.setCreateTime(LocalDateTime.now()); return paymentInfo; @@ -382,5 +370,4 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService { } } } - } diff --git a/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/RefundInfoTaskServiceImpl.java b/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/RefundInfoTaskServiceImpl.java index 30436c3..ac5d226 100644 --- a/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/RefundInfoTaskServiceImpl.java +++ b/xinelu-quartz/src/main/java/com/xinelu/quartz/service/impl/RefundInfoTaskServiceImpl.java @@ -59,11 +59,9 @@ public class RefundInfoTaskServiceImpl implements RefundInfoTaskService { /** * 自动处理退款状态定时任务,每15分钟执行一次 * 防止由于网络等其它原因未接受到退款回调通知进而导致的退款单状态修改不及时 - * - * @throws Exception 异常信息 */ @Override - public void automaticProcessRefundInfo() throws Exception { + public void automaticProcessRefundInfo() { List appointmentOrderList = appointmentOrderMapper.getRefundAppointmentOrderInfo(OrderStatusEnum.WAIT_REFUND.getInfo(), RefundStatusEnum.PROCESSING.getInfo(), ConfirmRefundStatusEnum.CONFIRMED.getInfo()); List refundGoodsOrderLit = goodsOrderMapper.getRefundGoodsOrderInfo(GooodsOrderStatusEnum.WAIT_REFUND.getInfo(), RefundStatusEnum.PROCESSING.getInfo(), ConfirmRefundStatusEnum.CONFIRMED.getInfo()); if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(refundGoodsOrderLit)) { @@ -131,9 +129,8 @@ public class RefundInfoTaskServiceImpl implements RefundInfoTaskService { * 处理退款成功的商品订单信息 * * @param refundGoodsOrderLit 商品退款订单信息 - * @throws Exception 异常信息 */ - private void processGoodsRefundInfo(List refundGoodsOrderLit) throws Exception { + private void processGoodsRefundInfo(List refundGoodsOrderLit) { List orderNoList = Lists.newArrayList(); for (RefundOrderInfoVO refundOrderInfoVO : refundGoodsOrderLit) { if (StringUtils.isBlank(refundOrderInfoVO.getOrderNo()) diff --git a/xinelu-quartz/src/main/java/com/xinelu/quartz/task/RefundInfoTask.java b/xinelu-quartz/src/main/java/com/xinelu/quartz/task/RefundInfoTask.java index de957c4..5afa317 100644 --- a/xinelu-quartz/src/main/java/com/xinelu/quartz/task/RefundInfoTask.java +++ b/xinelu-quartz/src/main/java/com/xinelu/quartz/task/RefundInfoTask.java @@ -22,10 +22,8 @@ public class RefundInfoTask { /** * 自动处理退款状态定时任务, * 防止由于网络等其它原因未接受到退款回调通知进而导致的退款单状态修改不及时 - * - * @throws Exception 异常信息 */ - public void automaticProcessRefundInfo() throws Exception { + public void automaticProcessRefundInfo() { log.info("开始执行关闭退款状态定时任务........"); refundInfoTaskService.automaticProcessRefundInfo(); log.info("完成关闭退款状态定时任务........");