using Newtonsoft.Json; using PTMedicalInsurance.Variables; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace PTMedicalInsurance.CardReaders { class NationECCodeAPI { private string url { get; set; } //电子凭证 [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData); public NationECCodeAPI(string _url) { url = _url; } public int NationEcTrans(NationECInput nationECInput, out string output ) { output = ""; try { StringBuilder sbURL = new StringBuilder(url); StringBuilder sbInput = new StringBuilder(JsonConvert.SerializeObject(nationECInput)); StringBuilder sbOut = new StringBuilder(40960); IntPtr pInt = NationEcTrans(sbURL, sbInput, sbOut); output = sbOut.ToString(); string str = Marshal.PtrToStringAnsi(pInt); if (str == "0000") { return 0; } else { return -1; } } catch (Exception ex) { output += ex.Message; throw; } finally { Global.writeLog($"NationEcTrans({url})", JsonConvert.SerializeObject(nationECInput),output); } } } class NationECInput { /// /// 机构代码 /// public string orgId { get; set; } /// /// 交易类型 /// public string transType { get; set; } /// /// 请求参数 /// public NationECData data { get; set; } /// /// 扩展参数 /// public string extra { get; set; } } class NationECData { /// /// 医保定点机构代码 /// public string orgId { get; set; } /// /// 用码业务类型 /// public string businessType { get; set; } /// /// 用码业务信息 /// public string businessInfo { get; set; } /// /// 收款员编号 /// public object operatorId { get; set; } /// /// 收款员姓名 /// public string operatorName { get; set; } /// /// 医保科室编号 /// public string officeId { get; set; } /// /// 科室名称 /// public string officeName { get; set; } /// /// 扩展参数 /// public string extData { get; set; } } class EcQueryData:NationECData { /// /// 人脸照片 字符 100k /// public string photoData { get; set; } /// /// 设备类型 /// public string deviceType { get; set; } } class QrcodeGetData : NationECData { /// /// 定点医药机构本次业务流水号 /// public string outBizNo { get; set; } /// /// 设备类型 /// public string deviceType { get; set; } } class EcAuthData:NationECData { /// /// 定点医药机构本次业务流水号 不可重复,每次请求都需要唯一 /// public string outBizNo { get; set; } } class AuthCheckData : NationECData { /// /// 定点医药机构本次业务流水号 不可重复,每次请求都需要唯一 /// public string outBizNo { get; set; } /// /// 实 人 认证 业 务流水号 医保综合服务终端返回的授权码 /// public string authNo { get; set; } /// /// 设备类型 /// public string deviceType { get; set; } } /// /// 医保结算数据实体(继承自 NationECData) /// class SettleNotifyData : NationECData { /// /// 核身或者刷脸的医疗机构业务流水号(必填) /// 需要传核身接口或者电子凭证接口里的流水号 /// public string outBizNo { get; set; } /// /// 医保/自费结算状态(必填) /// SUCCESS:结算成功, FAIL:结算失败, /// REFUND_SUCCESS:退款成功, REFUND_FAIL:退款失败 /// public string medicalSettleState { get; set; } /// /// 实人认证业务流水号(可空) /// public string authNo { get; set; } // operatorId 和 operatorName 已在父类中定义 /// /// 总费用(必填)字符型(金额建议为分或保留小数) /// public string totalFee { get; set; } /// /// 业务场景(必填) /// register:挂号窗口, settle:诊间, drugStore:药店 /// public string bizType { get; set; } /// /// 身份证号码(可空) /// public string idNo { get; set; } /// /// 姓名(可空) /// public string userName { get; set; } /// /// 结算时间(必填)格式如:yyyy-MM-dd HH:mm:ss /// public string setlTime { get; set; } /// /// 定点机构名称(必填) /// public string hospitalName { get; set; } // officeId 和 officeName 已在父类中定义 /// /// 医生姓名(可空) /// public string doctorName { get; set; } /// /// 失败原因(可空) /// public string failReason { get; set; } // ========== 以下字段在 medicalSettleState=SUCCESS 或 REFUND_SUCCESS 时必填 ========== /// /// 医保单据流水号(成功时必填) /// public string medicalSettleNo { get; set; } /// /// 自费费用(成功时必填) /// public string ownAmt { get; set; } /// /// 医保报销费用(成功时必填) /// public string hifAmt { get; set; } /// /// 个人帐户支出(成功时必填) /// public string acctAmt { get; set; } /// /// 统筹基金支出(成功时必填) /// public string hifpAmt { get; set; } /// /// 大额医疗保险支出(可空) /// public string hifmiAmt { get; set; } /// /// 公务员补助(可空) /// public string cvlservAmt { get; set; } /// /// 医疗救助(可空) /// public string maAmt { get; set; } /// /// 单病种定点医疗机构垫支(可空) /// public string hosPreAmt { get; set; } /// /// 药品超标扣款金额(可空) /// public string medOverLmtAmt { get; set; } /// /// 扶贫救助(可空) /// public string mafAmt { get; set; } /// /// 历史起付公务员返还(可空) /// public string cvlservDedcAmt { get; set; } /// /// 帐户余额(可空) /// public string balance { get; set; } } }