package com.uas.eis; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.uas.eis.config.DonlimConfig; import com.uas.eis.dao.*; import com.uas.eis.service.ERPService; import com.uas.eis.task.ElecInvoiceTask; import com.uas.eis.task.InvoiceOrderTask; import nuonuo.open.sdk.NNOpenSDK; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.io.*; import java.net.URL; import java.net.URLConnection; import java.text.SimpleDateFormat; import java.util.*; @RunWith(SpringRunner.class) @SpringBootTest(classes = {UasEisApplication.class}) public class UasEisApplicationTests { @Autowired private BaseDao baseDao; @Autowired private ERPService erpService; @Autowired private DonlimConfig donlimConfig; @Autowired private ElecInvoiceTask elecInvoiceTask; @Autowired InvoiceOrderTask invoiceOrderTask; /** * 开票订单对接 */ @Test public void Test() { System.out.println("test"); System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date())); Object ob=baseDao.getFieldDataByCondition("enterprise","EN_WHICHSYSTEM","1=1"); System.out.println(ob.toString()); erpService.pushInvoiceOrder("N_HUASL_SZ",47); } /** * 获取token */ @Test public void Test1() { /*//测试 String appKey = "SD47646161"; String appSecret = "SD681C05C3EA4408";*/ //正式 String appKey = "47646161"; String appSecret = "B6681C05C3EA4408"; // 接口调用 NNOpenSDK sdk = NNOpenSDK.getIntance(); String json = sdk.getMerchantToken(appKey, appSecret); // 响应报文解析 System.out.println("\n\n\n【商户获取Token】"); System.out.println(json); } @Test public void Test2(){ NNOpenSDK sdk = NNOpenSDK.getIntance(); String taxnum ="339901999999199";////测试 String appKey = "78607195"; String appSecret = "26A860C451744A21"; String method = "nuonuo.OpeMplatform.queryInvoiceList"; // API方法名 String url = "https://sdk.nuonuo.com/open/v1/services";//SDK请求地址 String token = "77f21f617f87135fcd97ef1ueud3dxdi"; String content = "{ \"requestType\": \"1\", \"pageNo\": \"2\", \"pageSize\": \"20\", \"taxnum\": \"339901999999199\", " + " \"startTime\": \"2023-07-20 00:00:00\", " + "\"endTime\": \"2023-07-21 00:00:00\" }"; content=sdk.convertToUtf8(content); String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可 String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content); System.out.println("result:"); System.out.println(result); } /** * 请求开具发票 */ @Test public void Test3() { erpService.invoiceOrderSubmitKp("N_HUASL_SZ",5); } /** * 删除平台开票订单 */ @Test public void Test_del() { erpService.cancelInvoiceOrder("N_HUASL_SZ",7); } /** * nuonuo.OpeMplatform.findOrderState(诺税通Saas订单状态查询接口) */ @Test public void TestfindOrderState() { String OrderCode = "SZ23070031"; SqlRowList io = baseDao.queryForRowSet("SELECT io_id FROM N_HUASL_SZ.invoiceOrder where IO_STATUS ='已审核' and IO_DOCKSTATUS = '对接成功' " + // "and nvl(IO_INVOICESTATUS,0) in(0,1,6) " + "and io_code = '"+OrderCode+"'" + "order by io_id "); //订单状态(0:待处理 1:处理中 2:已处理 4:提交失败 6:部分待处理 7:无需开票) //0:待处理 表示订单没有转了开票申请,此状态需要定时获取 //1:处理中 表示订单可能转了开票申请,此状态需要定时获取 //2:已处理 表示订单全部都转了开票申请,没有发票号的情况下要继续获取订单状态。 //4:提交失败 表示订单自动转失败了,此状态需要定时获取 //6:部分待处理 表示订单部分转了开票申请,此状态需要定时获取 //7:无需开票,此状态可以不用管,此状态需要定时获取 while (io.next()){ Map mm = erpService.findOrderState("N_HUASL_SZ", io.getGeneralInt("io_id")); } } @Test public void TestInvoiceOrderStateUpdate(){ invoiceOrderTask.InvoiceOrderStateUpdate(); } /** * 查询订单关联发票接口 nuonuo.OpeMplatform.findOrderRelationInvoice */ @Test public void Test5() { NNOpenSDK sdk = NNOpenSDK.getIntance(); String taxnum ="339901999999199";////测试 String appKey = "78607195"; String appSecret = "26A860C451744A21"; String method = "nuonuo.OpeMplatform.findOrderRelationInvoice"; // API方法名 String url = "https://sdk.nuonuo.com/open/v1/services";//SDK请求地址 String token = "77f21f617f87135fcd97ef1ueud3dxdi"; Map reqParam=new HashMap<>(); reqParam.put("needInvoiceSourceDetail","0");// 是否需要发票所来源的订单明细,1-是, 0-否(不填默认 0) 当为0时,将不回传orderDetailCallBackVOS //SZ23070026 //betaRTC-202105-003180-209 reqParam.put("originalOrderNo","SZ23070042");//部分待处理-没开票 {"status":"8958","message":"该订单对应的开票单不存在","data":null} reqParam.put("saleTaxNum","339901999999199"); // invoiceState = 1 开票状态,合并冲销时为空 1:开票成功 2:开票失败 //exceptionMessage 开票异常信息,开票失败状态时返回 String content=JSONArray.toJSONString(reqParam); // content=sdk.convertToUtf8(content); // System.out.println(content); String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可 String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content); System.out.println(result); } @Test public void TestDownLoadElecInvoice(){ // 20230731182154174492 SZ23070033 Map m = erpService.getElecInvoicesById("N_HUASL_SZ", 7); System.out.println(JSONObject.toJSONString(m)); // elecInvoiceTask.elecInvoiceDownLoad(); } //文件转存 //https://inv.jss.com.cn/fp2/2zpnwyKkdvu9dWzE8BhmSnER0Iux3xQRMLidDJhiIE2PziVXY4lL3k83OsK0K06YctW5cf1FFHxraffj-bf16A.pdf @Test public void TestPdfDowLoad(){ //下载地址 String fileUrl = "https://inv.jss.com.cn/fp2/2zpnwyKkdvu9dWzE8BhmSnER0Iux3xQRMLidDJhiIE2PziVXY4lL3k83OsK0K06YctW5cf1FFHxraffj-bf16A.pdf"; // 定义要保存的文件的路径 String filePath = "C:\\invoice\\988038486766_00007404.pdf";//开票代码_发票号码 try { // 创建URL对象 URL url = new URL(fileUrl); // 打开连接 URLConnection conn = url.openConnection(); // 获取输入流 InputStream in = conn.getInputStream(); // 创建输出流 OutputStream out = new FileOutputStream(filePath); // 创建缓冲区 byte[] buffer = new byte[1024]; // 读取并写入数据 int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } // 关闭流 in.close(); out.close(); //存文件 filepath System.out.println("下载成功"); } catch (Exception e) { e.printStackTrace(); } } @Test public void TestElecInvoiceAttachSave(){ elecInvoiceTask.elecInvoiceAttachSave(); } //冲红 @Test public void testRushRed(){ erpService.rushRed("N_HUASL_SZ",7); } @Test public void queryInvoiceRedConfirm(){ String url=donlimConfig.getRoute(); String appKey = donlimConfig.getAppKey(); String appSecret = donlimConfig.getAppSecret(); String token = donlimConfig.getToken(); String taxnum= donlimConfig.getTaxnum(); // erpService.queryInvoiceRedConfirmByCode( taxnum, appKey, appSecret, token, url,"1135624457459470336"); } @Test public void testRed(){ NNOpenSDK sdk = NNOpenSDK.getIntance(); String taxnum ="339901999999199";////测试 String appKey = "78607195"; String appSecret = "26A860C451744A21"; String token = "77f21f617f87135fcd97ef1ueud3dxdi"; String url = "https://sdk.nuonuo.com/open/v1/services";//SDK请求地址 String method = "nuonuo.OpeMplatform.queryInvoiceResult"; // API方法名 String content = "{" + // "\"serialNos\": \"23073118215402725192\""+//流水号 -- EI_SID -- invoiceSerialNum ",\"orderNos\": \"20230731182154174492\""+ //开票单号 --- EI_ORDERNO -- ORDERNO ",\"isOfferInvoiceDetail\": \"0\""+ // ",\"extensionNumber\": \"-\","+ // "\"deptId\": \"-\","+ // "\"clerkId\": \"-\","+ // "\"startTime\": \"2022-05-19\","+ // "\"endTime\": \"2022-06-19\""+ "}"; String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可 String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content); System.out.println(result); } @Test public void TestelecInvoiceRedConfirmStateUpdate(){ elecInvoiceTask.elecInvoiceRedConfirmStateUpdate(); } @Test public void TestElecInvoiceRedAttachSave(){ elecInvoiceTask.elecInvoiceRedAttachSave(); } }