| | |
| | | import cn.com.jit.new_vstk.Bean.EnvelopResult; |
| | | import cn.com.jit.new_vstk.Bean.SignResult; |
| | | import cn.com.jit.new_vstk.Bean.VerifyResult; |
| | | import cn.hutool.json.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.gkhy.exam.pay.entity.PayReqData; |
| | | import com.gkhy.exam.pay.utils.PayUtils; |
| | | import com.gkhy.exam.pay.utils.ResultVo; |
| | | import com.ruoyi.common.utils.uuid.UUID; |
| | | import com.gkhy.exam.pay.utils.Sign; |
| | | import com.gkhy.exam.pay.utils.SignDto; |
| | | import com.google.gson.JsonObject; |
| | | import com.ruoyi.common.utils.RandomUtil; |
| | | import lombok.extern.log4j.Log4j2; |
| | | import org.dom4j.*; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.test.context.ActiveProfiles; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.*; |
| | | |
| | | @SpringBootTest(classes = TextPay.class) |
| | | @ActiveProfiles("dev") |
| | |
| | | public class TextPay { |
| | | |
| | | |
| | | @Test |
| | | public void paytext() throws IOException { |
| | | |
| | | |
| | | PayReqData payReqData = new PayReqData(); |
| | | PayReqData.Feedata feedatas = new PayReqData.Feedata(); |
| | | |
| | | payReqData.setDesc("安全技术考试考务费_煤矿安全作业-001504"); |
| | | payReqData.setOrderNo("10000000001"); |
| | | payReqData.setMoney(BigDecimal.valueOf(103)); |
| | | payReqData.setAmount(1); |
| | | payReqData.setPayerName("测试"); |
| | | payReqData.setCertNo("411381199801093991"); |
| | | payReqData.setPayerType(1); |
| | | payReqData.setInvoiceSocialCode("11650000MB1957293J"); |
| | | payReqData.setHandlingPerson("张三"); |
| | | payReqData.setChecker("李四"); |
| | | payReqData.setEnterCode("680534083"); |
| | | |
| | | List<PayReqData.Feedata> feedatas1 = new ArrayList<>(); |
| | | feedatas.setAmount(1); |
| | | feedatas.setBusCode("DZ001504"); |
| | | feedatas.setPrice(BigDecimal.valueOf(103)); |
| | | feedatas1.add(feedatas); |
| | | payReqData.setFeeDatas(feedatas1); |
| | | |
| | | |
| | | ResultVo resultVo = PayUtils.sendApiPost(payReqData); |
| | | System.out.printf("请求结果:"+resultVo); |
| | | |
| | | } |
| | | // |
| | | //@Test |
| | | // public void paytext001() throws IOException{ |
| | | // |
| | | // for (int i = 1142; i <3001 ; i++) { |
| | | // String buscode="DZ00"+i; |
| | | // log.info("buscode为:"+buscode); |
| | | // ResultVo paytext = paytext(buscode); |
| | | // log.info("请求结果为:"+paytext.getRespcode()); |
| | | // if (paytext.getRespcode().equals("BUS0000")){ |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Test |
| | | public void paytext() throws IOException, DocumentException { |
| | | |
| | | |
| | | PayReqData payReqData = new PayReqData(); |
| | | PayReqData.Feedata feedatas = new PayReqData.Feedata(); |
| | | |
| | | |
| | | //订单编号 RandomUtil.generateOrderNumber(1L, "NC") NC202502170849287181 |
| | | payReqData.setOrderNo(RandomUtil.generateOrderNumber(1L, "NC")); |
| | | //订单总金额 |
| | | payReqData.setMoney(BigDecimal.valueOf(112)); |
| | | //子订单数目 |
| | | payReqData.setAmount(1); |
| | | //缴费人姓名(单位填单位名称)阿克苏地区博安煤矿安全技术服务中心 |
| | | payReqData.setPayerName("阿克苏地区博安煤矿安全技术服务中心"); |
| | | //缴费人证件号(单位填同一信用代码)52652900789893140A |
| | | payReqData.setCertNo("52652900789893140A"); |
| | | //缴款人类型(1个人 2单位) |
| | | payReqData.setPayerType(2); |
| | | //开票单位社会信用代码12650000MB1A9612XD |
| | | payReqData.setInvoiceSocialCode("11652300734487567J"); |
| | | //开票人 |
| | | payReqData.setHandlingPerson("姜倩"); |
| | | //复核人 |
| | | payReqData.setChecker("薄晓洁"); |
| | | //单位编码547185129 |
| | | payReqData.setEnterCode("547185129"); |
| | | //订单描述(非必填) |
| | | payReqData.setDesc("非煤安全作业理论考试-002002"); |
| | | //订单明细 |
| | | List<PayReqData.Feedata> feedatas1 = new ArrayList<>(); |
| | | //数量 |
| | | feedatas.setAmount(2); |
| | | //业务代码 |
| | | feedatas.setBusCode("DZ002002"); |
| | | //单价 |
| | | feedatas.setPrice(BigDecimal.valueOf(112)); |
| | | // PayReqData.Feedata feedata = new PayReqData.Feedata(); |
| | | // feedata.setBusCode("DZ012402"); |
| | | // 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 jsonString = JSONObject.toJSONString(resultVo); |
| | | // log.info("请求结果:"+jsonString); |
| | | String fileData = resultVo.getRespdata().getFileData(); |
| | | byte[] decode = Base64.getDecoder().decode(fileData); |
| | | String xmlString = new String(decode, StandardCharsets.UTF_8); |
| | | Document document = DocumentHelper.parseText(xmlString); |
| | | log.info("票据原文为:"+document.asXML()); |
| | | // Element rootElement = document.getRootElement(); |
| | | // Element eInvoiceData = rootElement.element("EInvoiceData"); |
| | | //// log.info("xml文件为:"+text); |
| | | // SignResult sign = payUtils.sign(decode); |
| | | //// log.info("签名结果为:"+ Arrays.toString(sign.getSignData())); |
| | | // VerifyResult verify = payUtils.verify(decode, sign.getSignData()); |
| | | // SignDto signDto = new SignDto("SM3", "Base64", new Date(), verify.getReturnData(), verify.getSerialNumber(), verify.getIssure()); |
| | | // Sign sign1 = new Sign(); |
| | | // Document signature = sign1.getSignature(signDto); |
| | | // eInvoiceData.add(signature); |
| | | // EnvelopResult envelopResult = payUtils.encryptEnvelop(document.asXML().getBytes()); |
| | | // log.info("制作数字信封为:"+ Arrays.toString(envelopResult.getEnvelopData())); |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void sing() throws IOException { |
| | | String fileData="<?xml version=\"1.0\" encoding=\"UTF-8\"?><EInvoice><Header><EInvoiceTag>CZ-EI-65</EInvoiceTag><EInvoiceID>8302000000-52101056</EInvoiceID><Version>1.0.0</Version></Header><EInvoiceData><Main><EInvoiceName>新疆维吾尔自治区政府非税收入票据_电子票</EInvoiceName><EInvoiceCode>65010125</EInvoiceCode><EInvoiceNumber>0000002038</EInvoiceNumber><RandomNumber>buac24</RandomNumber><EInvoiceSpecimenCode>652500010001</EInvoiceSpecimenCode><SupervisorAreaCode>650000</SupervisorAreaCode><TotalAmount>56.00</TotalAmount><IssueDate>2025-02-15</IssueDate><IssueTime>00:00:00</IssueTime><InvoicingParty><InvoicingPartyCode>11650000MB1957293J</InvoicingPartyCode><InvoicingPartyName>新疆维吾尔自治区应急管理厅</InvoicingPartyName></InvoicingParty><PayerParty><PayerPartyType>2</PayerPartyType><PayerPartyName>阿克苏地区博安煤矿安全技术服务中心</PayerPartyName></PayerParty><HandlingPerson>张三</HandlingPerson><Checker>李四</Checker><MainExt><PayCode>65000025000000017955</PayCode></MainExt><InvoicingPartySeal><SealId>006fba98-37ad-4499-8c2e-b2ed24d0d802</SealId><SealName>新疆维吾尔自治区应急管理厅机关(行政)</SealName><SealHash>1762185155</SealHash></InvoicingPartySeal><SupervisorPartySeal><SealId>cd7c38f4-ba68-4dd9-94ca-c5058faaf7ed</SealId><SealName>新疆维吾尔自治区财政厅</SealName><SealHash>-1186976973</SealHash></SupervisorPartySeal></Main><Details><Item><ItemCode>86211900001</ItemCode><ItemName>煤矿安全作业理论考试</ItemName><ItemAmount>56.00</ItemAmount></Item></Details></EInvoiceData><EInvoiceSignature><Signature id=\"InvoicingParty\"><SignedInfo><Reference URI=\"/EInvoice/Headerl/EInvoice/EInvoiceData\"/><SignatureAlgorithm>SM3</SignatureAlgorithm><SignatureFormat>DETACH</SignatureFormat></SignedInfo><SignatureTime>15 02 2025 15:15:15 GMT+08:00</SignatureTime><SignatureValue>CN=应急管理厅,T=11650000MB1957293J,OU=01,L=00,L=00,ST=65,O=01,O=MOF,C=CN</SignatureValue><KeyInfo><SerialNumber>63562B79EB75C36D</SerialNumber><X509IssuerName>CN=Private Certificate Authority Of MOF SM2,O=MOF,C=CN</X509IssuerName></KeyInfo></Signature></EInvoiceSignature></EInvoice>"; |
| | | |
| | | |
| | | PayUtils payUtils = new PayUtils(); |
| | | ResultVo resultVo = payUtils.uploadXml("CO202502140115634461", fileData); |
| | | log.info("请求结果为:"+resultVo); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void text001() throws DocumentException { |
| | | String aa = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Signature><id xmlns=\"InvoicingParty\"/><SignedInfo><Reference URI=\"/EInvoice/Headerl/EInvoice/EInvoiceData\"/><SignatureAlgorithm>SM3</SignatureAlgorithm><SignatureFormat>DETACH</SignatureFormat></SignedInfo><SignatureTime>15 02 2025 13:16:17 GMT+08:00</SignatureTime><SignatureValue>CN=应急管理厅,T=11650000MB1957293J,OU=01,L=00,L=00,ST=65,O=01,O=MOF,C=CN</SignatureValue><KeyInfo><SerialNumber>63562B79EB75C36D</SerialNumber><X509IssuerName>CN=Private Certificate Authority Of MOF SM2,O=MOF,C=CN</X509IssuerName></KeyInfo></Signature>"; |
| | | String bb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><EInvoice><Header><EInvoiceTag>CZ-EI-65</EInvoiceTag><EInvoiceID>8302000000-52101056</EInvoiceID><Version>1.0.0</Version></Header><EInvoiceData><Main><EInvoiceName>新疆维吾尔自治区政府非税收入票据_电子票</EInvoiceName><EInvoiceCode>65010125</EInvoiceCode><EInvoiceNumber>0000002038</EInvoiceNumber><RandomNumber>buac24</RandomNumber><EInvoiceSpecimenCode>652500010001</EInvoiceSpecimenCode><SupervisorAreaCode>650000</SupervisorAreaCode><TotalAmount>56.00</TotalAmount><IssueDate>2025-02-15</IssueDate><IssueTime>00:00:00</IssueTime><InvoicingParty><InvoicingPartyCode>11650000MB1957293J</InvoicingPartyCode><InvoicingPartyName>新疆维吾尔自治区应急管理厅</InvoicingPartyName></InvoicingParty><PayerParty><PayerPartyType>2</PayerPartyType><PayerPartyName>阿克苏地区博安煤矿安全技术服务中心</PayerPartyName></PayerParty><HandlingPerson>张三</HandlingPerson><Checker>李四</Checker><MainExt><PayCode>65000025000000017955</PayCode></MainExt><InvoicingPartySeal><SealId>006fba98-37ad-4499-8c2e-b2ed24d0d802</SealId><SealName>新疆维吾尔自治区应急管理厅机关(行政)</SealName><SealHash>1762185155</SealHash></InvoicingPartySeal><SupervisorPartySeal><SealId>cd7c38f4-ba68-4dd9-94ca-c5058faaf7ed</SealId><SealName>新疆维吾尔自治区财政厅</SealName><SealHash>-1186976973</SealHash></SupervisorPartySeal></Main><Details><Item><ItemCode>86211900001</ItemCode><ItemName>煤矿安全作业理论考试</ItemName><ItemAmount>56.00</ItemAmount></Item></Details></EInvoiceData></EInvoice>"; |
| | | |
| | | |
| | | Document documenta = DocumentHelper.parseText(aa); |
| | | Document documentb = DocumentHelper.parseText(bb); |
| | | log.info("原文为:"+documentb.asXML()); |
| | | log.info("需要拼接为:"+documenta.asXML()); |
| | | Element rootElement = documenta.getRootElement(); |
| | | // Element signature = rootElement.element("Signature"); |
| | | Element rootElement1 = documentb.getRootElement(); |
| | | // Element eInvoice = rootElement1.element("EInvoice"); |
| | | rootElement1.add(rootElement); |
| | | log.info("拼接后位:"+documentb.asXML()); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |