日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

NC凭证接口

發(fā)布時(shí)間:2024/1/1 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NC凭证接口 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

問題的描述:金融行業(yè)在系統(tǒng)模塊分為財(cái)務(wù)和業(yè)務(wù)兩個(gè)系統(tǒng)。但是財(cái)務(wù)有時(shí)候需要生成憑證,這時(shí)候就涉及業(yè)務(wù)模塊了,我方就需要寫NC憑證接口。這時(shí)候就需要三方交互好,確定規(guī)則。簡(jiǎn)單的說,就是我方發(fā)送一個(gè)正確的一個(gè)XML格式的字符給NC公司,然后NC公司會(huì)判斷這個(gè)XML是不是符合規(guī)則,返回一個(gè)xml格式結(jié)果。
用到的架包:dom4j-1.6.1.jar、jdom.jar
接口的代碼

package com.enfo.wd;import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List;import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult;import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.DocumentSource; import org.jdom.Element; import org.jdom.input.SAXBuilder;public class NCPush {@SuppressWarnings("rawtypes")public String checkNCSendPzFlag(String sendXML) throws Exception {String result = "";//returne標(biāo)識(shí)try {/*********將xml發(fā)送到目標(biāo)服務(wù)器*****************///將xml保存在本地文件夾String path = "F:\\xml_voucher\\IMP\\NC.xml";File file = new File("F:\\xml_voucher\\IMP");file.mkdirs();//創(chuàng)建父文件夾File f2 = new File(path);f2.createNewFile();FileOutputStream fos = new FileOutputStream(f2);fos.write(sendXML.getBytes("utf-8"));//寫入并設(shè)置編碼格式fos.flush();fos.close();//獲取Servlet連接并設(shè)置請(qǐng)求的方法//NC接口地址String url = "http://10.68.3.5:8020/service/XChangeServlet?account=04&groupcode=1";URL realURL = new URL(url);HttpURLConnection connection = (HttpURLConnection) realURL.openConnection();connection.setDoOutput(true);connection.setRequestProperty("Content-type", "text/xml");connection.setRequestMethod("POST");//將Document對(duì)象寫入連接的輸出流中BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());BufferedInputStream input = new BufferedInputStream(new FileInputStream(path));int length;byte[] buffer = new byte[1000];while ((length = input.read(buffer, 0, 1000)) != -1) {out.write(buffer, 0, length);}input.close();out.close();/***************從連接的輸入流中取得回執(zhí)信息***************///輸入流獲取返回的xml,寫入DocumentInputStream inputStream = connection.getInputStream();InputStreamReader isr = new InputStreamReader(inputStream, "utf-8");BufferedReader bufreader = new BufferedReader(isr);String xmlString = "";int c;while ((c = bufreader.read()) != -1) {System.out.print((char) c);xmlString += (char) c;}input.close();Document resDoc = DocumentHelper.parseText(xmlString);/************對(duì)回執(zhí)結(jié)果的后續(xù)處理…************///document轉(zhuǎn)化為xml,并保存TransformerFactory tFactory = TransformerFactory.newInstance();Transformer transformer = tFactory.newTransformer();DocumentSource source = new DocumentSource(resDoc);transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//設(shè)置文檔的換行與縮進(jìn)transformer.setOutputProperty(OutputKeys.INDENT, "YES");//設(shè)置日期格式SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");String resFile = "E:\\用友\\回執(zhí)目錄\\BkMsg_會(huì)計(jì)憑證_"+ fmt.format(new Date()) + ".xml";File resDis = new File("E:\\用友\\回執(zhí)目錄\\");if (!resDis.exists())resDis.mkdirs();StreamResult results = new StreamResult(new File(resFile));transformer.transform(source, results);//jdom解析XMLSAXBuilder builder = new SAXBuilder();Document doc = (Document) builder.build(new File(resFile));Element foo = (Element) doc.getRootElement();List allChildren = (List) foo.getChildren();for (int i = 0; i < allChildren.size(); i++) {System.out.println(" 發(fā)送狀態(tài):"+ ((Element)allChildren.get(i)).getChild("resultcode").getText());System.out.print("測(cè)試信息"+ ((Element)allChildren.get(i)).getChild("resultdescription").getText());}if (((Element)allChildren.get(0)).getChild("resultcode").getText().equals("1")) {result = "導(dǎo)入成功!";} else {result = "導(dǎo)入失敗:"+ ((Element) allChildren.get(0)).getChild("resultdescription").getText();}} catch (Exception e) {result = "導(dǎo)入失敗" + e.getMessage();e.printStackTrace();}return result;}}

總結(jié)

以上是生活随笔為你收集整理的NC凭证接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。