关于税控的一些问题总结
這次做了一個關于socket方式的稅控接口,讓人傷心的是,他們的接口文檔總是不成熟,各種各樣的錯。
先說說需要注意的地方。
第一:關于socket傳送的xml字符串時候應該注意的格式。要不然中文會亂碼。
?/// <summary>
??????? /// 發送XML數據
??????? /// </summary>
??????? /// <param name="xml"></param>
??????? /// <param name="ip"></param>
??????? /// <param name="port"></param>
??????? /// <returns>發送XML數據結果</returns>
??????? public string SocketGetXML(string xml, string ip, string port)
??????? {
??????????? byte[] result = new byte[1024];
??????????? IPAddress ipAdress = IPAddress.Parse(ip);
??????????? Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
??????????? clientSocket.Connect(new IPEndPoint(ipAdress, Convert.ToInt32(port)));
??????????? clientSocket.Send(Encoding.GetEncoding("GB2312").GetBytes(xml));
??????????? Thread.Sleep(1000);
??????????? int receiveLength = clientSocket.Receive(result);
??????????? clientSocket.Close();
??????????? return Encoding.GetEncoding("GB2312").GetString(result, 0, receiveLength);
??????? }
第二:關于模態化窗口傳遞中文參數應該注意的問題
在前臺js:
var message = window.showModalDialog("InvoiceCharge.aspx?Kpr=" + encodeURI(encodeURI(Kpr)) + "&Je=" + Je + "&InvoVersion=" + InvoVersion + "&InvoNumber=" + fph, "", "dialogHeight:100px;dialogWidth:200px;status:no;center:yes;");
?
后臺C#處理時候:
string Kpr = HttpUtility.UrlDecode(Request["Kpr"]); ????????
string Je = Request["Je"]; ????????
string InvoVersion = Request["InvoVersion"]; ???
string InvoNumber = Request["InvoNumber"];
?
但是如果傳遞的參數中包含了—號或者%號等一些特別的符號,這時造成無法解析。可以在前臺用encodeURIComponent(parameters)轉化就行了。
第三:關于模態化窗體的取值:
可以在C#后臺,將需要傳遞的值傳遞給一個隱藏域,
同時在頁面前臺用用js獲取他的值,但是這個js必須放在body的onload中加載。如:
? <script language="javascript" type="text/javascript">
?????? function onload() {
?????????? var messsage = document.getElementById("HiddenField2").value;
??????? window.returnValue = messsage;
??????????? window.close();
??????? }
??? </script>
</head>
<body οnlοad="onload();">
第四:關于js解析xml字符串的問題。
首先要把xml字符串轉化為xml對象。然后解析
//字符串轉化為xml對象
function toXmlDom(source) {
??? var xmlDoc = null;
??? if (window.ActiveXObject) {
??????? var ARR_ACTIVEX = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
??????? var XmlDomflag = false;
??????? for (var i = 0; i < ARR_ACTIVEX.length && !XmlDomflag; i++) {
??????????? try {
??????????????? var objXML = new ActiveXObject(ARR_ACTIVEX[i]);
??????????????? xmlDoc = objXML; XmlDomflag = true;
??????????? } catch (e) { }
??????? } if (xmlDoc) {
??????????? xmlDoc.async = false;
??????????? xmlDoc.loadXML(source);
??????? }
??? } else {
??????? var parser = new DOMParser();
??????? var xmlDoc = parser.parseFromString(source, "text/xml");
??? }
??? return xmlDoc;
}
這是一個適合各種瀏覽器的轉化方法,兼容了IE和火狐。
然后:
?function getAttributeValue(xmlNode, attrName) {
??????????? if (!xmlNode) return "";
??????????? if (!xmlNode.attributes) return "";
??????????? if (xmlNode.attributes[attrName] != null)
??????????????? return xmlNode.attributes[attrName].value;
??????????? if (xmlNode.attributes.getNamedItem(attrName) != null)
??????????????? return xmlNode.attributes.getNamedItem(attrName).value; return "";
??????? }
這是獲取相應節點中的屬性值。
?
????????????????????????? var? xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
??????????????????????????? xmlDoc.async = "false";
??????????????????????????? xmlDoc.loadXML(aryBill[i]);
??????????????????????????? var Je = (getAttributeValue(xmlDoc.getElementsByTagName("ITEM")[0].childNodes[55], "VALUE")).split(':')[1].toString();
??????????????????????????? var Kpr = (getAttributeValue(xmlDoc.getElementsByTagName("ITEM")[0].childNodes[70], "VALUE")).split(' ')[0].toString();
??????????????????????????? var fpbbh = InvoVersion;
??????????????????????????? var fph = getAttributeValue(xmlDoc.getElementsByTagName("ITEM")[0].childNodes[95], "VALUE");
這是如何獲取其中的值。
?
轉載于:https://www.cnblogs.com/selfimprove/p/4017769.html
總結
以上是生活随笔為你收集整理的关于税控的一些问题总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动开发构架漫谈——反劫持实战篇
- 下一篇: 基于 Flink、ClickHouse