From 81e434127603db109b89264975eb35d6149dbbf2 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Wed, 29 Jan 2025 23:48:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=89=E5=8D=A1=E6=8B=89=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/pay/service/LakalaService.java | 12 -- .../pay/service/impl/LakalaServiceImpl.java | 145 +----------------- .../service/impl/PayUserPayServiceImpl.java | 38 +++-- .../suisung/mall/pay/utils/LakalaUtil.java | 87 +++++++++-- 4 files changed, 104 insertions(+), 178 deletions(-) diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/LakalaService.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/LakalaService.java index e25be858..d3aceaa5 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/LakalaService.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/LakalaService.java @@ -17,18 +17,6 @@ import javax.servlet.http.HttpServletResponse; public interface LakalaService { - /** - * 初始化拉卡拉支付参数 - */ - void doInit(); - - /** - * 初始化微信V3支付参数 - * - * @return - */ - NativePayService initWxV3SDK(); - JSONObject transPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId); /** diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaServiceImpl.java index d8e4ebd9..21e3c907 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaServiceImpl.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaServiceImpl.java @@ -13,167 +13,37 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.ijpay.core.kit.IpKit; -import com.lkl.laop.sdk.Config2; import com.lkl.laop.sdk.LKLSDK; import com.lkl.laop.sdk.exception.SDKException; import com.lkl.laop.sdk.request.V3LabsTransPreorderRequest; import com.lkl.laop.sdk.request.model.V3LabsTradeLocationInfo; import com.lkl.laop.sdk.request.model.V3LabsTradePreorderWechatBus; import com.suisung.mall.common.exception.ApiException; -import com.suisung.mall.common.pojo.res.PayAccRespFieldsRes; import com.suisung.mall.common.utils.I18nUtil; import com.suisung.mall.pay.service.LakalaService; -import com.wechat.pay.java.core.exception.ServiceException; +import com.suisung.mall.pay.utils.LakalaUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Base64; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; - -import com.wechat.pay.java.core.Config; -import com.wechat.pay.java.core.RSAAutoCertificateConfig; -import com.wechat.pay.java.service.payments.nativepay.NativePayService; -import com.wechat.pay.java.service.payments.nativepay.model.Amount; -import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest; -import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.Signature; -import java.security.SignatureException; -import java.security.cert.*; @Slf4j @Service public class LakalaServiceImpl implements LakalaService { - private static volatile boolean init = false; - private static volatile NativePayService wxV3Service= null; - - /** - * 服务地址 - */ - @Value("${lakala.server_url}") - private String serverUrl; - @Value("${lakala.app_id}") - private String appId; // 拉卡拉appId - @Value("${lakala.merchant_no}") - private String merchantNo; - @Value("${lakala.serial_no}") - private String serialNo; // 你的证书序列号 - @Value("${lakala.term_no}") - private String termNo; - /** - * 商户私钥信息地址 - */ - @Value("${lakala.api_pri_key_path}") - private String priKeyPath; - /** - * 拉卡拉支付平台证书地址 - */ - @Value("${lakala.lkl_platform_cer_path}") - private String lklCerPath; - /** - * 拉卡拉支付平台证书地址2(用于拉卡拉通知验签) - */ - @Value("${lakala.lkl_platform_cer_path}") - private String lklNotifyCerPath; - - - /*** - * @Description: 初始化设置商户公共参数(全局只需设置一次) - * @throws Exception - */ - public void doInit() { - if (!init) { - init = initLKLSDK(); - } - } - - /** - * 读取证书文件内容 - * - * @param fileName - * @return - */ - private String getResourceFile(String fileName) { - StringBuilder stringBuilder = new StringBuilder(); - try (InputStream inputStream = new ClassPathResource(fileName).getInputStream(); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { - String line; - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line).append("\n"); - } - String content = stringBuilder.toString(); - // log.info("证书内容:{}", content); - return content; - } catch (IOException e) { - // 记录异常信息 - log.error(e.getMessage()); - return ""; - } - } - - /** - * 初始化 拉卡拉 SDK - * - * @return - */ - public boolean initLKLSDK() { - Config2 config = new Config2(); - config.setAppId(appId); - config.setSerialNo(serialNo); - config.setPriKey(getResourceFile(priKeyPath)); - config.setLklCer(getResourceFile(lklCerPath)); - config.setLklNotifyCer(getResourceFile(lklNotifyCerPath)); - config.setServerUrl(serverUrl); - return LKLSDK.init(config); - } - - @Override - public NativePayService initWxV3SDK() { - if (wxV3Service!=null) { - return wxV3Service; - } - - Config config = - new RSAAutoCertificateConfig.Builder() - .merchantId("1684833481") - .privateKey(getResourceFile("payKey/wx/apiclient_key.pem")) - .privateKeyFromPath("privateKeyPath") - .merchantSerialNumber("30314B93B394352C6A4616B7611C23402041ADE2") - .apiV3Key("n8tgyMKKAov9lVJuczMOLUjXr5IeZjce") - .build(); - // 构建service - NativePayService service = new NativePayService.Builder().config(config).build(); - if(service==null){ - throw new ApiException(I18nUtil._("微信SDKV3初始化失败!")); - } - - wxV3Service = service; - return service; - } @Override public cn.hutool.json.JSONObject transPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId) { // 1. 配置初始化 - doInit(); + LakalaUtil.doInit(); //2. 装配数据 /*** 微信主扫场景示例 */ V3LabsTransPreorderRequest v3LabsTransPreorderWechatReq = new V3LabsTransPreorderRequest(); - v3LabsTransPreorderWechatReq.setMerchantNo(merchantNo); - v3LabsTransPreorderWechatReq.setTermNo(termNo); + v3LabsTransPreorderWechatReq.setMerchantNo(LakalaUtil.merchantNo); + v3LabsTransPreorderWechatReq.setTermNo(LakalaUtil.termNo); v3LabsTransPreorderWechatReq.setOutTradeNo(orderId); v3LabsTransPreorderWechatReq.setSubject("油麦菜5斤装特惠"); v3LabsTransPreorderWechatReq.setAccountType("WECHAT"); @@ -224,14 +94,13 @@ public class LakalaServiceImpl implements LakalaService { @Override public JSONObject transPreOrder(String merchantNo, String termNo, String xcxAppId, String openId, String orderId, String subject, String totalAmount, String notifyURL, String requestIP, String remark) { // 1. 配置初始化 - doInit(); + LakalaUtil.doInit(); if (StrUtil.isBlank(merchantNo)) { - merchantNo = this.merchantNo; + merchantNo = LakalaUtil.merchantNo; } - if (StrUtil.isBlank(termNo)) { - termNo = this.termNo; + termNo = LakalaUtil.termNo; } //2. 装配数据 diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java index 1e922d94..3a27f074 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java @@ -1256,7 +1256,7 @@ public class PayUserPayServiceImpl extends BaseServiceImpl params; try { - lakalaService.doInit(); + LakalaUtil.doInit(); // spring-boot 2.x 直接调用读取请求体并验签方法,返回请求体 String body = LKLSDK.notificationHandle(request); @@ -1268,8 +1268,8 @@ public class PayUserPayServiceImpl extends BaseServiceImpl tradeQueryWrapper = new QueryWrapper<>(); - tradeQueryWrapper.eq("order_id", order_id); - PayConsumeTrade trade_row_tmp = payConsumeTradeService.findOne(tradeQueryWrapper); + String orderSubject = ""; + Integer userId = 0; + // 交易模式 2直接交易:商家直接收款; 1担保交易:平台收款,平台和商家结算。 +// if (!accountBaseConfigService.getTradeModePlantform()) { + // 不可以联合支付。 + QueryWrapper tradeQueryWrapper = new QueryWrapper<>(); + tradeQueryWrapper.eq("order_id", order_id); + PayConsumeTrade trade_row_tmp = payConsumeTradeService.findOne(tradeQueryWrapper); - if(trade_row_tmp!=null) { - payment_store_id = trade_row_tmp.getStore_id(); - orderSubject = trade_row_tmp.getTrade_title(); - } + if (trade_row_tmp != null) { + payment_store_id = trade_row_tmp.getStore_id(); + orderSubject = trade_row_tmp.getTrade_title(); + userId = trade_row_tmp.getBuyer_id(); } +// } QueryWrapper channelQueryWrapper = new QueryWrapper<>(); channelQueryWrapper.eq("payment_channel_code", "lakala"); @@ -1311,6 +1314,9 @@ public class PayUserPayServiceImpl extends BaseServiceImpl getLakalaAuthorizationMap(String authorization) { @@ -165,7 +230,7 @@ public class LakalaUtil { String[] var7 = infoArr; int var8 = infoArr.length; - for(int var9 = 0; var9 < var8; ++var9) { + for (int var9 = 0; var9 < var8; ++var9) { String info = var7[var9]; if (info.contains("=")) { int fpos = info.indexOf("=");