教育训练处考试制证系统后端
heheng
2025-02-19 b6557d2be3ae385d15af640aa184ca7f8711f42a
测试
已修改3个文件
306 ■■■■ 文件已修改
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java 254 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
exam-system/src/main/java/com/gkhy/exam/pay/utils/SignatureFileVo.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java
@@ -63,7 +63,7 @@
        String lockKey = NON_COAL_PAY_STUDENT_LOCK + dataId + "_PAY_TYPE_" + payType;
        Boolean b = redisLock.tryLock(lockKey, 10, 20, TimeUnit.SECONDS);
        Boolean b = redisLock.tryLock(lockKey, 30, 40, TimeUnit.SECONDS);
        if (b) {
            String orderNo = RandomUtil.generateOrderNumber(dataId, "NC");
            List<NonCoalPayOrder> nonCoalPayOrders = nonCoalPayMapper.selectNonCoalPayOrderByParam(dataId, Long.valueOf(payType));
@@ -87,24 +87,24 @@
                return nonCoalStuRep.getOrderId();
            }
            //财政缴款码未生成
            if (nonCoalStuRep.getPayStatus() == 0) {
                if ("1".equals(payType)) {
                    baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                            .set(NonCoalPayStudent::getOrderNo, orderNo)
                            .set(NonCoalPayStudent::getGovPayStatus, 1)
                            .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
                            .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
                } else {
                    //团体缴费
                    baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                            .set(NonCoalPayStudent::getOrderNo, orderNo)
                            .set(NonCoalPayStudent::getGovPayStatus, 1)
                            .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
                            .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
                }
            } else {
                orderNo = nonCoalStuRep.getOrderNo();
            }
//            if (nonCoalStuRep.getPayStatus() == 0) {
//                if ("1".equals(payType)) {
//                    baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
//                            .set(NonCoalPayStudent::getOrderNo, orderNo)
//                            .set(NonCoalPayStudent::getGovPayStatus, 1)
//                            .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
//                            .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
//                } else {
//                    //团体缴费
//                    baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
//                            .set(NonCoalPayStudent::getOrderNo, orderNo)
//                            .set(NonCoalPayStudent::getGovPayStatus, 1)
//                            .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
//                            .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
//                }
//            } else {
//                orderNo = nonCoalStuRep.getOrderNo();
//            }
            List<NonCoalCateRep> nonCoalPayCategoryList = nonCoalPayOrder.getNonCoalPayCategoryList();
            if (StringUtils.isEmpty(nonCoalPayCategoryList)) {
@@ -115,7 +115,7 @@
            PayReqData payReqData = dealData(nonCoalPayOrder, orderNo, payType);
            try {
                ResultVo resultVo = payUtils.sendApiPost(payReqData);
                ResultVo resultVo = payUtils.faqiV2(payReqData);
                log.info("调用接口返回结果:" + resultVo);
                if (resultVo.getRespcode().equals("BUS0000")) {
                    String orderId = resultVo.getRespdata().getOrderId();
@@ -125,16 +125,18 @@
                        if ("1".equals(payType)) {
                            baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                                    .set(NonCoalPayStudent::getOrderId, orderId)
//                                    .set(NonCoalPayStudent::getOrderNo, orderNo)
                                    .set(NonCoalPayStudent::getOrderNo, orderNo)
                                    .set(NonCoalPayStudent::getPayCode, billNo)
                                    .set(NonCoalPayStudent::getGovPayStatus, 2)
                                    .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
                                    .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
                        } else {
                            //团体缴费
                            baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
                                    .set(NonCoalPayStudent::getOrderId, orderId)
//                                    .set(NonCoalPayStudent::getOrderNo, orderNo)
                                    .set(NonCoalPayStudent::getOrderNo, orderNo)
                                    .set(NonCoalPayStudent::getPayCode, billNo)
                                    .set(NonCoalPayStudent::getGovPayStatus, 2)
                                    .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0)
                                    .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0));
                        }
@@ -418,7 +420,7 @@
                    stu1.setPhone(stu.getPhone());
//                    stu1.setOrderNo(RandomUtil.generateOrderNumber());
                    stu1.setSex(StudentSex.BOY.getStatus().equals(stu.getSex().trim()) ? 0L : 1L);
                    stu1.setSex(StudentSex.BOY.getDesc().equals(stu.getSex().trim()) ? 0L : 1L);
                    nonCoalPayStudentMapper.insertNonCoalPayStudent(stu1);
                    successNum++;
                    successMsg.append("<br/>" + successNum + "、身份证号 " + stu.getIdCard() + " 导入成功");
exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java
@@ -5,8 +5,8 @@
import cn.com.jit.mof.bean.MOFVerifyResult;
import cn.com.jit.new_vstk.AdvanceSignClient;
import cn.com.jit.new_vstk.Bean.*;
import cn.com.jit.new_vstk.SignClient;
import cn.com.jit.new_vstk.exception.NewCSSException;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.gkhy.exam.pay.entity.PayReqData;
import lombok.extern.slf4j.Slf4j;
@@ -42,6 +42,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -49,6 +50,7 @@
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.*;
@@ -85,6 +87,7 @@
    /**
     * 请求开票,发起支付
     *
     * @param payReqData
     * @return
     * @throws IOException
@@ -394,6 +397,247 @@
        return resultVo;
    }
    public ResultVo faqiV2(PayReqData payReqData) {
        System.out.println("发起接到参数===" + payReqData.toString());
        String reqdatastr = JSONObject.toJSONString(payReqData);
        String mac = this.getMD5("A1749891493E4CDDBFE4506357B1F0AB||" + this.getBase64(reqdatastr));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("appid", "A1749891493E4CDDBFE4506357B1F0AB");
        jsonObject.put("mac", mac);
        jsonObject.put("reqdata", this.getBase64(reqdatastr));
        Map<String, String> header = new HashMap();
        header.put("Accept", "application/json;charset=utf-8");
        header.put("Content-Type", "application/json;charset=utf-8");
        String resultStr = HttpUtil.post("http://finpt.xjcz.gov.cn/fs-service/fs-pay/invoice.do ", jsonObject);
        System.out.println("发起入参===" + jsonObject);
        JSONObject result = JSONObject.parseObject(resultStr);
        ResultVo resultVo = JSONObject.parseObject(resultStr, ResultVo.class);
        System.out.println("发起回参===" + result);
        result.put("postData", reqdatastr);
        JSONObject jsonObject2 = result.getJSONObject("respdata");
        String signfile = jsonObject2.getString("fileData");
        String orderNo1 = jsonObject2.getString("orderNo");
        String xmlFilePath = "F:/files/" + orderNo1 + ".xml";
        generateBase64StringToFile(signfile, xmlFilePath);
        String trr2 = "";
        try {
            File file = new File(xmlFilePath);
            FileReader reader1 = new FileReader(file);
            BufferedReader bReader = new BufferedReader(reader1);
            StringBuilder sb = new StringBuilder();
            String s = "";
            while ((s = bReader.readLine()) != null) {
                sb.append(s);
            }
            bReader.close();
            trr2 = sb.toString();
        } catch (Exception var34) {
            Exception e = var34;
            e.printStackTrace();
        }
        String jmsignfile = this.signFilejdnew(trr2);
        String zuizhongpath = montageXmlV3(xmlFilePath, jmsignfile);
        String zzsignfile = convertFileToBase64(zuizhongpath);
        this.uploadXmlV2(orderNo1, zzsignfile);
        File file = new File(xmlFilePath);
        file.delete();
        File file1 = new File(zuizhongpath);
        file1.delete();
        return resultVo;
    }
    public static String montageXmlV3(String ywfilePath, String xmlStr) {
        try {
            String outputxmlpath = ywfilePath.replace(".xml", "_3.xml");
            xmlStr = xmlStr.trim().replace("\n", "");
            FileWriter writer = new FileWriter(outputxmlpath);
            writer.write(xmlStr);
            writer.close();
            return outputxmlpath;
        } catch (Exception var4) {
            Exception e = var4;
            e.printStackTrace();
            return null;
        }
    }
    public static String convertFileToBase64(String imgPath) {
        byte[] data = null;
        try {
            InputStream in = new FileInputStream(imgPath);
            data = new byte[((InputStream) in).available()];
            ((InputStream) in).read(data);
            ((InputStream) in).close();
        } catch (IOException var4) {
            IOException e = var4;
            e.printStackTrace();
        }
        BASE64Encoder encoder = new BASE64Encoder();
        String base64Str = encoder.encode(data);
        return base64Str;
    }
    public static boolean generateBase64StringToFile(String fileStr, String fileFilePath) {
        if (fileStr == null) {
            return false;
        } else {
            try {
                byte[] b = org.apache.commons.codec.binary.Base64.decodeBase64(fileStr);
                for (int i = 0; i < b.length; ++i) {
                    if (b[i] < 0) {
                        b[i] = (byte) (b[i] + 256);
                    }
                }
                OutputStream out = new FileOutputStream(fileFilePath);
                ((OutputStream) out).write(b);
                ((OutputStream) out).flush();
                ((OutputStream) out).close();
                return true;
            } catch (Exception var4) {
                return false;
            }
        }
    }
    public String signFilejdnew(String plain) {
        BillSign sign = new BillSign(new ISignCommond() {
            @Override
            public SignDto signSm3Detach(String plain) {
                SignDto dto = null;
                try {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("data", plain);
                    JSONObject Result = signFileV2(jsonObject);
                    dto = new SignDto(Result.getJSONObject("content").getDate("signTime"), Result.getJSONObject("content").getString("signResult"), "CN=Private Certificate Authority Of MOF SM2,O=MOF,C=CN", "142FA2FA197E349C");
                } catch (Exception var5) {
                    Exception exception = var5;
                    exception.printStackTrace();
                }
                return dto;
            }
        });
        try {
            String xx = sign.signBill(plain);
            return xx;
        } catch (Exception var4) {
            var4.printStackTrace();
            return null;
        }
    }
    public JSONObject signFileV2(JSONObject job) throws Exception {
        JSONObject xysfResult = new JSONObject();
        String certId = "11650000MB1957293J";
        String plain = job.getString("data").trim();
        MOFSignResult result = null;
        Map<String, Object> mmp = new HashMap();
        try {
            String filePath = "F:/cssconfig.properties";
            System.out.println("配置文件路径:" + filePath);
            MOFClient client = new MOFClient(filePath);
            System.out.println("证书标识为:" + certId);
            System.out.println("待签名数据:" + plain);
            result = client.sign(certId, plain.getBytes(StandardCharsets.UTF_8));
            System.out.println("签名返回结果:" + JSONObject.toJSONString(result));
            byte[] signData = result.getSignData();
            String base64Str = new String(cn.com.jit.ida.util.pki.encoders.Base64.encode(signData));
            mmp.put("signResult", base64Str);
            MOFVerifyResult resultVer = client.verifySign(signData, plain.getBytes(StandardCharsets.UTF_8));
            System.out.println("验签结果为:" + JSONObject.toJSONString(resultVer));
            mmp.put("issure", resultVer.getIssure());
            mmp.put("sn", resultVer.getSn());
            mmp.put("signTime", resultVer.getSignTime());
            xysfResult.put("success", true);
            xysfResult.put("content", mmp);
            return xysfResult;
        } catch (NewCSSException var12) {
            NewCSSException e = var12;
            System.out.println("****签名失败****");
            System.out.println("错误号为:" + e.getCode());
            System.out.println("错误描述为:" + e.getDescription());
            xysfResult.put("success", false);
            xysfResult.put("msg", "系统错误");
            return xysfResult;
        }
    }
    public ResultVo uploadXmlV2(String orderId, String plain) {
        Map<String, String> params = new HashMap<>();
        String appid = "A1749891493E4CDDBFE4506357B1F0AB";
        String orderUrl = "http://finpt.xjcz.gov.cn/fs-service/fs-pay/uploadXml.do";
        SignatureFileVo signatureFile = new SignatureFileVo();
        signatureFile.setFileData(plain);
        signatureFile.setOrderNo(orderId);
        String reqdata = getBase64(signatureFile.toString());
        String mac = appid + "||" + reqdata;
        mac = DigestUtils.md5Hex(mac.getBytes());
        params.put("appid", appid);
        params.put("reqdata", reqdata);
        params.put("mac", mac);
        HttpPost httpPost = new HttpPost(orderUrl);
        httpPost.setEntity(assemblyFormEntity(params, "utf-8"));
        HttpClient httpClient = getHttpClient(orderUrl);
        HttpResultVo execute = null;
        try {
            execute = httpClient.execute(httpPost, getResponseHandler());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String stringContent = execute.getStringContent();
        ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class);
        log.info("请求结果转为:" + resultVo);
        return resultVo;
    }
    public String getMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            StringBuilder hexString = new StringBuilder();
            byte[] var5 = messageDigest;
            int var6 = messageDigest.length;
            for (int var7 = 0; var7 < var6; ++var7) {
                byte b = var5[var7];
                hexString.append(String.format("%02x", b));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException var9) {
            NoSuchAlgorithmException e = var9;
            throw new RuntimeException(e);
        }
    }
    public String getBase64(String str) {
        String encodedStr = org.apache.commons.codec.binary.Base64.encodeBase64String(str.getBytes());
        return encodedStr;
    }
    //获取XML文件字节码
    public static byte[] convertElementToByteArray(Element element) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@@ -456,7 +700,6 @@
            return xysfResult;
        }
    }
    //签名
@@ -550,13 +793,6 @@
        }
        return result;
    }
}
exam-system/src/main/java/com/gkhy/exam/pay/utils/SignatureFileVo.java
@@ -3,10 +3,10 @@
/*    */ public class SignatureFileVo
        /*    */ {
    /*    */
//    @Validator(validatorType = 2, rangeInt = {1, 50})
    /*    */ private String orderNo;
    /*    */
//    @Validator(validatorType = 1)
    /*    */ private String fileData;
    /*    */