KKSU
2024-09-10 f52cfc92db48d9a215d7f728ce4000de1cdd6ae2
src/main/java/cc/mrbird/febs/pay/service/impl/NBYHServiceImpl.java
@@ -1,15 +1,16 @@
package cc.mrbird.febs.pay.service.impl;
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
import cc.mrbird.febs.mall.entity.MallMemberBank;
import cc.mrbird.febs.mall.entity.MallMemberWithdraw;
import cc.mrbird.febs.mall.entity.MallMemberWithdrawMsg;
import cc.mrbird.febs.mall.mapper.MallMemberBankMapper;
import cc.mrbird.febs.mall.mapper.MallMemberWithdrawMapper;
import cc.mrbird.febs.mall.mapper.MallMemberWithdrawMsgMapper;
import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.pay.model.NBYHResponse;
import cc.mrbird.febs.pay.service.NBYHService;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -26,6 +27,7 @@
@Slf4j
@Service
@RequiredArgsConstructor
public class NBYHServiceImpl implements NBYHService {
    /**
     * 登录报文原文
@@ -38,7 +40,8 @@
    private static final String TRADE_MESSAGE_SEARCH = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><JYXH>${serialNoOld}</JYXH></ReqParam></opReq>";
    private static final String TRADE_MESSAGE_SINGLE = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><FKZH>${FKZH}</FKZH><SKZH>${SKZH}</SKZH><SKHM>${SKHM}</SKHM><JYJE>${JYJE}</JYJE><YOTU>${YOTU}</YOTU></ReqParam></opReq>";
//    private static final String TRADE_MESSAGE_SINGLE = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><FKZH>82260120102022631</FKZH><SKZH>78040122000059277</SKZH><SKHM>792311957</SKHM><JYJE>0.01</JYJE><YOTU>银企接口测试</YOTU></ReqParam></opReq>";
    private static final String TRADE_MESSAGE = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><FKZH>${FKZH}</FKZH><SKZH>${SKZH}</SKZH><SKHM>${SKHM}</SKHM><SKYH>${SKYH}</SKYH><SKSH>${SKSH}</SKSH><SKSI>${SKSI}</SKSI><JYJE>${JYJE}</JYJE><YOTU>${YOTU}</YOTU><SKHH>${SKHH}</SKHH></ReqParam></opReq>";
//    private static final String TRADE_MESSAGE = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><FKZH>${FKZH}</FKZH><SKZH>${SKZH}</SKZH><SKHM>${SKHM}</SKHM><SKYH>${SKYH}</SKYH><SKSH>${SKSH}</SKSH><SKSI>${SKSI}</SKSI><JYJE>${JYJE}</JYJE><YOTU>${YOTU}</YOTU><SKHH>${SKHH}</SKHH></ReqParam></opReq>";
    private static final String TRADE_MESSAGE = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><FKZH>${FKZH}</FKZH><SKZH>${SKZH}</SKZH><SKHM>${SKHM}</SKHM><SKYH>${SKYH}</SKYH><SKSH>${SKSH}</SKSH><SKSI>${SKSI}</SKSI><JYJE>${JYJE}</JYJE><YOTU>${YOTU}</YOTU></ReqParam></opReq>";
//   private static final String TRADE_MESSAGE = "<opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><FKZH>82260120102022631</FKZH><SKZH>6228481060643871117</SKZH><SKHM>王苏平</SKHM><SKYH>中国农业银行舟山市定海支行营业中心</SKYH><SKSH>浙江省</SKSH><SKSI>舟山市</SKSI><JYJE>0.01</JYJE><BIZH>01</BIZH><ZZLX>02</ZZLX><ZZLB>0</ZZLB><YOTU>银企接口测试</YOTU><SKHH>103342040518</SKHH></ReqParam></opReq>";
    /**
     *
@@ -109,6 +112,8 @@
     */
//    private static final String URL = "http://127.0.0.1:9080/directlink/httpAccess";
    private static final String URL = "http://n5z7ej.natappfree.cc/directlink/httpAccess";
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    /**
     * 签名ip
     */
@@ -121,7 +126,7 @@
    /**
     * 签名端口
     */
    private static final int VERIFY_PORT = 41933;
    private static final int VERIFY_PORT = 39296;
//    private static final int VERIFY_PORT = 8010;
    /**
@@ -151,6 +156,8 @@
    public static void main(String[] args) {
        try {
            InetAddress addr = InetAddress.getByName(VERIFY_IP);
            Socket socket = new Socket(addr, VERIFY_PORT);
@@ -372,10 +379,19 @@
     * @throws Exception
     */
    @SuppressWarnings("rawtypes")
    public static String executeServerHttpService(String requestData) throws Exception {
    public String executeServerHttpService(String requestData) throws Exception {
//    public static void executeServerHttpService(String serviceId, String serviceName, String serialNo,String requestData) throws Exception {
        // 处理交易的url
        java.net.URL url = new URL(URL);
        DataDictionaryCustom urlDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.BANK_TRANS_URL.getType(),
                DataDictionaryEnum.BANK_TRANS_URL.getCode()
        );
        StringBuffer urlSb = new StringBuffer();
        urlSb.append("http://");
        urlSb.append(urlDic.getValue());
        urlSb.append("/directlink/httpAccess");
        java.net.URL url = new URL(urlSb.toString());
//        java.net.URL url = new URL(URL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        if (cookies != null) {
            // 如果已登录,设置coikie
@@ -510,7 +526,7 @@
     * @throws FileNotFoundException
     * @throws IOException
     */
    public static String getRequestDataForWithDraw(String serviceId, String serviceName,MallMemberWithdraw mallMemberWithdraw,MallMemberBank mallMemberBank)
    public String getRequestDataForWithDraw(String serviceId, String serviceName,MallMemberWithdraw mallMemberWithdraw,MallMemberBank mallMemberBank)
            throws FileNotFoundException, IOException {
        StringBuffer buf = new StringBuffer();
        // 报文编码格式utf-8
@@ -522,6 +538,18 @@
        buf.append(serviceId);
        buf.append("</serviceId>");
        String reqData = "";
        DataDictionaryCustom fkzhDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.BANK_TRANS_FKZH.getType(),
                DataDictionaryEnum.BANK_TRANS_FKZH.getCode()
        );
        DataDictionaryCustom customerIdDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.BANK_TRANS_customerId.getType(),
                DataDictionaryEnum.BANK_TRANS_customerId.getCode()
        );
        DataDictionaryCustom softwareIdDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.BANK_TRANS_softwareId.getType(),
                DataDictionaryEnum.BANK_TRANS_softwareId.getCode()
        );
        if (serviceId.equals("srv001_signOn")) {
            reqData = SIGN_MESSAGE;
        } else if (serviceId.equals("srv006_singleInnerTransfer")) {
@@ -541,7 +569,7 @@
             * </opReq>
             * *
             */
            reqData = reqData.replaceFirst("\\$\\{FKZH\\}", FKZH);
            reqData = reqData.replaceFirst("\\$\\{FKZH\\}", fkzhDic.getValue());
            reqData = reqData.replaceFirst("\\$\\{SKZH\\}", mallMemberBank.getBankNo());
            reqData = reqData.replaceFirst("\\$\\{SKHM\\}", mallMemberBank.getName());
            if(mallMemberWithdraw.getRemark().equals("凭证提现")){
@@ -576,7 +604,7 @@
             */
            reqData = TRADE_MESSAGE;
            reqData = reqData.replaceFirst("\\$\\{FKZH\\}", FKZH);
            reqData = reqData.replaceFirst("\\$\\{FKZH\\}", fkzhDic.getValue());
            reqData = reqData.replaceFirst("\\$\\{SKZH\\}", mallMemberBank.getBankNo());
            reqData = reqData.replaceFirst("\\$\\{SKHM\\}", mallMemberBank.getName());
            reqData = reqData.replaceFirst("\\$\\{SKYH\\}", mallMemberBank.getBankName()+mallMemberBank.getSubbranchName());
@@ -590,7 +618,7 @@
                        mallMemberWithdraw.getAmount().subtract(mallMemberWithdraw.getAmountFee()).setScale(2, BigDecimal.ROUND_DOWN).toString());
            }
            reqData = reqData.replaceFirst("\\$\\{YOTU\\}", "跨行汇款");
            reqData = reqData.replaceFirst("\\$\\{SKHH\\}", mallMemberBank.getSkhh());
