/// <summary> /// 公交查询 /// </summary> /// <param name="param"></param> /// <returns></returns> public BusQueryThatInfo BusQuery2(BusQueryParam param) { BusQueryThatInfo busQueryInfo = new BusQueryThatInfo(); Dictionary <String, String> parameters = new Dictionary <String, String>(); parameters.Add("authcode", param.authcode); parameters.Add("servicename", param.servicename); parameters.Add("trandateTime", param.trandateTime); parameters.Add("reqsn", param.reqsn); parameters.Add("opno", param.opno); parameters.Add("scode", param.scode); parameters.Add("terno", param.terno); parameters.Add("tradeno", param.tradeno); parameters.Add("btype", param.btype); parameters.Add("inapdu", param.inapdu); parameters.Add("step", param.step); parameters.Add("loginId", param.loginId); parameters.Add("APDUSUM", param.APDUSUM); parameters.Add("APDUDATA", param.APDUDATA); parameters.Add("APDUSW", param.APDUSW); parameters.Add("RETDATA", param.RETDATA); string jsonText = HttpHelper.getHttp(SysConfigHelper.readerNode("BusQueryName"), parameters, null); JObject jsonObj = (JObject)JsonConvert.DeserializeObject(jsonText); JObject msgrsp = (JObject)JsonConvert.DeserializeObject(jsonObj["msgrsp"].ToString()); JObject msghead = (JObject)JsonConvert.DeserializeObject(jsonObj["msghead"].ToString()); JObject cpumsg = (JObject)JsonConvert.DeserializeObject(jsonObj["cpumsg"].ToString()); busQueryInfo.msgrsp = JsonConvert.DeserializeObject <BusQueryThatMsgrsp>(msgrsp.ToString()); busQueryInfo.msghead = JsonConvert.DeserializeObject <BusQueryThatMsghead>(msghead.ToString()); busQueryInfo.cpumsg = JsonConvert.DeserializeObject <BusQueryThatCpumsg>(cpumsg.ToString()); return(busQueryInfo); }
/// <summary> /// 公交卡查询 /// </summary> /// <returns></returns> public static BusQueryThatInfo QueryBus() { bool isSuccess = false; //签到 BusRegisterInfo busRegisterInfo = BusAccess.BusRegister(); if (busRegisterInfo.cpumsg != null) { isSuccess = true; } //公交卡签到未成功 if (isSuccess == false) { throw new Exception("公交卡签到未成功"); } isSuccess = false; BusQueryInfo busQueryInfo = new BusQueryInfo(); //公交卡查询 BusInterface access = new BusInterface(); BusQueryParam param = new BusQueryParam(); string inapdu = ""; string trandateTime = SysBLL.getYYYYMMDDHHMMSSTime(); string reqsn = SysBLL.getSerialNum(); string APDUDATA = ""; string APDUSW = ""; string RETDATA = ""; int APDUSUM = 0; string step = "0"; param.authcode = SysBLL.Authcode; param.servicename = "DS001"; param.trandateTime = trandateTime; param.reqsn = reqsn; param.opno = busRegisterInfo.cpumsg.OUTPUT.OPNO; param.scode = busRegisterInfo.cpumsg.OUTPUT.SCODE; param.terno = SysBLL.getMac(); param.tradeno = SysBLL.getHHMMSSITime10(); param.btype = "1900"; param.inapdu = inapdu; param.step = step; param.loginId = SysBLL.getCpuNo(); //设备ID busQueryInfo = access.BusQuery1(param); if (busQueryInfo.cpumsg.OUTPUT.OUTAPDU.APDU != null) { isSuccess = true; } //公交查询未成功 if (isSuccess == false) { throw new Exception("公交查询未成功"); } isSuccess = false; step = busQueryInfo.cpumsg.OUTPUT.STEP; string status = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.LASTAPDU; BusCardBLL bus = new BusCardBLL(); string port = SysConfigHelper.readerNode("CRT603Port"); //int openRet = CRT603.CRT603Vx_OpenConnection(Int32.Parse(port), 19200); //上电 int iOutAtrLen = 0; byte[] byOutAtrData = new byte[1024]; int chipRet = CRT603.CRT603Vx_RF_chipPower(ref iOutAtrLen, byOutAtrData); string apduData = ""; List <BusQueryApdu> apdu = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.APDU; string result = ""; string last = ""; for (int i = 0; i < apdu.Count; i++) { APDUDATA = APDUDATA + apdu[i].APDUDATA + "|"; result = bus.sendApdu(apdu[i].APDUDATA); last = result.Substring(result.Length - 4); APDUSW = APDUSW + last + "|"; result = result.Remove(result.Length - 4, 4); if (apduData != null) { RETDATA = RETDATA + result + "|"; } Thread.Sleep(20); APDUSUM++; } //CRT603.CRT603Vx_CloseConnection(); APDUDATA = APDUDATA.Remove(APDUDATA.Length - 1, 1); APDUSW = APDUSW.Remove(APDUSW.Length - 1, 1); RETDATA = RETDATA.Remove(RETDATA.Length - 1, 1); BusQueryThatInfo busQueryInfo2 = null; while (true) { param.inapdu = "yes"; param.step = step; param.APDUSUM = APDUSUM.ToString(); param.APDUDATA = APDUDATA; param.APDUSW = APDUSW; param.RETDATA = RETDATA; //表示最后一条 if (status.Equals("01")) { //结果 busQueryInfo2 = access.BusQuery2(param); //处理结果 return(busQueryInfo2); } //继续查询 busQueryInfo2 = access.BusQuery2(param); if (busQueryInfo2.cpumsg.OUTPUT != null) { isSuccess = true; } //公交查询未成功 if (isSuccess == false) { throw new Exception("公交查询未成功"); } isSuccess = false; APDUDATA = ""; APDUSW = ""; RETDATA = ""; List <BusQueryApdu> apdu2 = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.APDU; for (int i = 0; i < apdu.Count; i++) { APDUDATA = APDUDATA + apdu2[i].APDUDATA + "|"; result = bus.sendApdu(apdu2[i].APDUDATA); last = result.Substring(result.Length - 4); result = result.Remove(result.Length - 4, 4); APDUSW = last + APDUSW + "|"; //执行apdu RETDATA = RETDATA + result + "|"; } APDUDATA = APDUDATA.Remove(APDUDATA.Length - 1, 1); APDUSW = APDUSW.Remove(APDUSW.Length - 1, 1); RETDATA = RETDATA.Remove(RETDATA.Length - 1, 1); step = busQueryInfo.cpumsg.OUTPUT.STEP; status = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.LASTAPDU; } }