public ResultDTO DownloadInvoic(CommodityOrder commodityOrder, int isRefund, ContextSession contextSession) { ResultDTO resultDto = new ResultDTO() { ResultCode = 1 }; try { string fpdm = ""; string fphm = ""; string kprq = ""; string pdfContent = ""; string pdfMd5 = ""; string msgCode = ""; string msg = ""; XmlDocument xmlDoc = new XmlDocument(); //创建类型声明节点 XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", ""); xmlDoc.AppendChild(node); //创建根节点 XmlNode root = xmlDoc.CreateElement("InvoInfo"); xmlDoc.AppendChild(root); if (isRefund == 0) { CreateNode(xmlDoc, root, "swno", "jh" + commodityOrder.Code); //流水号 } else if (isRefund == 1) { CreateNode(xmlDoc, root, "swno", "tk" + commodityOrder.Code); //流水号 } else if (isRefund == 2) { CreateNode(xmlDoc, root, "swno", "pr" + commodityOrder.Code); //流水号 } CreateNode(xmlDoc, root, "saleTax", CustomConfig.saleTax); //销方税号 测试税号:110101TRDX8RQU1 LogHelper.Info(string.Format("下载电子发票接口所需xml节点。电子发票订单号:{0},xmlContent:{1}", commodityOrder.Id, xmlDoc.InnerXml)); string strXml = xmlDoc.InnerXml; //EInvoiceServiceClient eInvoice = new EInvoiceServiceClient("EInvoiceServicePort"); //var returnInfo = eInvoice.downloadEInvoiceInfo(strXml); //LogHelper.Info(string.Format("下载电子发票接口返回xml结果。XML:{0}", returnInfo)); Jinher.AMP.YJBJMQ.Deploy.CustomDTO.ResultDTO returnInfo = YJBJMQSV.DownloadInvoic(strXml); xmlDoc = new XmlDocument(); xmlDoc.LoadXml(returnInfo.Message); XmlNode rootNode = xmlDoc.SelectSingleNode("DownloadInfo"); if (rootNode != null) { foreach (XmlNode xxNode in rootNode.ChildNodes) { if ("fpdm".Equals(xxNode.Name)) { fpdm = xxNode.InnerText; } else if ("fphm".Equals(xxNode.Name)) { fphm = xxNode.InnerText; } else if ("kprq".Equals(xxNode.Name)) { kprq = xxNode.InnerText; } else if ("pdfContent".Equals(xxNode.Name)) { pdfContent = xxNode.InnerText; } else if ("pdfMd5".Equals(xxNode.Name)) { pdfMd5 = xxNode.InnerText; } } } XmlNode returnMsgnode = xmlDoc.SelectSingleNode("DownloadInfo/returnMsg"); if (returnMsgnode != null) { foreach (XmlNode xxNode in returnMsgnode.ChildNodes) { if ("msgCode".Equals(xxNode.Name)) { msgCode = xxNode.InnerText; } else if ("msg".Equals(xxNode.Name)) { msg = xxNode.InnerText; } } } LogHelper.Info(string.Format( "下载电子发票接口返回xml结果。fpdm:{0},fphm:{1},kprq:{2},pdfContent:{3},pdfMd5:{4},msgCode:{5},msg:{6},电子发票订单号:{7}", fpdm, fphm, kprq, pdfContent, pdfMd5, msgCode, msg, commodityOrder.Id)); HTJSInvoice htjsInvoice = HTJSInvoice.FindByID(commodityOrder.Id); htjsInvoice.Fpdm = fpdm; htjsInvoice.Fphm = fphm; htjsInvoice.Kprq = Convert.ToDateTime(kprq); htjsInvoice.PdfContent = pdfContent; htjsInvoice.PdfMd5 = pdfMd5; htjsInvoice.SMsgCode = msgCode; htjsInvoice.SMsg = msg; htjsInvoice.EntityState = EntityState.Modified; contextSession.SaveObject(htjsInvoice); } catch (Exception ex) { LogHelper.Error(string.Format("调用下载电子发票接口保存相关的返回信息异常。订单id:{0}", commodityOrder.Id), ex); resultDto.Message = "处理异常"; } return(resultDto); }
public ResultDTO CreateInvoic(ContextSession contextSession, CommodityOrder commodityOrder, int isRefund) { LogHelper.Info(string.Format("开始进入开票接口。订单ID(commodityOrder.id:{0}), 是否是开正票(isRefund:{1})", commodityOrder.Id, isRefund)); ResultDTO resultDto = new ResultDTO() { ResultCode = 1 }; try { string fMsgCode = ""; string fMsg = ""; string strXml = CreateXmlFile(commodityOrder, isRefund); if (strXml == "") { resultDto.Message = "保存失败"; return(resultDto); } //EInvoiceServiceClient eInvoice = new EInvoiceServiceClient("EInvoiceServicePort"); //var returnInfo = eInvoice.submitEInvoiceInfo(strXml); //LogHelper.Info(string.Format("开票接口返回xml结果。XML:{0}", returnInfo)); //<ReturnMsg> <msgCode>0000</msgCode> <msg>发票开具数据保存成功</msg> </ReturnMsg> Jinher.AMP.YJBJMQ.Deploy.CustomDTO.ResultDTO returnInfo = YJBJMQSV.CreateInvoic(strXml); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(returnInfo.Message); XmlNode rootNode = xmlDoc.SelectSingleNode("ReturnMsg"); if (rootNode != null) { foreach (XmlNode xxNode in rootNode.ChildNodes) { if ("msgCode".Equals(xxNode.Name)) { fMsgCode = xxNode.InnerText; } else if ("msg".Equals(xxNode.Name)) { fMsg = xxNode.InnerText; } } } LogHelper.Info(string.Format("开票接口返回xml结果。fMsgCode:{0},fMsg:{1}", fMsgCode, fMsg)); HTJSInvoice htjsInvoice = HTJSInvoice.FindByID(commodityOrder.Id); //新增 if (htjsInvoice == null) { htjsInvoice = new HTJSInvoice { Id = commodityOrder.Id, SubId = commodityOrder.SubId, SubTime = DateTime.Now, SwNo = "jh" + commodityOrder.Code, RefundType = 0, ModifiedOn = DateTime.Now, FMsgCode = fMsgCode, FMsg = fMsg, SMsgCode = "1111",//给下载发票一个默认错误码 EntityState = EntityState.Added }; } //补发 处理返回错误码的情况 else { if (isRefund == 0) { htjsInvoice.SwNo = "jh" + commodityOrder.Code; } else if (isRefund == 1) { htjsInvoice.SwNo = "tk" + commodityOrder.Code; htjsInvoice.SMsgCode = "1111"; //给下载发票一个默认错误码 } else if (isRefund == 2) { htjsInvoice.SwNo = "pr" + commodityOrder.Code; htjsInvoice.SMsgCode = "1111"; //给下载发票一个默认错误码 } htjsInvoice.RefundType = isRefund; htjsInvoice.ModifiedOn = DateTime.Now; htjsInvoice.FMsgCode = fMsgCode; htjsInvoice.FMsg = fMsg; htjsInvoice.EntityState = EntityState.Modified; } contextSession.SaveObject(htjsInvoice); } catch (Exception ex) { LogHelper.Error(string.Format("调用开票接口保存相关的返回信息异常。订单id:{0}", commodityOrder.Id), ex); resultDto.Message = "处理异常"; } return(resultDto); }