public override JObject Send(long terminalID, string uniCode, string apiURL, string accessSecret = null) { Models.IOT.Command cmd = this.Create(terminalID, uniCode); JObject requestBody = new JObject(); requestBody.Add("TerminalID", terminalID); requestBody.Add("HexPacket", cmd.HexPacket); string key = "Terminal:" + terminalID; string transeURL = new Common.Redis.Helper().HashGet(key, "TranseURL"); string response = Common.HttpClientHelper.HttpPost(transeURL, requestBody.ToString(Newtonsoft.Json.Formatting.None)); return(JObject.Parse(response)); }
/// <summary> /// 根据数据配置文件创建指令实体 /// </summary> /// <param name="terminalID"></param> /// <param name="uniCode"></param> /// <returns></returns> public Models.IOT.Command Create(long terminalID, string uniCode) //,string transeURL,string accessSecret { string hexTerminalID = Convert.ToString(terminalID, 16).PadLeft(8, '0'); long nowTimestamp = Common.Time.GetUTCTimestamp(DateTime.Now); string hexTimeStamp8 = nowTimestamp.ToString("x2").PadLeft(16, '0'); //Convert.ToString(nowTimestamp, 16) string hexTimeStamp6 = (nowTimestamp / 1000).ToString("x2").PadLeft(12, '0'); string hexTimeStamp4 = (nowTimestamp / 1000).ToString("x2").PadLeft(8, '0'); Models.IOT.Instruction ins = Data.Instruction.Get(uniCode); if (!string.IsNullOrWhiteSpace(ins.ChildCmd)) { ins.ChildCmd = ins.ChildCmd.Replace("{Timestamp4}", hexTimeStamp4); byte[] childCmd = Common.Hex.Hex2Bytes(ins.ChildCmd); int childLen = childCmd.Length; childCmd[childLen - 2] = COCOPASS.Helper.NetCoreHelper.Encrypt.Xor(childCmd); ins.Cmd = ins.Cmd.Replace("{ChildCmd}", Common.Hex.Bytes2Hex(childCmd).Replace("-", "")); } ins.Cmd = ins.Cmd.Replace("{TerminalID}", hexTerminalID); ins.Cmd = ins.Cmd.Replace("{Timestamp6}", hexTimeStamp6); byte[] cmd = Common.Hex.Hex2Bytes(ins.Cmd); int len = cmd.Length; int[] intArrayCmd = new int[len]; cmd[len - 2] = COCOPASS.Helper.NetCoreHelper.Encrypt.Xor(cmd); ins.Cmd = Common.Hex.Bytes2Hex(cmd).Replace("-", ""); for (int i = 0; i < len; i++) { intArrayCmd[i] = (sbyte)cmd[i]; } Models.IOT.Command command = new Models.IOT.Command(); command.Packet = intArrayCmd; //command.BytePacket = cmd; command.HexPacket = ins.Cmd; command.TerminalID = terminalID; //command.Sign = COCOPASS.Helper.NetCoreHelper.Encrypt.MD5(accessSecret + terminalID + command.HexPacket + accessSecret); return(command); }
public override JObject Send(long terminalID, string uniCode, string apiURL, string accessSecret = null) { apiURL = "http://xinyun.luyuan.cn/api.ashx?cla=BAILI.Modules.Systems.SessionAction&fn=create&code=JSON"; string response = Common.HttpClientHelper.HttpGet(apiURL); JObject JobResponse = JObject.Parse(response); bool success = (bool)JobResponse["success"]; if (!success) { return(null); } string key = JobResponse["data"].ToString(); apiURL = "http://xinyun.luyuan.cn/api.ashx?cla=BAILI.Modules.User.BLL.LoginAction&fn=getUserByPhone&key=" + key; JObject requestBody = new JObject(); requestBody.Add("PhoneNo", "111111"); requestBody.Add("Pwd", "MTlmOGZkYmMyNzI3NTM4NGRlNjRlNDUxYzhmM2FkMTA="); response = Common.HttpClientHelper.Request(apiURL, requestBody.ToString(Newtonsoft.Json.Formatting.None)); JobResponse = JObject.Parse(response); success = (bool)JobResponse["success"]; if (!success) { return(null); } apiURL = "http://xinyun.luyuan.cn/api.ashx?cla=BAILI.Modules.Nebula.Controller.DeviceOrderHandler&fn=sendHex&key=" + key; Models.IOT.Command cmd = this.Create(terminalID, uniCode); requestBody = new JObject(); requestBody.Add("mid", terminalID); requestBody.Add("cmd", cmd.HexPacket); response = Common.HttpClientHelper.HttpPost(apiURL, requestBody.ToString(Newtonsoft.Json.Formatting.None)); return(JObject.Parse(response)); }