From 90b730c2f8d71c89ddc192f9d96251f74c302b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Mon, 9 Sep 2024 18:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=81=94=E6=94=AF=E4=BB=98=E6=8E=A5?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/pay/syb/service/ApiTestV2.java | 5 +- .../common/pay/syb/service/SybPayClient.java | 244 ++++++++++++++++ .../common/pay/syb/service/SybPayService.java | 272 ++++-------------- .../service/impl/PayBillConverterImpl.java | 2 +- .../service/impl/PayBillServiceImpl.java | 8 +- .../domain/enums/TransactionBillPayType.java | 14 +- .../service/TransactionBillValidator.java | 2 +- .../impl/TransactionBillValidatorImpl.java | 7 + .../app/AppTransactionBillController.java | 2 +- 9 files changed, 323 insertions(+), 233 deletions(-) create mode 100644 smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayClient.java diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java index f8cafd8b..c44a63de 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java @@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.math.BigDecimal; import java.util.Map; @@ -13,7 +14,7 @@ import java.util.Map; public class ApiTestV2 extends BaseController { @Autowired - private SybPayService service; + private SybPayClient service; @GetMapping("/scanPay") public AjaxResult testScanPay() throws Exception { @@ -47,7 +48,7 @@ public class ApiTestV2 extends BaseController { public AjaxResult testPay() throws Exception { String reqsn = String.valueOf(System.currentTimeMillis()); - Map map = service.pay(1, reqsn, "W06", "标题", "备注", "ol5kD7eeXNGeYE5z7uIhk12K-rBA", "123", "https://test.allinpaygd.com/JWeb/NotifyServlet", "", "", "", "", "", "", "", "", "", "", "", ""); + Map map = service.pay(1L, reqsn, "W06", "标题", "备注", "ol5kD7eeXNGeYE5z7uIhk12K-rBA", "123", "https://test.allinpaygd.com/JWeb/NotifyServlet", "", "", "", "", "", "", "", "", "", "", "", ""); return success(map); } } diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayClient.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayClient.java new file mode 100644 index 00000000..a9fc3b2c --- /dev/null +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayClient.java @@ -0,0 +1,244 @@ +package com.ruoyi.common.pay.syb.service; + +import com.alibaba.fastjson2.JSON; +import com.ruoyi.common.pay.syb.config.SybConfig; +import com.ruoyi.common.pay.syb.util.HttpConnectionUtil; +import com.ruoyi.common.pay.syb.util.SybUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Map; +import java.util.TreeMap; + +@Component +public class SybPayClient { + + @Autowired + private SybConfig sybConfig; + + + + /** + * + * @param trxamt + * @param reqsn + * @param paytype + * @param body + * @param remark + * @param acct + * @param validtime + * @param notify_url + * @param limit_pay + * @param idno + * @param truename + * @param asinfo + * @param sub_appid + * @param goods_tag 单品优惠信息 + * @param chnlstoreid + * @param subbranch + * @param cusip 限云闪付JS支付业务 + * @param fqnum 限支付宝分期业务 + * @return + * @throws Exception + */ + public Map pay(long trxamt, String reqsn, String paytype, String body, String remark, String acct, String validtime, String notify_url, String limit_pay, + String idno, String truename, String asinfo, String sub_appid, String goods_tag, String benefitdetail, String chnlstoreid, String subbranch, String extendparams, String cusip, String fqnum) throws Exception{ + HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/pay"); + http.init(); + TreeMap params = new TreeMap(); + if(!SybUtil.isEmpty(sybConfig.getOrgId())) { + params.put("orgid", sybConfig.getOrgId()); + } + params.put("cusid", sybConfig.getCusId()); + params.put("appid", sybConfig.getAppId()); + params.put("version", "11"); + params.put("trxamt", String.valueOf(trxamt)); + params.put("reqsn", reqsn); + params.put("paytype", paytype); + params.put("randomstr", SybUtil.getValidatecode(8)); + params.put("body", body); + params.put("remark", remark); + params.put("validtime", validtime); + params.put("acct", acct); + params.put("notify_url", notify_url); + params.put("limit_pay", limit_pay); + params.put("sub_appid", sub_appid); + params.put("goods_tag", goods_tag); + params.put("benefitdetail", benefitdetail); + params.put("chnlstoreid", chnlstoreid); + params.put("subbranch", subbranch); + params.put("extendparams", extendparams); + params.put("cusip", cusip); + params.put("fqnum", fqnum); + params.put("idno", idno); + params.put("truename", truename); + params.put("asinfo", asinfo); + params.put("signtype", sybConfig.getSignType()); + String appkey = ""; + if(sybConfig.getSignType().equals("RSA")) { + appkey = sybConfig.getRsaCusPriKey(); + } else if(sybConfig.getSignType().equals("SM2")) { + appkey = sybConfig.getSm2CusPriKey(); + } else { + appkey = sybConfig.getMd5AppKey(); + } + params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); + byte[] bys = http.postParams(params, true); + String result = new String(bys,"UTF-8"); + Map map = handleResult(result); + return map; + + } + + public Map cancel(long trxamt,String reqsn,String oldtrxid,String oldreqsn) throws Exception{ + HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/cancel"); + http.init(); + TreeMap params = new TreeMap(); + if(!SybUtil.isEmpty(sybConfig.getOrgId())) + params.put("orgid", sybConfig.getOrgId()); + params.put("cusid", sybConfig.getCusId()); + params.put("appid", sybConfig.getAppId()); + params.put("version", "11"); + params.put("trxamt", String.valueOf(trxamt)); + params.put("reqsn", reqsn); + params.put("oldtrxid", oldtrxid); + params.put("oldreqsn", oldreqsn); + params.put("randomstr", SybUtil.getValidatecode(8)); + params.put("signtype", sybConfig.getSignType()); + String appkey = ""; + if(sybConfig.getSignType().equals("RSA")) + appkey = sybConfig.getRsaCusPriKey(); + else if(sybConfig.getSignType().equals("SM2")) + appkey = sybConfig.getSm2CusPriKey(); + else + appkey = sybConfig.getMd5AppKey(); + params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); + byte[] bys = http.postParams(params, true); + String result = new String(bys,"UTF-8"); + Map map = handleResult(result); + return map; + } + + public Map refund(long trxamt,String reqsn,String oldtrxid,String oldreqsn) throws Exception{ + HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/refund"); + http.init(); + TreeMap params = new TreeMap(); + if(!SybUtil.isEmpty(sybConfig.getOrgId())) + params.put("orgid", sybConfig.getOrgId()); + params.put("cusid", sybConfig.getCusId()); + params.put("appid", sybConfig.getAppId()); + params.put("version", "11"); + params.put("trxamt", String.valueOf(trxamt)); + params.put("reqsn", reqsn); + params.put("oldreqsn", oldreqsn); + params.put("oldtrxid", oldtrxid); + params.put("randomstr", SybUtil.getValidatecode(8)); + params.put("signtype", sybConfig.getSignType()); + String appkey = ""; + if(sybConfig.getSignType().equals("RSA")) + appkey = sybConfig.getRsaCusPriKey(); + else if(sybConfig.getSignType().equals("SM2")) + appkey = sybConfig.getSm2CusPriKey(); + else + appkey = sybConfig.getMd5AppKey(); + params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); + byte[] bys = http.postParams(params, true); + String result = new String(bys,"UTF-8"); + Map map = handleResult(result); + return map; + } + + public Map query(String reqsn,String trxid) throws Exception{ + HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/query"); + http.init(); + TreeMap params = new TreeMap(); + if(!SybUtil.isEmpty(sybConfig.getOrgId())) + params.put("orgid", sybConfig.getOrgId()); + params.put("cusid", sybConfig.getCusId()); + params.put("appid", sybConfig.getAppId()); + params.put("version", "11"); + params.put("reqsn", reqsn); + params.put("trxid", trxid); + params.put("randomstr", SybUtil.getValidatecode(8)); + params.put("signtype", sybConfig.getSignType()); + String appkey = ""; + if(sybConfig.getSignType().equals("RSA")) + appkey = sybConfig.getRsaCusPriKey(); + else if(sybConfig.getSignType().equals("SM2")) + appkey = sybConfig.getSm2CusPriKey(); + else + appkey = sybConfig.getMd5AppKey(); + params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); + byte[] bys = http.postParams(params, true); + String result = new String(bys,"UTF-8"); + Map map = handleResult(result); + return map; + } + + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Map handleResult(String result) throws Exception{ + System.out.println("ret:"+result); + Map map = JSON.parseObject(result, Map.class); + if(map == null){ + throw new Exception("返回数据错误"); + } + if("SUCCESS".equals(map.get("retcode"))){ + TreeMap tmap = new TreeMap(); + tmap.putAll(map); + String appkey = ""; + if(sybConfig.getSignType().equals("RSA")) + appkey = sybConfig.getRsaTlPubKey(); + else if(sybConfig.getSignType().equals("SM2")) + appkey = sybConfig.getSm2TlPubKey(); + else + appkey = sybConfig.getMd5AppKey(); + if(SybUtil.validSign(tmap, appkey, sybConfig.getSignType())){ + System.out.println("签名成功"); + return map; + }else{ + throw new Exception("验证签名失败"); + } + + }else{ + throw new Exception(map.get("retmsg").toString()); + } + } + + public Map scanPay(long trxamt,String reqsn,String body,String remark,String authcode,String limit_pay,String idno,String truename,String asinfo) throws Exception{ + // TODO Auto-generated method stub + HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/scanqrpay"); + http.init(); + TreeMap params = new TreeMap(); + if(!SybUtil.isEmpty(sybConfig.getOrgId())) + params.put("orgid", sybConfig.getOrgId()); + params.put("cusid", sybConfig.getCusId()); + params.put("appid", sybConfig.getAppId()); + params.put("version", "11"); + params.put("trxamt", String.valueOf(trxamt)); + params.put("reqsn", reqsn); + params.put("randomstr", SybUtil.getValidatecode(8)); + params.put("body", body); + params.put("remark", remark); + params.put("authcode", authcode); + params.put("limit_pay", limit_pay); + params.put("asinfo", asinfo); + params.put("signtype", sybConfig.getSignType()); + String appkey = ""; + if(sybConfig.getSignType().equals("RSA")) + appkey = sybConfig.getRsaCusPriKey(); + else if(sybConfig.getSignType().equals("SM2")) + appkey = sybConfig.getSm2CusPriKey(); + else + appkey = sybConfig.getMd5AppKey(); + params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); + byte[] bys = http.postParams(params, true); + String result = new String(bys,"UTF-8"); + Map map = handleResult(result); + return map; + } + + +} diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayService.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayService.java index 6fd981de..2b7c759d 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayService.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/SybPayService.java @@ -1,240 +1,64 @@ package com.ruoyi.common.pay.syb.service; import com.alibaba.fastjson2.JSON; -import com.ruoyi.common.pay.syb.config.SybConfig; -import com.ruoyi.common.pay.syb.util.HttpConnectionUtil; -import com.ruoyi.common.pay.syb.util.SybUtil; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.pay.wx.domain.Payable; +import com.ruoyi.common.utils.StringUtils; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Map; -import java.util.TreeMap; +/** + * @author wjh + * 2024/9/9 + */ @Service public class SybPayService { - @Autowired - private SybConfig sybConfig; + @Autowired + private SybPayClient sybPayClient; - /** - * - * @param trxamt - * @param reqsn - * @param paytype - * @param body - * @param remark - * @param acct - * @param validtime - * @param notify_url - * @param limit_pay - * @param idno - * @param truename - * @param asinfo - * @param sub_appid - * @param goods_tag 单品优惠信息 - * @param chnlstoreid - * @param subbranch - * @param cusip 限云闪付JS支付业务 - * @param fqnum 限支付宝分期业务 - * @return - * @throws Exception - */ - public Map pay(long trxamt,String reqsn,String paytype,String body,String remark,String acct,String validtime,String notify_url,String limit_pay, - String idno,String truename,String asinfo,String sub_appid,String goods_tag,String benefitdetail,String chnlstoreid,String subbranch,String extendparams,String cusip,String fqnum) throws Exception{ - HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/pay"); - http.init(); - TreeMap params = new TreeMap(); - if(!SybUtil.isEmpty(sybConfig.getOrgId())) { - params.put("orgid", sybConfig.getOrgId()); - } - params.put("cusid", sybConfig.getCusId()); - params.put("appid", sybConfig.getAppId()); - params.put("version", "11"); - params.put("trxamt", String.valueOf(trxamt)); - params.put("reqsn", reqsn); - params.put("paytype", paytype); - params.put("randomstr", SybUtil.getValidatecode(8)); - params.put("body", body); - params.put("remark", remark); - params.put("validtime", validtime); - params.put("acct", acct); - params.put("notify_url", notify_url); - params.put("limit_pay", limit_pay); - params.put("sub_appid", sub_appid); - params.put("goods_tag", goods_tag); - params.put("benefitdetail", benefitdetail); - params.put("chnlstoreid", chnlstoreid); - params.put("subbranch", subbranch); - params.put("extendparams", extendparams); - params.put("cusip", cusip); - params.put("fqnum", fqnum); - params.put("idno", idno); - params.put("truename", truename); - params.put("asinfo", asinfo); - params.put("signtype", sybConfig.getSignType()); - String appkey = ""; - if(sybConfig.getSignType().equals("RSA")) { - appkey = sybConfig.getRsaCusPriKey(); - } else if(sybConfig.getSignType().equals("SM2")) { - appkey = sybConfig.getSm2CusPriKey(); - } else { - appkey = sybConfig.getMd5AppKey(); - } - params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); - byte[] bys = http.postParams(params, true); - String result = new String(bys,"UTF-8"); - Map map = handleResult(result); - return map; + /** + * 微信小程序预下单 + */ + public PrepayWithRequestPaymentResponse prepayWxApp(Payable payable) { + try { + Map result = sybPayClient.pay( + payable.payableMoney().longValue(), + payable.payableOutTradeNo(), + "W06", + payable.payableDescription(), + payable.payableDescription(), + payable.payableOpenId(), + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + ); - } - - public Map cancel(long trxamt,String reqsn,String oldtrxid,String oldreqsn) throws Exception{ - HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/cancel"); - http.init(); - TreeMap params = new TreeMap(); - if(!SybUtil.isEmpty(sybConfig.getOrgId())) - params.put("orgid", sybConfig.getOrgId()); - params.put("cusid", sybConfig.getCusId()); - params.put("appid", sybConfig.getAppId()); - params.put("version", "11"); - params.put("trxamt", String.valueOf(trxamt)); - params.put("reqsn", reqsn); - params.put("oldtrxid", oldtrxid); - params.put("oldreqsn", oldreqsn); - params.put("randomstr", SybUtil.getValidatecode(8)); - params.put("signtype", sybConfig.getSignType()); - String appkey = ""; - if(sybConfig.getSignType().equals("RSA")) - appkey = sybConfig.getRsaCusPriKey(); - else if(sybConfig.getSignType().equals("SM2")) - appkey = sybConfig.getSm2CusPriKey(); - else - appkey = sybConfig.getMd5AppKey(); - params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); - byte[] bys = http.postParams(params, true); - String result = new String(bys,"UTF-8"); - Map map = handleResult(result); - return map; - } - - public Map refund(long trxamt,String reqsn,String oldtrxid,String oldreqsn) throws Exception{ - HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/refund"); - http.init(); - TreeMap params = new TreeMap(); - if(!SybUtil.isEmpty(sybConfig.getOrgId())) - params.put("orgid", sybConfig.getOrgId()); - params.put("cusid", sybConfig.getCusId()); - params.put("appid", sybConfig.getAppId()); - params.put("version", "11"); - params.put("trxamt", String.valueOf(trxamt)); - params.put("reqsn", reqsn); - params.put("oldreqsn", oldreqsn); - params.put("oldtrxid", oldtrxid); - params.put("randomstr", SybUtil.getValidatecode(8)); - params.put("signtype", sybConfig.getSignType()); - String appkey = ""; - if(sybConfig.getSignType().equals("RSA")) - appkey = sybConfig.getRsaCusPriKey(); - else if(sybConfig.getSignType().equals("SM2")) - appkey = sybConfig.getSm2CusPriKey(); - else - appkey = sybConfig.getMd5AppKey(); - params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); - byte[] bys = http.postParams(params, true); - String result = new String(bys,"UTF-8"); - Map map = handleResult(result); - return map; - } - - public Map query(String reqsn,String trxid) throws Exception{ - HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/query"); - http.init(); - TreeMap params = new TreeMap(); - if(!SybUtil.isEmpty(sybConfig.getOrgId())) - params.put("orgid", sybConfig.getOrgId()); - params.put("cusid", sybConfig.getCusId()); - params.put("appid", sybConfig.getAppId()); - params.put("version", "11"); - params.put("reqsn", reqsn); - params.put("trxid", trxid); - params.put("randomstr", SybUtil.getValidatecode(8)); - params.put("signtype", sybConfig.getSignType()); - String appkey = ""; - if(sybConfig.getSignType().equals("RSA")) - appkey = sybConfig.getRsaCusPriKey(); - else if(sybConfig.getSignType().equals("SM2")) - appkey = sybConfig.getSm2CusPriKey(); - else - appkey = sybConfig.getMd5AppKey(); - params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); - byte[] bys = http.postParams(params, true); - String result = new String(bys,"UTF-8"); - Map map = handleResult(result); - return map; - } - - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Map handleResult(String result) throws Exception{ - System.out.println("ret:"+result); - Map map = JSON.parseObject(result, Map.class); - if(map == null){ - throw new Exception("返回数据错误"); - } - if("SUCCESS".equals(map.get("retcode"))){ - TreeMap tmap = new TreeMap(); - tmap.putAll(map); - String appkey = ""; - if(sybConfig.getSignType().equals("RSA")) - appkey = sybConfig.getRsaTlPubKey(); - else if(sybConfig.getSignType().equals("SM2")) - appkey = sybConfig.getSm2TlPubKey(); - else - appkey = sybConfig.getMd5AppKey(); - if(SybUtil.validSign(tmap, appkey, sybConfig.getSignType())){ - System.out.println("签名成功"); - return map; - }else{ - throw new Exception("验证签名失败"); - } - - }else{ - throw new Exception(map.get("retmsg").toString()); - } - } - - public Map scanPay(long trxamt,String reqsn,String body,String remark,String authcode,String limit_pay,String idno,String truename,String asinfo) throws Exception{ - // TODO Auto-generated method stub - HttpConnectionUtil http = new HttpConnectionUtil(sybConfig.getApiUrl()+"/scanqrpay"); - http.init(); - TreeMap params = new TreeMap(); - if(!SybUtil.isEmpty(sybConfig.getOrgId())) - params.put("orgid", sybConfig.getOrgId()); - params.put("cusid", sybConfig.getCusId()); - params.put("appid", sybConfig.getAppId()); - params.put("version", "11"); - params.put("trxamt", String.valueOf(trxamt)); - params.put("reqsn", reqsn); - params.put("randomstr", SybUtil.getValidatecode(8)); - params.put("body", body); - params.put("remark", remark); - params.put("authcode", authcode); - params.put("limit_pay", limit_pay); - params.put("asinfo", asinfo); - params.put("signtype", sybConfig.getSignType()); - String appkey = ""; - if(sybConfig.getSignType().equals("RSA")) - appkey = sybConfig.getRsaCusPriKey(); - else if(sybConfig.getSignType().equals("SM2")) - appkey = sybConfig.getSm2CusPriKey(); - else - appkey = sybConfig.getMd5AppKey(); - params.put("sign", SybUtil.unionSign(params,appkey,sybConfig.getSignType())); - byte[] bys = http.postParams(params, true); - String result = new String(bys,"UTF-8"); - Map map = handleResult(result); - return map; - } + if (result != null) { + String payInfo = result.get("payinfo"); + if (StringUtils.hasText(payInfo)) { + return JSON.parseObject(payInfo, PrepayWithRequestPaymentResponse.class); + } + } + return null; + } catch(Exception e) { + throw new ServiceException("调起支付失败:" + e.getMessage()); + } + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillConverterImpl.java index a7b207fc..9017e9d4 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillConverterImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillConverterImpl.java @@ -110,7 +110,7 @@ public class PayBillConverterImpl implements PayBillConverter { po.setChannelCost(this.calcChannelCost(channel, order.getMoney())); // 支付人 - if (TransactionBillPayType.WECHAT.getType().equals(channel.getChannelId())) { + if (TransactionBillPayType.wxList().contains(channel.getChannelId())) { po.setAccount(user.getWxOpenId()); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java index dd2e603d..40165eaa 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java @@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit; import com.ruoyi.common.core.redis.RedisLock; import com.ruoyi.common.core.redis.enums.RedisLockKey; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.pay.syb.service.SybPayService; import com.ruoyi.common.pay.wx.util.WxPayUtil; import com.ruoyi.common.pay.yst.service.YstPayService; import com.ruoyi.common.utils.DateUtils; @@ -78,7 +79,7 @@ public class PayBillServiceImpl implements PayBillService private PayBillConverter payBillConverter; @Autowired - private YstPayService ystPayService; + private SybPayService sybPayService; /** * 查询支付订单 @@ -156,6 +157,7 @@ public class PayBillServiceImpl implements PayBillService @Override public DoPayVO createPayBill(PayBill bill) { + ServiceUtil.assertion(bill == null, "待新增的支付订单不存在"); // 锁 String lockKey = bill.getBstType() + bill.getBstId(); if (!redisLock.lock(RedisLockKey.PAY_BILL, lockKey)) { @@ -291,8 +293,8 @@ public class PayBillServiceImpl implements PayBillService } else { if (TransactionBillPayType.WECHAT.getType().equals(bill.getChannelId())) { vo.setPayParams(wxPayService.prepayWithRequestPayment(bill)); - } else if (TransactionBillPayType.YST_WX.getType().equals(bill.getChannelId())) { - vo.setPayParams(ystPayService.prepayWx(bill)); + } else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) { + vo.setPayParams(sybPayService.prepayWxApp(bill)); } else { throw new ServiceException("暂不支持该支付方式"); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillPayType.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillPayType.java index 9719efc6..c5541fc6 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillPayType.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillPayType.java @@ -4,8 +4,12 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.ss.account.domain.enums.AccountType; import lombok.AllArgsConstructor; import lombok.Getter; +import nonapi.io.github.classgraph.utils.LogNode; +import java.util.Arrays; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * 支付方式(打款方式) @@ -20,7 +24,7 @@ public enum TransactionBillPayType { ALI(2L, "支付宝", AccountType.ALIPAY), BANK(3L, "银行卡", AccountType.BANK_CARD), BALANCE(4L, "余额支付", null), - YST_WX(5L, "通联微信支付", null) + TL_WX(5L, "通联微信支付", null) ; private final Long type; @@ -35,4 +39,12 @@ public enum TransactionBillPayType { } throw new ServiceException("不存在值为" + type + "的支付方式(打款方式)"); } + + public static List asList(TransactionBillPayType ...types) { + return Arrays.stream(types).map(TransactionBillPayType::getType).collect(Collectors.toList()); + } + + public static List wxList() { + return asList(WECHAT, TL_WX); + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillValidator.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillValidator.java index ad699ecb..e5a6ac1f 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillValidator.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillValidator.java @@ -46,7 +46,7 @@ public interface TransactionBillValidator { boolean isUser(TransactionBillVO bill, Long userId); /** - * 微信支付前校验 + * 支付前校验 */ ValidateResult prePay(RechargePayBO bo); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java index 2c8dcaf6..5cc1a24d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java @@ -261,6 +261,13 @@ public class TransactionBillValidatorImpl extends BaseValidator implements Trans if (!TransactionBillType.RECHARGE.getType().equals(order.getType())) { return error("只能支付充值订单"); } + ChannelVO channel = bo.getChannel(); + if (channel == null) { + return error("支付渠道不存在"); + } + if (channel.getEnabled() == null || !channel.getEnabled()) { + return error("支付渠道暂不可用"); + } return success(); } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java index 8eaca52a..e37e8f11 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java @@ -335,7 +335,7 @@ public class AppTransactionBillController extends BaseController @PutMapping("/pay") public AjaxResult pay(@RequestBody BillPayDTO dto) { TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillNo(dto.getBillNo()); - if (transactionBillValidator.isUser(bill, getUserId())) { + if (!transactionBillValidator.isUser(bill, getUserId())) { return error("这不是您的订单,无法支付"); } RechargePayBO bo = transactionBillConverter.toRechargePayBO(bill, dto.getChannelId());