//            reqData = reqData.replaceFirst("\\$\\{SKHH\\}", mallMemberBank.getSkhh());
        }else if (serviceId.equals("srv008_transferResultInfoQuery")) {
            reqData = TRADE_MESSAGE_SEARCH;
            //原订单流水号
@@ -608,7 +636,7 @@
             * <opReq><serialNo>${serialNo}</serialNo><reqTime>${reqTime}</reqTime><ReqParam><ZHHA>${ZHHA}</ZHHA></ReqParam></opReq>
             */
            //原订单流水号
            reqData = reqData.replaceFirst("\\$\\{ZHHA\\}", FKZH);
            reqData = reqData.replaceFirst("\\$\\{ZHHA\\}", fkzhDic.getValue());
        }
//      String serialNo = String.valueOf(Math.round(Math.random() * 10000))
//            + System.currentTimeMillis();
@@ -627,10 +655,10 @@
            e.printStackTrace();
        }
        buf.append("<customerId>");
        buf.append(customerId);
        buf.append(customerIdDic.getValue());
        buf.append("</customerId>");
        buf.append("<softwareId>");
        buf.append(softwareId);
        buf.append(softwareIdDic.getValue());
        buf.append("</softwareId>");
        buf.append("<functionId>");
        buf.append(serviceId.substring(0, 6));
@@ -657,7 +685,7 @@
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String signData(String orignalData)
    public String signData(String orignalData)
            throws UnsupportedEncodingException {
        InetAddress addr = null;
        Socket socket = null;
@@ -669,9 +697,17 @@
                + "<origin_data_len>" + orignalData.getBytes("GBK").length
                + "</origin_data_len>\n" + "<origin_data>" + orignalData
                + "</origin_data>\n" + "</msg_body>\n" + "</msg>";
        DataDictionaryCustom VERIFY_IPDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.BANK_TRANS_VERIFY_IP.getType(),
                DataDictionaryEnum.BANK_TRANS_VERIFY_IP.getCode()
        );DataDictionaryCustom VERIFY_PORT_Dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.BANK_TRANS_VERIFY_PORT.getType(),
                DataDictionaryEnum.BANK_TRANS_VERIFY_PORT.getCode()
        );
        try {
            addr = InetAddress.getByName(VERIFY_IP);
            socket = new Socket(addr, VERIFY_PORT);
            addr = InetAddress.getByName(VERIFY_IPDic.getValue());
            socket = new Socket(addr, Integer.parseInt(VERIFY_PORT_Dic.getValue()));
//            InetAddress localHost = addr.getLocalHost();
//            socket = new Socket(localHost, VERIFY_PORT);
            // 发送