教育训练处考试制证系统后端
“djh”
2025-03-24 631ead73058002bafa9a5a47f092e85d87c9a5d8
exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java
@@ -9,6 +9,12 @@
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.gkhy.exam.pay.entity.PayReqData;
import com.ruoyi.common.utils.Threads;
import com.xjhys.edu.fee.sdk.client.BillClient;
import com.xjhys.edu.fee.sdk.client.impl.ClientFactory;
import com.xjhys.edu.fee.sdk.model.ResponseDataVo;
import com.xjhys.edu.fee.sdk.model.SignatureFileVo;
import com.xjhys.edu.fee.sdk.model.UploadXmlReponseDataVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
@@ -41,6 +47,7 @@
import org.dom4j.io.XMLWriter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;
@@ -285,6 +292,17 @@
        return params;
    }
    @Async
    public void asyncNotrify(String orderNo){
        try {
            Threads.sleep(2000);
            affirmPost(orderNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //缴费结果确认查询
    public String affirmPost(String orderNo) throws IOException {
@@ -305,8 +323,9 @@
        HttpResultVo execute = httpClient.execute(httppost, getResponseHandler());
        String stringContent = execute.getStringContent();
        ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class);
        log.info("缴费结果确认,请求参数:"+orderNo);
        log.info("请求结果为:" + resultVo);
        if (resultVo.getRespcode().equals("BUS0000")) {
        if (resultVo.getRespcode().equals(CaiZhengConstans.CAI_ZHENG_SUCCESS)) {
            return "success";
        }
        return "fail";
@@ -403,24 +422,26 @@
        String reqdatastr = JSONObject.toJSONString(payReqData);
        String mac = this.getMD5("A1749891493E4CDDBFE4506357B1F0AB||" + this.getBase64(reqdatastr));
        String mac = this.getMD5(appId+"||"+ this.getBase64(payReqData));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("appid", "A1749891493E4CDDBFE4506357B1F0AB");
        jsonObject.put("appid", appId);
        jsonObject.put("mac", mac);
        jsonObject.put("reqdata", this.getBase64(reqdatastr));
        jsonObject.put("reqdata", this.getBase64(payReqData));
        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);
        String resultStr = HttpUtil.post(orderUrl, jsonObject);
        log.info("发起入参===" + jsonObject);
        JSONObject result = JSONObject.parseObject(resultStr);
        ResultVo resultVo = JSONObject.parseObject(resultStr, ResultVo.class);
        System.out.println("发起回参===" + result);
        log.info("发起回参===" + 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";
        // /home/www/swspkmas/files/
//        String xmlFilePath = "/home/www/swspkmas/files/" + orderNo1 + ".xml";
        String xmlFilePath = "F:\\text\\" + orderNo1 + ".xml";
        generateBase64StringToFile(signfile, xmlFilePath);
        String trr2 = "";
@@ -445,11 +466,17 @@
        String jmsignfile = this.signFilejdnew(trr2);
        String zuizhongpath = montageXmlV3(xmlFilePath, jmsignfile);
        String zzsignfile = convertFileToBase64(zuizhongpath);
        this.uploadXmlV2(orderNo1, zzsignfile);
        Boolean b = this.uploadXmlV2(orderNo1, zzsignfile);
        File file = new File(xmlFilePath);
        file.delete();
        File file1 = new File(zuizhongpath);
        file1.delete();
        if (b) {
            return resultVo;
        } else {
            resultVo.setRespcode("BUS8888");
        }
        return resultVo;
    }
@@ -548,7 +575,7 @@
        Map<String, Object> mmp = new HashMap();
        try {
            String filePath = "F:/cssconfig.properties";
            String filePath = "F:\\text/cssconfig.properties";
            System.out.println("配置文件路径:" + filePath);
            MOFClient client = new MOFClient(filePath);
            System.out.println("证书标识为:" + certId);
@@ -577,40 +604,27 @@
        }
    }
    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";
    public Boolean uploadXmlV2(String orderNo, String signFile) {
        log.info("上传验签开始");
        log.info("上传验签参数订单号:" + orderNo + "签名文件:" + signFile);
        ResponseDataVo<?> res = ClientFactory.sdkConfig(appId, "http://finpt.xjcz.gov.cn/fs-service", "http://finpt.xjcz.gov.cn/fs-service");
        SignatureFileVo signatureFile = new SignatureFileVo();
        signatureFile.setFileData(plain);
        signatureFile.setOrderNo(orderId);
        signatureFile.setFileData(signFile);
        signatureFile.setOrderNo(orderNo);
        BillClient billClient = ClientFactory.getBillClient();
        ResponseDataVo<UploadXmlReponseDataVo> dataRes = billClient.uploadXml(signatureFile);
        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);
        if (!dataRes.getRespcode().equals(CaiZhengConstans.CAI_ZHENG_SUCCESS)) {
            log.info("上传验签失败:" + dataRes);
            return false;
        }
        String stringContent = execute.getStringContent();
        ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class);
        log.info("请求结果转为:" + resultVo);
        return resultVo;
//        String mac = this.getMD5("A1749891493E4CDDBFE4506357B1F0AB||" + this.getBase64(signatureFile.toString()));
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("appid", "A1749891493E4CDDBFE4506357B1F0AB");
//        jsonObject.put("mac", mac);
//        jsonObject.put("reqdata", this.getBase64(signatureFile.toString()));
        return true;
    }
    public String getMD5(String input) {
        try {
@@ -632,9 +646,12 @@
        }
    }
    public String getBase64(String str) {
        String encodedStr = org.apache.commons.codec.binary.Base64.encodeBase64String(str.getBytes());
        return encodedStr;
    public String getBase64(PayReqData str) {
//        String encodedStr = org.apache.commons.codec.binary.Base64.encodeBase64String(str.getBytes());
        String reqData = Base64.getEncoder().encodeToString(JSONObject.toJSONString(str).getBytes());
        return reqData;
    }
@@ -672,7 +689,8 @@
//        Map<String, Object> mmp = new HashMap<>();
        try {
            String filePath = "F:\\text\\cssconfig.properties";
//            String filePath = "/home/www/swspkmas/cssconfig.properties";
            String filePath = "F:\\text/cssconfig.properties";
            System.out.println("配置文件路径:" + filePath);
            MOFClient client = new MOFClient(filePath);
            System.out.println("证书标识为:" + certId);
@@ -707,7 +725,7 @@
        SignResult result = null;
        String certId = "11650000MB1957293J";
        try {
            MOFClient client = new MOFClient("F:\\text\\cssconfig.properties");
            MOFClient client = new MOFClient("/home/www/swspkmas/cssconfig.properties");
            result = client.sign(certId, strData.getBytes(StandardCharsets.UTF_8));
            log.info("***签名成功***");
            log.info("签名返回结果为:" + result);
@@ -729,7 +747,7 @@
    public MOFVerifyResult verify(byte[] strData, String signData) {
        MOFVerifyResult verify = null;
        try {
            MOFClient client = new MOFClient("F:\\text\\cssconfig.properties");
            MOFClient client = new MOFClient("/home/www/swspkmas/cssconfig.properties");
            verify = client.verifySign(strData, signData.getBytes(StandardCharsets.UTF_8));
            log.info("验签成功");
@@ -753,7 +771,7 @@
    public EnvelopResult encryptEnvelop(byte[] plain) {
        EnvelopResult envelopResult = null;
        try {
            AdvanceSignClient client = new AdvanceSignClient("F:\\text\\cssconfig.properties");
            AdvanceSignClient client = new AdvanceSignClient("/home/www/swspkmas/cssconfig.properties");
            String certId = "rsa";
            CertIdParams certIdParams = new CertIdParams(certId);
            //将封装好的加密证书参数对象放入 数组中
@@ -774,7 +792,7 @@
    public DecryptResult decryptEnvelop(String signData) {
        DecryptResult result = null;
        try {
            AdvanceSignClient client = new AdvanceSignClient("F:\\text\\cssconfig.properties");
            AdvanceSignClient client = new AdvanceSignClient("/home/www/swspkmas/cssconfig.properties");
            byte[] enc_data = signData.getBytes();
            result = client.decryptEnvelop(enc_data);
            log.info("解密数字信封结果成功");