|
|
@@ -113,6 +113,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.hc.openapi.tool.fastjson.JSON;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
@@ -140,6 +141,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
* @date 2023-08-11
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
@EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
|
|
|
public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
@@ -698,16 +700,21 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
throw new CustomException("退款请求失败"+refund.getResp_desc());
|
|
|
}
|
|
|
} else if ("appPay".equals(fsStorePayment.getPayMode()) && "wx".equals(fsStorePayment.getPayTypeCode())) {
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsStorePayment.getPaymentId());
|
|
|
+ FsPayConfig fsPayConfig = com.alibaba.fastjson.JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
+
|
|
|
// 处理微信退款
|
|
|
- WxPayService wxPayService = getWxPayService();
|
|
|
+ WxPayService wxPayService = getWxPayService(fsPayConfig);
|
|
|
WxPayRefundRequest refundRequest = new WxPayRefundRequest();
|
|
|
refundRequest.setOutTradeNo(orderType+"-"+fsStorePayment.getPayCode());
|
|
|
refundRequest.setOutRefundNo(orderType+"-"+fsStorePayment.getPayCode());
|
|
|
refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(fsStorePayment.getPayMoney().toString()));
|
|
|
refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(fsStorePayment.getPayMoney().toString()));
|
|
|
+ log.info("微信退款入参:{}",refundRequest);
|
|
|
try {
|
|
|
WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
|
|
|
WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
|
|
|
+ log.info("微信退款出参:{}",refundQueryResult);
|
|
|
if (refundQueryResult != null && refundQueryResult.getResultCode().equals("SUCCESS")) {
|
|
|
FsStorePayment paymentMap = new FsStorePayment();
|
|
|
paymentMap.setPaymentId(fsStorePayment.getPaymentId());
|
|
|
@@ -724,9 +731,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
}
|
|
|
|
|
|
} else if ("appPay".equals(fsStorePayment.getPayMode()) && "ali".equals(fsStorePayment.getPayTypeCode())) {
|
|
|
- // 实例化客户端
|
|
|
- SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
- FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsStorePayment.getPaymentId());
|
|
|
+ FsPayConfig fsPayConfig = com.alibaba.fastjson.JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", fsPayConfig.getAliAppId(), fsPayConfig.getAliPrivateKey(), "json", "utf-8", fsPayConfig.getAliPublicKey(), "RSA2");
|
|
|
// 构造请求参数以调用接口
|
|
|
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
@@ -734,8 +740,10 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
model.setOutTradeNo(orderType+"-"+fsStorePayment.getPayCode());
|
|
|
model.setRefundAmount(fsStorePayment.getPayMoney().toString());
|
|
|
request.setBizModel(model);
|
|
|
+ log.info("支付宝请求退款入参:{}",request);
|
|
|
try {
|
|
|
AlipayTradeRefundResponse response = alipayClient.execute(request);
|
|
|
+ log.info("支付宝请求退款出参:{}",response);
|
|
|
if (response.isSuccess()) {
|
|
|
FsStorePayment paymentMap = new FsStorePayment();
|
|
|
paymentMap.setPaymentId(fsStorePayment.getPaymentId());
|
|
|
@@ -758,9 +766,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private WxPayService getWxPayService(){
|
|
|
- SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
- FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
+ private WxPayService getWxPayService(FsPayConfig fsPayConfig){
|
|
|
+
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
payConfig.setAppId(fsPayConfig.getWxAppAppId());
|
|
|
payConfig.setMchId(fsPayConfig.getWxAppMchId());
|