123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- /******************************************************************************
- * 文件名称: CardReader.cs
- * 文件说明: 读卡的封装,包括社保卡,身份证,电子凭证等等
- * 当前版本: V1.0
- * 创建日期: 2022-06-20
- *
- * * 2020-06-20: 增加 CardReader 类
- * ***** 2020-06-20: 增加 CardReader 方法,获取URL地址,USER信息,地方版SSCard.dll使用
- * ***** 2020-06-20: 增加 CardReader 方法重载,国家版电子凭证使用
- * ***** 2020-06-20: 增加 Init 方法,SSCard环境初始化
- * ***** 2020-06-20: 增加 ReadCardBas 方法,读社保卡
- * ***** 2020-06-20: 增加 VerifyPIN 方法,验证密码
- * ***** 2020-06-20: 增加 ChangePIN 方法,修改密码
- * ***** 2020-06-20: 增加 ReadSFZ 方法,读身份证
- * ***** 2020-06-20: 增加 GetQRBase 方法,读二维码
- * ***** 2020-06-20: 增加 NationEcTrans 方法,读电子凭证(国家版)
- ******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using PTMedicalInsurance.Variables;
- using PTMedicalInsurance.Helper;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System.Windows.Forms;
- using Sunny.UI;
- using System.Security.Policy;
- using System.IO;
- namespace PTMedicalInsurance.Common
- {
- class CardReader
- {
- private string URL;
- private string User;
- public CardReader()
- {
- }
- public CardReader(string URL, string User)
- {
- this.URL = URL;
- this.User = User;
- }
- const string DllPath = @"D:\CardDLL\SSCard.dll";
- [DllImport("SSCard.dll", EntryPoint = "Init", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern int Init(StringBuilder pURL, StringBuilder pUser);
- [DllImport("SSCard.dll", EntryPoint = "ReadCardBas", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern int ReadCardBas(StringBuilder pOutBuff, int nOutBuffLen, StringBuilder pSignBuff, int nSignBuffLen);
- [DllImport("SSCard.dll", EntryPoint = "VerifyPIN", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern int VerifyPIN(StringBuilder pOutBuff, int nOutBuffLen);
- [DllImport("SSCard.dll", EntryPoint = "ChangePIN", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern int ChangePIN(StringBuilder pOutBuff, int nOutBuffLen);
- [DllImport("SSCard.dll", EntryPoint = "ReadSFZ", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern int ReadSFZ(StringBuilder pOutBuff, int nOutBuffLen, StringBuilder pSignBuff, int nSignBuffLen);
- [DllImport("SSCard.dll", EntryPoint = "GetQRBase", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern int GetQRBase(int nTimeout, StringBuilder pOutBuff, int nOutBuffLen, StringBuilder pSignBuff, int nSignBuffLen);
- //电子凭证
- [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData);
- public int Init()
- {
- string errMsg = "";
- int result = -1;
- try
- {
- StringBuilder sbURL = new StringBuilder(URL);
- StringBuilder sbUSER = new StringBuilder(User);
- result = Init(sbURL, sbUSER);
- return result;
- }
- catch (Exception ex)
- {
- errMsg = ex.Message;
- return result;
- }
- finally
- {
- Global.writeLog("初始化", URL + ":" + User, result.ToString() + ":" + errMsg);
- }
- }
- public int ReadCardBas(out string basInfo, out string regInfo)
- {
- basInfo = ""; regInfo = "";
- int rtn = -1;
- try
- {
- StringBuilder sbBasInfo = new StringBuilder(1024);
- StringBuilder sbRegInfo = new StringBuilder(1024);
- rtn = ReadCardBas(sbBasInfo, 1024, sbRegInfo, 1024);
- basInfo = sbBasInfo.ToString();
- regInfo = sbRegInfo.ToString();
- return rtn;
- }
- catch (Exception ex)
- {
- basInfo = "ReadCardBas异常:" + ex.Message;
- return rtn;
- }
- finally
- {
- Global.writeLog("读社保卡(" + URL + ")", regInfo, basInfo);
- }
- }
- public int VerifyPIN(out string outBuff)
- {
- outBuff = "";
- int rtn = -1;
- try
- {
- StringBuilder sbOutBuff = new StringBuilder(1024);
- rtn = VerifyPIN(sbOutBuff, 1024);
- outBuff = sbOutBuff.ToString();
- return rtn;
- }
- catch (Exception ex)
- {
- outBuff = "VerifyPIN:" + ex.Message;
- return rtn;
- }
- }
- public int ChangePIN(out string outBuff)
- {
- outBuff = "";
- int rtn = -1;
- try
- {
- StringBuilder sbOutBuff = new StringBuilder(1024);
- rtn = ChangePIN(sbOutBuff, 1024);
- outBuff = sbOutBuff.ToString();
- return rtn;
- }
- catch (Exception ex)
- {
- outBuff = "ChangePIN:" + ex.Message;
- return rtn;
- }
- }
- public int ReadSFZ(out string OutBuff, out string SignBuff)
- {
- OutBuff = ""; SignBuff = "";
- int rtn = -1;
- try
- {
- StringBuilder sbOutBuff = new StringBuilder(1024);
- StringBuilder sbSignBuff = new StringBuilder(1024);
- rtn = ReadSFZ(sbOutBuff, 1024, sbSignBuff, 1024);
- OutBuff = sbOutBuff.ToString();
- SignBuff = sbSignBuff.ToString();
- return rtn;
- }
- catch (Exception ex)
- {
- OutBuff = "ReadSFZ 异常:" + ex.Message;
- return rtn;
- }
- }
- public int GetQRBase(int timeout, out string OutBuff, out string SignBuff)
- {
- OutBuff = ""; SignBuff = "";
- int rtn = -1;
- try
- {
- StringBuilder sbOutBuff = new StringBuilder(1024);
- StringBuilder sbSignBuff = new StringBuilder(1024);
- rtn = GetQRBase(timeout, sbOutBuff, 1024, sbSignBuff, 1024);
- OutBuff = sbOutBuff.ToString();
- SignBuff = sbSignBuff.ToString();
- return rtn;
- }
- catch (Exception ex)
- {
- OutBuff = "GetQRBase 异常:" + ex.Message;
- return rtn;
- }
- }
- public string NationEcTrans(string URL, string InData, out string OutData)
- {
- OutData = "";
- try
- {
- StringBuilder sbURL = new StringBuilder(URL);
- StringBuilder sbInData = new StringBuilder(InData);
- StringBuilder sbOutData = new StringBuilder(1024);
- IntPtr pRtn = NationEcTrans(sbURL, sbInData, sbOutData);
- OutData = sbOutData.ToString();
- string rtn = Marshal.PtrToStringAnsi(pRtn);
- return rtn;
- }
- catch (Exception ex)
- {
- OutData = "NationEcTrans 异常:" + ex.Message;
- return "-1";
- }
- finally
- {
- Global.writeLog("电子凭证(" + URL + ")", InData, OutData);
- }
- }
- }
- class CardReader_HLJ
- {
- string progID = "SCardDriverHLJ.SCard";
- System.Type ComType;
- object ComInstance;
- public CardReader_HLJ()
- {
- ComType = Type.GetTypeFromProgID(progID);
- // 创建Com的实例
- if (ComType != null)
- {
- //创建实例
- ComInstance = Activator.CreateInstance(ComType);
- }
- }
- public string readCardBas(int type, string hospNO)
- {
- if (ComType == null)
- {
- return "ComType为空!";
- }
- if (ComInstance == null)
- {
- return "ComInstance为空!";
- }
- try
- {
- //设置需要设置的参数值
- object[] ParamArray = new object[2];
- ParamArray[0] = type;
- ParamArray[1] = hospNO;
- ParameterModifier[] ParamMods = new ParameterModifier[1];
- ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
- ParamMods[0][0] = true;
- ParamMods[0][1] = true; // 设置第二个参数为返回参数,调用含有ParameterModifier数组的重载函数
- object o = ComType.InvokeMember("iReadCardBas", // 接口函数名
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- ComInstance, // 调用的COM组件
- ParamArray, // 参数数组
- ParamMods, // 指定返回参数的ParameterModifier数组
- null,
- null);
- //string Msg = "加载成功:" + ParamArray[1].ToString();
- //Global.inf.writeLog(Msg + "___" + ParamArray[0].ToString());
- return o.ToString();
- }
- catch (Exception ex)
- {
- return "异常:" + ex.Message;
- }
- }
- }
- class ChangChun_DRG
- {
- //长春市DRG付费管理
- #region【长春东软DRG微服务版动态库相关调用】
- [DllImport("HmaSiInterface.dll", EntryPoint = "INIT", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
- public static extern int INIT_DRG(ref StringBuilder pErrMsg);
- //BASE64 编码函数
- [DllImport("HmaSiInterface.dll", EntryPoint = "PASCAL EXPORT FileToBase64", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
- public static extern int PASCALEXPORTFileToBase64_DRG(StringBuilder filePath, ref StringBuilder OutData, int len);
- //交易函数
- [DllImport("HmaSiInterface.dll", EntryPoint = "BUSINESS_HANDLE", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- public static extern int BUSINESS_HANDLE_DRG(string InData, StringBuilder OutData);
- /// <summary>
- /// DRG动态库初始化-INIT
- /// </summary>
- /// <param name="Msg"></param>
- /// <returns></returns>
- public int Init_DRG(out string Msg)
- {
- string errMsg = ""; Msg = "";
- int rnt = -1;
- JObject joRtn = new JObject();
- try
- {
- StringBuilder sbReMsg = new StringBuilder(2048);
- rnt = INIT_DRG(ref sbReMsg);
- Msg = sbReMsg.ToString();
- return rnt;
- }
- catch (Exception ex)
- {
- if (joRtn["infcode"] == null)
- { joRtn.Add("infcode", -1); }
- if (joRtn["err_msg"] == null)
- { joRtn.Add("err_msg", "INIT_DRG异常:" + ex.Message); }
- Msg = JsonHelper.Compress(joRtn);
- return rnt;
- }
- finally
- {
- Global.writeLog("Init_DRG初始化", "", rnt.ToString() + ": 无入参!");
- }
- }
- /// <summary>
- /// DRG动态库交易函数调用-BUSINESS_HANDLE
- /// </summary>
- /// <param name="Input"></param>
- /// <param name="OutPut"></param>
- /// <returns></returns>
- public int Business_DRG(string Input, out string OutPut)
- {
- string errMsg = ""; OutPut = "";
- int rnt = -1;
- JObject joRtn = new JObject();
- try
- {
- StringBuilder sbOutInfo = new StringBuilder(1024);
- MessageBox.Show("业务入参:"+Input);
- rnt = BUSINESS_HANDLE_DRG(Input, sbOutInfo);
- MessageBox.Show("返回值:"+ rnt.ToString()+ ", "+sbOutInfo.ToString());
- OutPut = sbOutInfo.ToString();
- return rnt;
- }
- catch (Exception ex)
- {
- if (joRtn["infcode"] == null)
- { joRtn.Add("infcode", -1); }
- if (joRtn["err_msg"] == null)
- { joRtn.Add("err_msg", "BUSINESS_HANDLE_DRG异常:" + ex.Message); }
- OutPut = JsonHelper.Compress(joRtn);
- return rnt;
- }
- finally
- {
- Global.writeLog("BUSINESS_HANDLE_DRG业务调用", Input, OutPut);
- }
- }
- /// <summary>
- /// DRG动态库交易函数调用-BUSINESS_HANDLE
- /// </summary>
- /// <param name="filePath"></param>
- /// <param name="OutPut"></param>
- /// <param name="DataLen"></param>
- /// <returns></returns>
- public int FileToBase64_DRG(string filePath, out string OutPut, int DataLen)
- {
- string errMsg = ""; OutPut = "";
- int rnt = -1, retLen = 0;
- JObject joRtn = new JObject();
- try
- {
- StringBuilder sbInputInfo = new StringBuilder(filePath);
- StringBuilder sbOutInfo = new StringBuilder(1024);
- retLen = DataLen;
- rnt = PASCALEXPORTFileToBase64_DRG(sbInputInfo, ref sbOutInfo, retLen);
- OutPut = sbOutInfo.ToString();
- return rnt;
- }
- catch (Exception ex)
- {
- if (joRtn["infcode"] == null)
- { joRtn.Add("infcode", -1); }
- if (joRtn["err_msg"] == null)
- { joRtn.Add("err_msg", "PASCALEXPORTFileToBase64_DRG异常:" + ex.Message); }
- OutPut = JsonHelper.Compress(joRtn);
- return rnt;
- }
- finally
- {
- Global.writeLog("PASCALEXPORTFileToBase64_DRG业务调用", filePath, OutPut);
- }
- }
- #endregion
- }
- class CardReader_JIL
- { //吉林基线版东软读卡
- #region
- //初始化
- [DllImport("HeaSecReadInfo.dll", EntryPoint = "Init", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
- public static extern int Init([MarshalAs(UnmanagedType.LPArray)] byte[] pInitInfo, [MarshalAs(UnmanagedType.LPArray)] byte[] pErrMsg);
- [DllImport("HeaSecReadInfo.dll", EntryPoint = "ReadCardBas", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
- public static extern int ReadCardBas([MarshalAs(UnmanagedType.LPArray)] byte[] pCardInfo, [MarshalAs(UnmanagedType.LPArray)] byte[] pBusiCardInfo);
- //[DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
- //public static extern long NationEcTrans(string strUrl, string InData, [MarshalAs(UnmanagedType.LPArray)] byte[] OutData);
- [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData);
- [DllImport("HeaSecReadInfo.dll", EntryPoint = "VerifyPIN", CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
- public static extern int VerifyPIN([MarshalAs(UnmanagedType.LPArray)] byte[] pOutBuff);
- [DllImport("HeaSecReadInfo.dll", EntryPoint = "ReadSFZ", CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- public static extern int ReadSFZ([MarshalAs(UnmanagedType.LPArray)] byte[] pPath, [MarshalAs(UnmanagedType.LPArray)] byte[] pOutBuff, [MarshalAs(UnmanagedType.LPArray)] byte[] pOutBusiBuff);
- [DllImport("HeaSecReadInfo.dll", EntryPoint = "GetClientID", CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
- public static extern int GetClientID([MarshalAs(UnmanagedType.LPArray)] byte[] pOutBuff);
- // [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
- // public static extern long NationEcTrans([MarshalAs(UnmanagedType.LPArray)] byte[] strUrl, [MarshalAs(UnmanagedType.LPArray)] byte[] InData, [MarshalAs(UnmanagedType.LPArray)] byte[] OutData);
- #endregion
- public int initCard()
- {
- int rtn = 0;
- try
- {
- string str = "{\"IP\":\"ddjk.jlhs.gov.cn\",\"PORT\":20215,\"TIMEOUT\":60,\"LOG_PATH\":\"C:/neu_log/\",\"SFZ_DRIVER_TYPE\":1}";
- byte[] input = System.Text.Encoding.Default.GetBytes(str);
- byte[] output = new byte[300];
- rtn = Init(input, output);
- }
- catch (Exception e)
- {
- rtn = -1;
- MessageBox.Show(e.Message);
- }
- return rtn;
- }
- public int readCard(out string Instr, out string outstr)
- {
- int rtn = 0;
- Instr = "";
- outstr = "";
-
- try
- {
- if (initCard() != 0)
- {
- rtn = -1;
- return rtn;
- }
-
- byte[] rin = new byte[500];
- byte[] rout = new byte[500];
-
- if (ReadCardBas(rin, rout) != 0)
- {
- rtn = -1;
- MessageBox.Show(System.Text.Encoding.Default.GetString(rin));
- return rtn;
- }
- Instr = System.Text.Encoding.Default.GetString(rin);
- outstr = System.Text.Encoding.Default.GetString(rout);
- }
- catch (Exception e)
- {
- rtn = -1; MessageBox.Show(e.Message);
- }
- return rtn;
- }
- //读身份证
- public int readSFZ(out string Instr, out string outstr)
- {
- int rtn = 0;
- Instr = "";
- outstr = "";
- string pth = @"D:/";
- try
- {
- if (initCard() != 0)
- {
- rtn = -1;
- return rtn;
- }
- byte[] Pth = new byte[500];
- byte[] rin = new byte[500];
- byte[] rout = new byte[500];
- Pth = System.Text.Encoding.Default.GetBytes(pth);
- if (ReadSFZ(Pth,rin, rout) != 0)
- {
- rtn = -1;
- MessageBox.Show(System.Text.Encoding.Default.GetString(rin));
- return rtn;
- }
- Instr = System.Text.Encoding.Default.GetString(rin);
- outstr = System.Text.Encoding.Default.GetString(rout);
- }
- catch (Exception e)
- {
- rtn = -1; MessageBox.Show(e.Message);
- }
- return rtn;
- }
- public int getCid(out string outstr)
- {
- int rtn = 0;
- outstr = "";
- try
- {
- if (initCard() != 0)
- {
- rtn = -1;
- return rtn;
- }
- byte[] rout = new byte[500];
- GetClientID(rout);
- outstr = System.Text.Encoding.Default.GetString(rout);
- }
- catch (Exception e)
- {
- rtn = -1; MessageBox.Show(e.Message);
- }
- return rtn;
- }
- //public int InsuQRCodeQuery(string url,string instr,out string outpar)
- //{
- // int rtn = 0;
- // string data = "{\"data\": {\"operatorId\": \"008\", \"operatorName\": \"TEST\", \"officeId\": \"01\",\"officeName\": \"内科\",\"orgId\": \"1234567\",\"businessType\": \"01101\", \"deviceType\": \"SelfService\"},\"orgId\": \"1234567\",\"transType\": \"ec.query\"}";
- // url = "";
- // JObject input = new JObject();
- // byte[] str = new byte[500];
- // //outstr = "";
- // try
- // {
- // NationEcTrans(url, data, str);
- // outpar = System.Text.Encoding.Default.GetString(str);
- // dynamic outputObj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(outpar);
- // MessageBox.Show(outpar);
- // }
- // catch (Exception e)
- // {
- // rtn = -1; MessageBox.Show(e.Message);
- // outpar = "";
- // }
- // return rtn;
- //}
- public string InsuQRCodeQuery(string URL, string InData, out string OutData)
- {
- // MessageBox.Show("进入医保电子凭读卡");
- // MessageBox.Show("入参:" + URL + ":" + InData);
- OutData = "";
- try
- {
- StringBuilder sbURL = new StringBuilder(URL);
- StringBuilder sbInData = new StringBuilder(InData);
- StringBuilder sbOutData = new StringBuilder(2048);
- IntPtr pRtn = NationEcTrans(sbURL, sbInData, sbOutData);
- OutData = sbOutData.ToString();
- string rtn = Marshal.PtrToStringAnsi(pRtn);
- return rtn;
- }
- catch (Exception ex)
- {
- OutData = "NationEcTrans 异常:" + ex.Message;
- return "-1";
- }
- finally
- {
- Global.writeLog("电子凭证(" + URL + ")", InData, OutData);
- }
- }
- //public string InsuQRCodeQuery(string url, string instr, out string outpar)
- //{
- // string code = "0", message = "成功", outResult = "";
- // //dynamic inputEmpParamsObj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(inParams);
- // int initFlag = 0;
- // MessageBox.Show("进入医保电子凭读卡");
- // MessageBox.Show("入参:"+ url + ":"+ instr);
- // try
- // {
- // MessageBox.Show("进入try");
- // //string strUrl = inputEmpParamsObj.url.ToString(); // "http://10.38.22.15:8081/localcfc/api/hsecfc/localQrCodeQuery";
- // string strUrl = url;
- // byte[] strUrlData = System.Text.Encoding.Default.GetBytes(strUrl);
- // //string inputStr = inputEmpParamsObj.inputData.ToString();
- // string inputStr = instr;
- // //"{\"data\":{\"businessType\":\"01101\",\"deviceType\":\"\",\"officeId\":\"32760\",\"officeName\":\"消化内科\",\"operatorId\":\"test001\",\"operatorName\":\"超级管理员\",\"orgId\":\"3502031900111\"},\"orgId\":\"35020319001\",\"transType\":\"ec.query\"}";
- // byte[] inputData = new byte[2048];
- // byte[] ecUrl = new byte[2048];
- // ecUrl= System.Text.Encoding.Default.GetBytes(strUrl);
- // inputData = System.Text.Encoding.Default.GetBytes(instr);
- // MessageBox.Show("进入try1");
- // byte[] outputData = new byte[2048];
- // string outputStr = "";
- // long retData = NationEcTrans(ecUrl, inputData, outputData);
- // MessageBox.Show("进入try2");
- // outputStr = System.Text.Encoding.Default.GetString(outputData);
- // outputStr = CheckStr(outputStr);
- // dynamic outputObj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(outputStr);
- // MessageBox.Show("进入try3");
- // if (outputObj.code != "0")
- // {
- // code = "-100";
- // message = "读取医保电子凭证失败:" + outputObj.message;
- // MessageBox.Show("进入try4");
- // }
- // else
- // {
- // MessageBox.Show("进入try5");
- // message = ""; //ecQrCode
- // string ecToken = outputObj.data.ecToken;
- // string ecQrCode = outputObj.data.ecQrCode;
- // string ecIndexNo = outputObj.data.ecIndexNo;
- // var result = new { ecToken = ecToken, ecQrCode = ecQrCode, ecIndexNo = ecIndexNo };
- // var resultObj = new { errorCode = "0", errorMessage = "", result = result };
- // string resultStr = JsonConvert.SerializeObject(resultObj);
- // MessageBox.Show("进入try6");
- // outpar = resultStr;
- // MessageBox.Show("电子凭证返参:"+ outpar);
- // return resultStr;
- // }
- // }
- // catch (Exception error)
- // {
- // code = "-1000";
- // message = "产生异常" + error.ToString();
- // }
- // var outlist = new { errorCode = code, errorMessage = message };
- // string outSerialize = JsonConvert.SerializeObject(outlist);
- // outpar = "";
- // return outSerialize;
- //}
- public static string CheckStr(string str)
- {
- int len = str.Length;
- string newStr = "";
- for (var i = 0; i < len; i++)
- {
- if ((int)System.Text.Encoding.Default.GetBytes(str.Substring(i, 1))[0] > 0)
- {
- string ret = str.Substring(i, 1);
- newStr = newStr + ret;
- }
- }
- return newStr;
- }
- }
- }
|