/// <summary> /// 取交易流水号 /// </summary> /// <param name="Astr_lydz">目的地址,为社保局的编码</param> /// <param name="Astr_ydz">源地址,为银行的编码</param> /// <param name="jylsh"></param> /// <returns></returns> private static string getjylsh(string Astr_lydz, string Astr_ydz) { byte[] Astr_jyjg = new byte[256], Astr_clxx = new byte[256]; int Aint_clbz = 0; webService.yhcall("002", "", Encoding.Default.GetBytes(""), "", "", ref Astr_jyjg, ref Aint_clbz, ref Astr_clxx); if (Aint_clbz <= 0) { Service_NCSB.WriteLog("申请交易流水号失败:[" + Astr_lydz + "|" + Astr_ydz + "]"); jylsh = ""; return(jylsh); } XmlDocument doc = new XmlDocument(); try { doc.InnerXml = Encoding.Default.GetString(Astr_jyjg); jylsh = doc.SelectSingleNode("jyjg/jylsh").InnerText; } catch (Exception err) { Service_NCSB.WriteLog("Exception:[" + err.Message + "]"); jylsh = ""; } return(jylsh); }
public static string yhcancel(string XmlPara01, ref string retcode) { string Astr_jylsh, Astr_lydz, Astr_ydz, strRecvXml = ""; byte[] Astr_jyjg = new byte[128], Astr_clxx = new byte[128], Astr_jysj = new byte[128]; int Aint_clbz = 0; if (!init()) { Service_NCSB.WriteLog("init 错误"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } XmlPara01 = "<Para01>" + XmlPara01 + "</Para01>"; Service_NCSB.WriteLog("XmlPara01[" + XmlPara01 + "]"); XmlDocument xReqPara = new XmlDocument(); try { xReqPara.InnerXml = XmlPara01; Astr_jylsh = xReqPara.SelectSingleNode("Para01/Astr_jylsh").InnerText; Astr_lydz = xReqPara.SelectSingleNode("Para01/Astr_lydz").InnerText; Astr_ydz = xReqPara.SelectSingleNode("Para01/Astr_ydz").InnerText; } catch (Exception err) { Service_NCSB.WriteLog("Exception:[" + err.Message + "]"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } Service_NCSB.WriteLog("Astr_jylsh[" + Astr_jylsh + "]"); Service_NCSB.WriteLog("Astr_lydz[" + Astr_lydz + "]"); Service_NCSB.WriteLog("Astr_ydz[" + Astr_ydz + "]"); webService.yhcancel(Astr_jylsh, Astr_lydz, Astr_ydz, ref Aint_clbz, ref Astr_clxx); strRecvXml += "<Aint_clbz>" + Aint_clbz + "</Aint_clbz>\r\n"; strRecvXml += "<Astr_clxx>" + Encoding.Default.GetString(Astr_clxx) + "</Astr_clxx>\r\n"; retcode = "0000"; return(strRecvXml); }
static public bool getConfigInfo() { try { INIClass inicls = new INIClass(Service_NCSB.MyConfigFile); if (!inicls.ExistINIFile()) { Service_NCSB.WriteLog("inicls错误"); return(false); } cfg_NCSB = new Cfg(); cfg_NCSB.WSip = inicls.IniReadValue("NCSB", "WS_IP"); cfg_NCSB.WSport = inicls.IniReadValue("NCSB", "WS_PORT"); cfg_NCSB.WStimeout = inicls.IniReadValue("NCSB", "WS_TIMEOUT"); cfg_NCSB.ftp_ip = inicls.IniReadValue("NCSB", "FTP_IP"); cfg_NCSB.ftp_user = inicls.IniReadValue("NCSB", "FTP_USER"); cfg_NCSB.ftp_passwd = inicls.IniReadValue("NCSB", "FTP_PASSWD"); cfg_NCSB.ftp_localpath = inicls.IniReadValue("NCSB", "FTP_LOCALPATH"); if (cfg_NCSB.ftp_ip == "" || cfg_NCSB.ftp_user == "" || cfg_NCSB.ftp_passwd == "") { Service_NCSB.WriteLog("ftp配置错误"); return(false); } if (cfg_NCSB.WSip == "" || cfg_NCSB.WSport == "") { Service_NCSB.WriteLog("WS配置错误"); return(false); } if (cfg_NCSB.WStimeout == "") { cfg_NCSB.WStimeout = "200000"; } } catch (Exception err) { Service_NCSB.WriteLog("getConfigInfo错误" + err.Message); return(false); } return(true); }
public static string szCall(string XmlPara01, string XmlPkg, ref string retcode) { /*aaz400:社保机构代码511300 tradeId:交易号 aae008:银行编号(测试定为103) inputXml:输入报文*/ string aaz400 = "511300", tradeId, aae008 = "103", reqseq, reqdate, inputXml, errinfo = "", strRecvXml = ""; //byte[]inputXml=new byte[128]; /*加密方式*/ int encryptKey = 2 | 4; INIClass iniKey = new INIClass(Service_NCSB.MyConfigFile); if (!iniKey.ExistINIFile()) { Service_NCSB.WriteLog("init 错误"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } /*配置密钥*/ string originalKey = iniKey.IniReadValue("KEY", "INIT_KEY"); string key = iniKey.IniReadValue("KEY", "NEW_KEY"); Service_NCSB.WriteLog("original key:[" + originalKey + "]"); Service_NCSB.WriteLog("new key:[" + key + "]"); if (key == "") { strRecvXml = ""; retcode = "9978"; return(strRecvXml); } if (!init()) { Service_NCSB.WriteLog("init 错误"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } XmlPara01 = "<Para01>" + XmlPara01 + "</Para01>"; Service_NCSB.WriteLog("XmlPara01[" + XmlPara01 + "]"); XmlDocument xReqPara = new XmlDocument(); try { xReqPara.InnerXml = XmlPara01; //aaz400 = xReqPara.SelectSingleNode("Para01/aaz400").InnerText; tradeId = xReqPara.SelectSingleNode("Para01/tradeId").InnerText; reqseq = xReqPara.SelectSingleNode("Para01/reqseq").InnerText; reqdate = xReqPara.SelectSingleNode("Para01/reqdate").InnerText; /*设置inputxml属性*/ XmlNode inputXmlNode = xReqPara.SelectSingleNode("Para01/inputxml"); XmlElement inputXmlElem = (XmlElement)inputXmlNode; inputXmlElem.SetAttribute("reqseq", reqseq); inputXmlElem.SetAttribute("reqdate", reqdate); inputXml = xReqPara.SelectSingleNode("Para01/inputxml").OuterXml; //Service_NCSB.WriteLog("aaz400[" + aaz400 + "]"); Service_NCSB.WriteLog("tradeId[" + tradeId + "]"); Service_NCSB.WriteLog("inputXml[" + inputXml + "]"); } catch (Exception err) { /*捕捉xml异常*/ Service_NCSB.WriteLog("Exception:[" + err.Message + "]"); strRecvXml = ""; retcode = "9996"; return(strRecvXml); } /*TODO:对帐处理*/ if (tradeId == "NC39006") { XmlDocument PkgXml = new XmlDocument(); PkgXml.InnerXml = XmlPkg; XmlNodeList fcNode = PkgXml.SelectNodes("ap/fc"); int fcLengh = fcNode.Count; XmlNode inputXmlNode = xReqPara.SelectSingleNode("Para01/inputxml"); //XmlElement inputXmlElem = (XmlElement)inputXmlNode; XmlElement rows = xReqPara.CreateElement("rows");//创建rows inputXmlNode.AppendChild(rows); for (int i = 0; i < fcLengh; i++) { XmlElement row = xReqPara.CreateElement("row"); string tmpfcXml = fcNode.Item(i).InnerXml; row.InnerXml = tmpfcXml; rows.AppendChild(row); } inputXml = xReqPara.SelectSingleNode("Para01/inputxml").OuterXml; Service_NCSB.WriteLog("inputXml[" + inputXml + "]"); //xReqPara.AppendChild(fcNode); //Service_NCSB.WriteLog("fc[") } /*签到*/ if (tradeId == "T0102") { /*新密钥*/ string newKey = ""; /*社保返回xml*/ string recvxmlDe = ""; try { /*加密方式*/ //int encryptKey = 2 | 4; /*加密xml*/ string encryptXmlKey = javaEncrypt.encrypt(inputXml, originalKey, encryptKey); /*调用*/ string recvxmlEn = webNCDC.szCall(aaz400, tradeId, encryptXmlKey, encryptKey.ToString(), aae008); Service_NCSB.WriteLog("签到返回加密[" + recvxmlEn + "]"); /*解密*/ recvxmlDe = javaEncrypt.decrypt(recvxmlEn, originalKey, encryptKey); Service_NCSB.WriteLog("签到返回解密[" + recvxmlDe + "]"); //recvxmlDe = "<result><code>1</code><message>成功</message><newkey>3333333311111111</newkey><sysdt>20161206161433</sysdt></result>"; } catch (Exception err) { /*捕捉签到调用及加解密异常*/ Service_NCSB.WriteLog("err=[" + err.Message + "]"); retcode = "0998"; strRecvXml = ""; return(strRecvXml); } xReqPara.LoadXml(recvxmlDe); /*判断社保返回结果*/ string returnCode = xReqPara.SelectSingleNode("result/code").InnerText; if (returnCode == "1") { newKey = xReqPara.SelectSingleNode("result/newkey").InnerText; Service_NCSB.WriteLog("newKey[" + newKey + "]"); iniKey.IniWriteValue("KEY", "NEW_KEY", newKey); } retcode = "0000"; recvxmlDe = xReqPara.SelectSingleNode("result").OuterXml; Service_NCSB.WriteLog("处理社保返回报文[" + recvxmlDe + "]"); return(recvxmlDe); } try { /*TODO:调用社保接口*/ //strRecvXml="<result><code>1</code><message></message><output><rows><row><aae001>2016</aae001><aae041>201601</aae041><aae042>201612</aae042></row></rows></output></result>"; //string keyEncrypt="1111111133333333"; //int entype = 2 | 4;//加密方式 string inputXmlEncrypt = javaEncrypt.encrypt(inputXml, key, encryptKey); //报文内容 Service_NCSB.WriteLog("加密inputXml[" + inputXmlEncrypt + "]"); string strTmpRecv = webNCDC.szCall(aaz400, tradeId, inputXmlEncrypt, encryptKey.ToString(), aae008); //得到社保原始报文 Service_NCSB.WriteLog("社保返回报文加密recvXml[" + strTmpRecv + "]"); strRecvXml = javaEncrypt.decrypt(strTmpRecv, key, encryptKey); Service_NCSB.WriteLog("社保返回报文解密[" + strRecvXml + "]"); } catch (Exception err) { /*捕捉webservice调用及加解密异常*/ Service_NCSB.WriteLog("err=[" + err.Message + "]"); retcode = "0998"; strRecvXml = ""; return(strRecvXml); } retcode = "0000"; xReqPara.LoadXml(strRecvXml); strRecvXml = xReqPara.SelectSingleNode("result").OuterXml; return(strRecvXml); }
/// <summary> ///南充社保接口 /// </summary> /// <param name="XmlPara01">交易编号</param> /// <returns>WS返回字符串</returns> public static string yhcall(string XmlPara01, ref string retcode) { string Astr_jyh, Astr_jylsh, Astr_lydz, Astr_ydz, errinfo = "", strRecvXml = ""; byte[] Astr_jyjg = new byte[128], Astr_clxx = new byte[128], Astr_jysj = new byte[128]; int Aint_clbz = 0; if (!init()) { Service_NCSB.WriteLog("init 错误"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } XmlPara01 = "<Para01>" + XmlPara01 + "</Para01>"; Service_NCSB.WriteLog("XmlPara01[" + XmlPara01 + "]"); XmlDocument xReqPara = new XmlDocument(); try { xReqPara.InnerXml = XmlPara01; Astr_jyh = xReqPara.SelectSingleNode("Para01/Astr_jyh").InnerText; //Service_NCSB.WriteLog("Astr_jyh[" + Astr_jyh + "]"); Astr_jylsh = xReqPara.SelectSingleNode("Para01/Astr_jylsh").InnerText; //Service_NCSB.WriteLog("Astr_jylsh[" + Astr_jylsh + "]"); Astr_lydz = xReqPara.SelectSingleNode("Para01/Astr_lydz").InnerText; //Service_NCSB.WriteLog("Astr_lydz[" + Astr_lydz + "]"); Astr_ydz = xReqPara.SelectSingleNode("Para01/Astr_ydz").InnerText; //Service_NCSB.WriteLog("Astr_ydz[" + Astr_ydz + "]"); if (Astr_jyh == "003" || Astr_jyh == "004") {//处理性交易,需要申请流水号 //Astr_jylsh = getjylsh(Astr_lydz, Astr_ydz); if (Astr_jylsh == "") { Service_NCSB.WriteLog("申请交易流水号不能为空:[" + Astr_lydz + "|" + Astr_ydz + "]"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } Service_NCSB.WriteLog("jylsh=[" + jylsh + "]"); } Astr_jysj = Encoding.Default.GetBytes(xReqPara.SelectSingleNode("Para01/Astr_jysj").InnerXml); } catch (Exception err) { Service_NCSB.WriteLog("Exception:[" + err.Message + "]"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } if (Astr_jyh == "998")//对帐文件上传成功,可以对帐 { string jysj, wjdx; string wjmc = xReqPara.SelectSingleNode("Para01/Astr_jysj/jysj/wjmc").InnerText; if (!File.Exists(cfg_NCSB.ftp_localpath + "\\" + wjmc)) { Service_NCSB.WriteLog("ftp文件不存在!"); strRecvXml = ""; retcode = "9989"; return(strRecvXml); } if (!Func.StrFile2XmlFile(cfg_NCSB.ftp_localpath + "/" + wjmc, cfg_NCSB.ftp_localpath + "\\NCSB\\" + wjmc + ".txt", out strRecvXml)) { Service_NCSB.WriteLog(strRecvXml); strRecvXml = ""; retcode = "9989"; return(strRecvXml); } Service_NCSB.WriteLog("StrFile2XmlFile end."); FileInfo fi = new FileInfo(cfg_NCSB.ftp_localpath + "\\NCSB\\" + wjmc + ".txt"); Astr_jysj = Encoding.Default.GetBytes("<jysj><wjmc>" + wjmc + "</wjmc><wjdx>" + fi.Length + "</wjdx></jysj>"); try { FTP ftpObj; Service_NCSB.WriteLog("ftp_ip=[" + cfg_NCSB.ftp_ip + "]"); ftpObj = new FTP(cfg_NCSB.ftp_ip, cfg_NCSB.ftp_user, cfg_NCSB.ftp_passwd); Service_NCSB.WriteLog("FTP Create !"); if (!ftpObj.Put("", cfg_NCSB.ftp_localpath + "\\NCSB\\" + wjmc + ".txt", out errinfo)) { Service_NCSB.WriteLog("Exception:[" + errinfo + "]"); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } } catch (Exception err) { Service_NCSB.WriteLog(err.Message); strRecvXml = ""; retcode = "0998"; return(strRecvXml); } } Service_NCSB.WriteLog("Astr_jyh[" + Astr_jyh + "]"); Service_NCSB.WriteLog("Astr_jylsh[" + Astr_jylsh + "]"); Service_NCSB.WriteLog("Astr_jysj[" + Encoding.Default.GetString(Astr_jysj) + "]"); Service_NCSB.WriteLog("Astr_lydz[" + Astr_lydz + "]"); Service_NCSB.WriteLog("Astr_ydz[" + Astr_ydz + "]"); try { webService.yhcall(Astr_jyh, Astr_jylsh, Astr_jysj, Astr_lydz, Astr_ydz, ref Astr_jyjg, ref Aint_clbz, ref Astr_clxx); strRecvXml = "\r\n<Astr_jyjg>" + Encoding.Default.GetString(Astr_jyjg) + "</Astr_jyjg>\r\n"; strRecvXml += "<Aint_clbz>" + Aint_clbz + "</Aint_clbz>\r\n"; string strTmp = Encoding.Default.GetString(Astr_clxx); Service_NCSB.WriteLog("Astr_clxx=[" + strTmp + "]"); if (strTmp.Length >= 32) { strTmp = strTmp.Substring(0, 32); } strRecvXml += "<Astr_clxx>" + strTmp + "</Astr_clxx>\r\n"; //int iTmp = strTmp.IndexOf("jysj:<jysj>"); //if (iTmp>0) // strRecvXml += "<Astr_clxx>" + strTmp.Substring(0, strTmp.IndexOf("jysj:<jysj>") + 4) + "</Astr_clxx>\r\n"; //else // strRecvXml += "<Astr_clxx>" + strTmp + "</Astr_clxx>\r\n"; //Service_NCSB.WriteLog("strRecvXml:[" + strRecvXml + "]"); } catch (Exception err) { Service_NCSB.WriteLog("err=[" + err.Message + "]"); retcode = "9989"; strRecvXml = ""; return(strRecvXml); } //if (Aint_clbz <= 0 ) //{ // Service_NCSB.WriteLog("yhcall失败:[" + Astr_jyh + "|" + Astr_jylsh + "]"); // Service_NCSB.WriteLog(Encoding.Default.GetString(Astr_clxx)); // strRecvXml = ""; // retcode = "0998"; // return strRecvXml; //} //strRecvXml = Encoding.Default.GetString(Astr_jyjg); retcode = "0000"; return(strRecvXml); }