| | |
| | | package com.gkhy.exam.pay.service.impl; |
| | | |
| | | import cn.com.jit.mof.bean.MOFVerifyResult; |
| | | import cn.com.jit.new_vstk.Bean.SignResult; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.pay.dto.rep.CoalPayRepDto; |
| | |
| | | import com.gkhy.exam.pay.mapper.CoalPayMapper; |
| | | import com.gkhy.exam.pay.service.CoalPayService; |
| | | import com.gkhy.exam.pay.service.CoalPayStudentService; |
| | | import com.gkhy.exam.pay.utils.*; |
| | | import com.gkhy.exam.pay.utils.BillSignException; |
| | | import com.gkhy.exam.pay.utils.PayUtils; |
| | | import com.gkhy.exam.pay.utils.ResultVo; |
| | | import com.ruoyi.common.constant.ResultConstants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dom4j.Document; |
| | | import org.dom4j.DocumentException; |
| | | import org.dom4j.DocumentHelper; |
| | | import org.dom4j.Element; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | |
| | | |
| | | //订单编号 |
| | | payReqData.setOrderNo("NC202502170905105061"); |
| | | payReqData.setOrderNo(RandomUtil.generateOrderNumber(1L, "NC")); |
| | | //订单总金额 |
| | | payReqData.setMoney(BigDecimal.valueOf(112)); |
| | | payReqData.setMoney(BigDecimal.valueOf(56)); |
| | | //子订单数目 |
| | | payReqData.setAmount(1); |
| | | //缴费人姓名(单位填单位名称)阿克苏地区博安煤矿安全技术服务中心 |
| | | payReqData.setPayerName("阿克苏地区博安煤矿安全技术服务中心"); |
| | | payReqData.setPayerName("李州"); |
| | | //缴费人证件号(单位填同一信用代码)52652900789893140A |
| | | payReqData.setCertNo("52652900789893140A"); |
| | | payReqData.setCertNo("612324197909106056"); |
| | | //缴款人类型(1个人 2单位) |
| | | payReqData.setPayerType(2); |
| | | payReqData.setPayerType(1); |
| | | //开票单位社会信用代码12650000MB1A9612XD |
| | | payReqData.setInvoiceSocialCode("11650000MB1957293J"); |
| | | payReqData.setInvoiceSocialCode("11652100MB19019356"); |
| | | //开票人 |
| | | payReqData.setHandlingPerson("姜倩"); |
| | | payReqData.setHandlingPerson("孙乾"); |
| | | //复核人 |
| | | payReqData.setChecker("薄晓洁"); |
| | | payReqData.setChecker("哲霞"); |
| | | //单位编码547185129 |
| | | payReqData.setEnterCode("547185129"); |
| | | payReqData.setEnterCode("204704695"); |
| | | //订单描述(非必填) |
| | | payReqData.setDesc("非煤安全作业理论考试-002002"); |
| | | payReqData.setDesc("非煤安全作业考试费_理论-012381"); |
| | | //订单明细 |
| | | List<PayReqData.Feedata> feedatas1 = new ArrayList<>(); |
| | | //数量 |
| | | // feedatas.setAmount(1); |
| | | // //业务代码 |
| | | // feedatas.setBusCode("DZ12401"); |
| | | // //单价 |
| | | // feedatas.setPrice(BigDecimal.valueOf(56)); |
| | | feedatas.setAmount(1); |
| | | //业务代码 |
| | | feedatas.setBusCode("DZ012381"); |
| | | //单价 |
| | | feedatas.setPrice(BigDecimal.valueOf(56)); |
| | | PayReqData.Feedata feedata = new PayReqData.Feedata(); |
| | | feedata.setBusCode("DZ002002"); |
| | | feedata.setAmount(2); |
| | | feedata.setPrice(BigDecimal.valueOf(112)); |
| | | // feedatas1.add(feedatas); |
| | | feedatas1.add(feedata); |
| | | // feedata.setBusCode("DZ011574"); |
| | | // feedata.setAmount(1); |
| | | // feedata.setPrice(BigDecimal.valueOf(103)); |
| | | feedatas1.add(feedatas); |
| | | // feedatas1.add(feedata); |
| | | payReqData.setFeeDatas(feedatas1); |
| | | log.info("请求参数:" + JSONObject.toJSONString(payReqData)); |
| | | |
| | | |
| | | PayUtils payUtils = new PayUtils(); |
| | | ResultVo resultVo = payUtils.sendApiPost(payReqData); |
| | | String fileData = resultVo.getRespdata().getFileData(); |
| | | //票据原文转为byte字节文件 |
| | | byte[] decode = Base64.getDecoder().decode(fileData); |
| | | //byte字节文件转为xml字符串 |
| | | String xmlString = new String(decode, StandardCharsets.UTF_8); |
| | | Document document = null; |
| | | try { |
| | | document = DocumentHelper.parseText(xmlString); |
| | | } catch (DocumentException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | log.info("票据原文为:" + document.asXML()); |
| | | BillSign billSign = new BillSign(); |
| | | String s = billSign.readRefSignDto(document); |
| | | Element rootElement = document.getRootElement(); |
| | | SignResult sign = payUtils.sign(s); |
| | | MOFVerifyResult verify = payUtils.verify(sign.getSignData(), s); |
| | | SignDto signDto = new SignDto(verify.getSignTime(), new String(Base64.getEncoder().encode(sign.getSignData())), verify.getIssure(), verify.getSn()); |
| | | log.info("拼接对象为:" + JSONObject.toJSONString(signDto)); |
| | | Sign sign1 = new Sign(); |
| | | Document signature = sign1.getSignature(signDto); |
| | | // Element rootElement1 = signature.getRootElement(); |
| | | log.info("拼接结果为:" + signature.asXML()); |
| | | rootElement.add(signature.getRootElement()); |
| | | // EnvelopResult envelopResult = payUtils.encryptEnvelop(document.asXML().getBytes()); |
| | | // log.info("制作数字信封为:"+ Arrays.toString(envelopResult.getEnvelopData())); |
| | | log.info("签名后票据为:" + document.asXML()); |
| | | ResultVo resultVo1 = payUtils.uploadXml(resultVo.getRespdata().getOrderNo(), document.asXML()); |
| | | return resultVo1; |
| | | ResultVo resultVo = payUtils.faqiV2(payReqData); |
| | | log.info("请求结果:" + JSONObject.toJSONString(resultVo)); |
| | | // String fileData = resultVo.getRespdata().getFileData(); |
| | | // //票据原文转为byte字节文件 |
| | | // byte[] decode = Base64.getDecoder().decode(fileData); |
| | | // //byte字节文件转为xml字符串 |
| | | // String xmlString = new String(decode, StandardCharsets.UTF_8); |
| | | // Document document = null; |
| | | // try { |
| | | // document = DocumentHelper.parseText(xmlString); |
| | | // } catch (DocumentException e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // log.info("票据原文为:" + document.asXML()); |
| | | // BillSign billSign = new BillSign(); |
| | | // String s = billSign.readRefSignDto(document); |
| | | // Element rootElement = document.getRootElement(); |
| | | // SignResult sign = payUtils.sign(s); |
| | | // MOFVerifyResult verify = payUtils.verify(sign.getSignData(), s); |
| | | // SignDto signDto = new SignDto(verify.getSignTime(), new String(Base64.getEncoder().encode(sign.getSignData())), verify.getIssure(), verify.getSn()); |
| | | // log.info("拼接对象为:" + JSONObject.toJSONString(signDto)); |
| | | // Sign sign1 = new Sign(); |
| | | // Document signature = sign1.getSignature(signDto); |
| | | //// Element rootElement1 = signature.getRootElement(); |
| | | // log.info("拼接结果为:" + signature.asXML()); |
| | | // rootElement.add(signature.getRootElement()); |
| | | //// EnvelopResult envelopResult = payUtils.encryptEnvelop(document.asXML().getBytes()); |
| | | //// log.info("制作数字信封为:"+ Arrays.toString(envelopResult.getEnvelopData())); |
| | | // log.info("签名后票据为:" + document.asXML()); |
| | | // ResultVo resultVo1 = payUtils.uploadXml(resultVo.getRespdata().getOrderNo(), document.asXML()); |
| | | return resultVo; |
| | | } |
| | | |
| | | private PayReqData fillData(List<CoalPayStudent> coalPayStudent, CoalPay coalPay, List<CoalCategory> coalCategories, CoalTicket coalTicket, Integer payType, CoalTeamPayReq coalTeamPayReq) { |