//开关门上传数据解析 public static OpenOrCloseGateRequest openOrCloseGate(Stream input) { OpenOrCloseGateRequest req = new OpenOrCloseGateRequest(); req.Id = Guid.NewGuid(); byte[] src = new byte[42]; int count = readStream(input, src); //3字节ID byte[] id = new byte[3]; Array.Copy(src, 0, id, 0, id.Length); string terminalId = ByteUtils.byteToHexStr(id); req.TerminalId = terminalId; //32字节用户id byte[] userId = new byte[32]; Array.Copy(src, id.Length, userId, 0, userId.Length); string dststr = ""; for (int i = 0; i < userId.Length; i++) { string c = ((char)userId[i]).ToString(); dststr = dststr + c; // string str = System.Text.Encoding.ASCII.GetString(userId); } //byte[] srcUserId=new byte[16]; // Array.Copy(userId, 0, srcUserId, 0, srcUserId.Length); // string hexstr = ByteUtils.byteToHexStr(userId); //string dststr = ""; //for (int i = 0; i < hexstr.Length; i = i + 2) //{ // dststr = dststr + hexstr.Substring(i + 1, 1); //} //req.UserId = dststr; req.UserId = dststr; byte[] year = new byte[2]; Array.Copy(src, id.Length + userId.Length, year, 0, year.Length); byte[] month = new byte[1]; Array.Copy(src, id.Length + userId.Length + year.Length, month, 0, month.Length); //日 1byte byte[] d = new byte[1]; Array.Copy(src, id.Length + userId.Length + year.Length + month.Length, d, 0, d.Length); //时 1byte byte[] hour = new byte[1]; Array.Copy(src, id.Length + userId.Length + year.Length + month.Length + d.Length, hour, 0, hour.Length); //分 1byte byte[] min = new byte[1]; Array.Copy(src, id.Length + userId.Length + year.Length + month.Length + d.Length + hour.Length, min, 0, min.Length); //秒 byte[] sec = new byte[1]; Array.Copy(src, id.Length + userId.Length + year.Length + month.Length + d.Length + hour.Length + min.Length, sec, 0, sec.Length); req.SampleTime = "" + ByteUtils.byteToHexStr(year) + ByteUtils.byteToHexStr(month) + ByteUtils.byteToHexStr(d) + ByteUtils.byteToHexStr(hour) + ByteUtils.byteToHexStr(min) + ByteUtils.byteToHexStr(sec); return(req); }
public OpenOrCloseGateRequest uploadOpenOrCloseGate(OpenOrCloseGateRequest input) { OpenOrCloseGateRequest open = db_realtime.AddOpenOrCloseGate(input); if (open != null) { //开门开始计费 //修改订单状态为开门状态 //dbOrd_realtime.updateToOpenDoor(open.UserId); return(open); } return(null); }
public OpenOrCloseGateRequest AddOpenOrCloseGate(OpenOrCloseGateRequest open) { if (open != null) { using (DataContext db = new SqlserverContext()) { Table <OpenOrCloseGateRequest> T_order = db.GetTable <OpenOrCloseGateRequest>(); T_order.InsertOnSubmit(open); db.SubmitChanges(); return(open); } } return(null); }
//开关门上传数据解析 public static IList <OpenOrCloseGateRequest> openOrCloseGate(Stream input) { IList <OpenOrCloseGateRequest> list = new List <OpenOrCloseGateRequest>(); OpenOrCloseGateRequest req = new OpenOrCloseGateRequest(); byte[] src = new byte[1000]; int count = readStream(input, src); int begin = 3; //3字节ID byte[] id = new byte[3]; Array.Copy(src, 0, id, 0, id.Length); string terminalId = ByteUtils.byteToHexStr(id); while (begin < count) { req.TerminalId = terminalId; //手机号码 byte[] tel = new byte[6]; Array.Copy(src, 3, tel, 0, tel.Length); req.UserId = ByteUtils.byteToHexStr(tel); //日 1byte byte[] d = new byte[1]; Array.Copy(src, 3 + 6, d, 0, d.Length); //时 1byte byte[] hour = new byte[1]; Array.Copy(src, 3 + 6 + 1, hour, 0, hour.Length); //分 1byte byte[] min = new byte[1]; Array.Copy(src, 3 + 6 + 1 + 1, min, 0, min.Length); req.SampleTime = d[0] + "日" + hour[0] + "时" + min[0] + "分"; list.Add(req); begin += 6 + 3; } return(list); }
public void OpenCloseGate() { LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 收到终端开门请求"); try { Stream inputStream = Request.GetBufferedInputStream(); //byte[] src = new byte[42]; //int offset = 0; //int result = 0; //int cnt = 0; //while ((result = inputStream.ReadByte()) != -1) //{ // cnt++; // src[offset] = (byte)result; // offset++; //} // LogerHelper.debug("平台收到数据:"+ByteUtils.byteToHexStr(src)); OpenOrCloseGateRequest opens = RealTimeAnalysis.openOrCloseGate(inputStream); opens.CreateTime = DateTime.Now; orderbll.uploadOpenOrCloseGate(opens); }catch (Exception e) { LogHelper.Exception(this.Url.RequestContext, e); } }