public T GetJson <T>(string filename) { string filepath = Path.Combine(this.pathPrefix, filename); JObject jObject = JObject.Parse(File.ReadAllText(filepath)); T thing = jObject.ToObject <T>(); List <string> nullProperties = GetNullProperties(thing.GetType().FullName, thing).ToList(); if (nullProperties.Any()) { string message = System.String.Join("\n", nullProperties .Select(str => "\t- " + str) .Prepend("\nThese properties are missing from '" + filename + "':")); if (throwExceptionOnInvalidJson) { throw new InvalidJsonException(message); } else { System.Console.WriteLine(message); } } return(thing); }
public string get(string data) { // try // { // tou = JSONObject.Parse(data); // // string userid="1"; // // string userpasword="123"; // // string mw=userid+userpasword; // // HttpContext.Session.SetString("token",Program.tool.Get32MD5One(mw)); try { tou = JSONObject.Parse(data); } catch (Exception) { string a1 = "{'type':'error','message':'string change JSONObject Error'}"; a1 = a1.Replace("\'", "\""); return(a1); } tou.Add("islogin", false); if (Request.Headers["token"].ToString().Trim() != "") { string retxt = Program.tool.AES.Decode(Request.Headers["token"].ToString(), "jsd7yfjysd98f7"); JSONObject obj; obj = JSONObject.Parse(retxt); //-----判断有效期 start DateTime objdatetime = (Convert.ToDateTime(obj["date"])); DateTime carrdatetime = DateTime.Now; TimeSpan ts = carrdatetime - objdatetime; if (ts.Days < 30) { //有效 tou.Add("islogin", true); tou.Add("crrloginuserid", obj["userid"].ToString()); } } return(TodoApi.Program.请求接口.请求处理(tou.ToString()).ToString()); // return TodoApi.Program.请求接口.请求处理(tou.ToString()).ToString(); // } // catch (Exception) // { // Console.WriteLine("token=" + HttpContext.Session.GetString("token")); // string a1 = "{'type':'error','message':'string change JSONObject Error'}"; // a1 = a1.Replace("\'", "\""); // return a1; // } }
/// <summary> /// Executes given command and receives response (withholding API inter-command timeout). /// </summary> /// <param name="cmd">Command to execute</param> /// <returns>Response from the server</returns> public JSONObject ExecuteCommand(BaseCommand cmd) { try { return((JSONObject)JSONObject.Parse(this.ExecuteCommand(cmd.ToJSONString()))); } catch (Exception ex) { throw new APICommunicationException("Problem with executing command: " + ex.Message); } }
public string post(string data_) { string data = Request.Form["data"]; Console.WriteLine("login data=" + data); try { tou = JSONObject.Parse(data); } catch (Exception) { string a1 = "{'type':'error','message':'string change JSONObject Error'}"; a1 = a1.Replace("\'", "\""); return(a1); } JSONObject ret = TodoApi.Program.请求接口.请求处理(tou.ToString()); //return TodoApi.Program.请求接口.请求处理(tou.ToString()).ToString(); if (ret["code"].ToString() == "200") { Console.WriteLine("login ok=" + ret["code"].ToString()); //token md5 = 手机号 + 短信验证码 // string token = Program.tool.Get32MD5One(ret["phonenumber"].ToString() + ret["VerificationCode"].ToString()); //--构造token json对象 start JSONObject token = new JSONObject(); token.Add("userid", ret["userid"].ToString()); token.Add("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm")); //--构造token json对象 end //--加密 start string ciphertext = Program.tool.AES.Encode(token.ToString(), "jsd7yfjysd98f7"); // string ciphertext = Program.tool.AES.Encode(token.ToString(), "HttpContextSessionSetString"); // Console.WriteLine("密文=" + ciphertext); //--加密 end // Console.WriteLine("login token=" + token); // Response.HttpContext.Session.SetString("token", token.ToString()); // Response.HttpContext.Session.SetString("userid", ret["userid"].ToString()); ret.Add("token", ciphertext); } return(ret.ToString()); }
/// <summary> /// Executes the HTTP request to Sentry. /// </summary> /// <returns> /// The <see cref="JsonPacket.EventID" /> of the successfully captured JSON packet, or <c>null</c> if it fails. /// </returns> public string Request() { using (var s = this.webRequest.GetRequestStream()) { if (this.ravenClient.Compression) { GzipUtil.Write(this.data.Scrubbed, s); } else { using (var sw = new StreamWriter(s)) { sw.Write(this.data.Scrubbed); } } } using (var wr = (HttpWebResponse)this.webRequest.GetResponse()) { using (var responseStream = wr.GetResponseStream()) { if (responseStream == null) { return(null); } using (var sr = new StreamReader(responseStream)) { var content = sr.ReadToEnd(); #if (net35) var response = JObject.Parse(content); return(response["id"] != null ? response["id"].ToString() : null); #else var response = JsonConvert.DeserializeObject <dynamic>(content); return(response.id); #endif } } } }
public string post(string data_) { // Console.WriteLine("cookie-------=" + Request.Cookies["cookie"]); // Response.Cookies.Append("cookie", "ok",new CookieOptions(){IsEssential=true,HttpOnly=true,SameSite=Microsoft.AspNetCore.Http.SameSiteMode.None,Domain="localhost"}); // Console.WriteLine("cookie-------=" + Request.Cookies["cookie"]); // Console.WriteLine("session-------=" + HttpContext.Session.GetString("cookie")); // HttpContext.Session.SetString("cookie", "ok"); // Console.WriteLine("session-------=" + HttpContext.Session.GetString("cookie")); // Console.WriteLine("请求token=" + Request.HttpContext.Session.GetString("token")); // Console.WriteLine("加密=" + ciphertext); // Console.WriteLine("解密=" + ); if (Request.Headers["token"].ToString().Trim() != null) { string retxt = Program.tool.AES.Decode(Request.Headers["token"].ToString(), "jsd7yfjysd98f7"); JSONObject obj; obj = JSONObject.Parse(retxt); //-----判断有效期 start DateTime objdatetime = (Convert.ToDateTime(obj["date"])); DateTime carrdatetime = DateTime.Now; TimeSpan ts = carrdatetime - objdatetime; if (ts.Days < 30) { //有效 string data = Request.Form["data"]; try { tou = JSONObject.Parse(data); return(TodoApi.Program.请求接口.请求处理(tou.ToString()).ToString()); } catch (Exception) { string a1 = "{'type':'error','message':'string change JSONObject Error'}"; a1 = a1.Replace("\'", "\""); return(a1); } } else { //过期 JSONObject ret = new JSONObject(); ret.Add("tyoe", "error"); ret.Add("msg", "date expire"); return(ret.ToString()); } //-----判断有效期 end } else { JSONObject ret = new JSONObject(); ret.Add("tyoe", "error"); ret.Add("msg", "token is null"); return(ret.ToString()); } // string token = Request.Headers["token"]; // Console.WriteLine("token=" + token); }
/// <summary> /// Reads stream message. /// </summary> private void ReadStreamMessage() { try { String message = ReadMessage(); if (message != null) { JSONObject responseBody = JSONObject.Parse(message); string commandName = responseBody["command"].ToString(); if (commandName == "tickPrices") { StreamingTickRecord tickRecord = new StreamingTickRecord(); tickRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (TickRecordReceived != null) { TickRecordReceived.Invoke(tickRecord); } if (sl != null) { sl.ReceiveTickRecord(tickRecord); } } else if (commandName == "trade") { StreamingTradeRecord tradeRecord = new StreamingTradeRecord(); tradeRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (TradeRecordReceived != null) { TradeRecordReceived.Invoke(tradeRecord); } if (sl != null) { sl.ReceiveTradeRecord(tradeRecord); } } else if (commandName == "balance") { StreamingBalanceRecord balanceRecord = new StreamingBalanceRecord(); balanceRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (BalanceRecordReceived != null) { BalanceRecordReceived.Invoke(balanceRecord); } if (sl != null) { sl.ReceiveBalanceRecord(balanceRecord); } } else if (commandName == "tradeStatus") { StreamingTradeStatusRecord tradeStatusRecord = new StreamingTradeStatusRecord(); tradeStatusRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (TradeStatusRecordReceived != null) { TradeStatusRecordReceived.Invoke(tradeStatusRecord); } if (sl != null) { sl.ReceiveTradeStatusRecord(tradeStatusRecord); } } else if (commandName == "profit") { StreamingProfitRecord profitRecord = new StreamingProfitRecord(); profitRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (ProfitRecordReceived != null) { ProfitRecordReceived.Invoke(profitRecord); } if (sl != null) { sl.ReceiveProfitRecord(profitRecord); } } else if (commandName == "news") { StreamingNewsRecord newsRecord = new StreamingNewsRecord(); newsRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (NewsRecordReceived != null) { NewsRecordReceived.Invoke(newsRecord); } if (sl != null) { sl.ReceiveNewsRecord(newsRecord); } } else if (commandName == "keepAlive") { StreamingKeepAliveRecord keepAliveRecord = new StreamingKeepAliveRecord(); keepAliveRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (KeepAliveRecordReceived != null) { KeepAliveRecordReceived.Invoke(keepAliveRecord); } if (sl != null) { sl.ReceiveKeepAliveRecord(keepAliveRecord); } } else if (commandName == "candle") { StreamingCandleRecord candleRecord = new StreamingCandleRecord(); candleRecord.FieldsFromJSONObject((JSONObject)responseBody["data"]); if (CandleRecordReceived != null) { CandleRecordReceived.Invoke(candleRecord); } if (sl != null) { sl.ReceiveCandleRecord(candleRecord); } } else { throw new APICommunicationException("Unknown streaming record received"); } } } catch (Exception) { } }
/// <summary> /// Handler for streaming message. /// </summary> /// <param name="sender">Sender</param> /// <param name="args">Args</param> private void StreamingMessageHandler(object sender, IncomingMessageArgs args) { var message = args.Message.Parameters.GetString("update"); JSONObject responseBody = (JSONObject)JSONObject.Parse(message); string commandName = responseBody["command"].ToString(); if (RecordReceived != null) { RecordReceived.Invoke(message); } switch (commandName) { case "tickPrices": TickRecord tickRecord = new TickRecord((JSONObject)responseBody["data"]); if (TickPricesRecordReceived != null) { TickPricesRecordReceived.Invoke(tickRecord); } break; case "trade": StreamingTradeRecord tradeRecord = new StreamingTradeRecord((JSONObject)responseBody["data"]); if (TradeRecordReceived != null) { TradeRecordReceived.Invoke(tradeRecord); } break; case "indicators": IndicatorsRecord balanceRecord = new IndicatorsRecord((JSONObject)responseBody["data"]); if (AccountIndicatorsRecordReceived != null) { AccountIndicatorsRecordReceived.Invoke(balanceRecord); } break; case "orderStatus": OrderStatusRecord tradeStatusRecord = new OrderStatusRecord((JSONObject)responseBody["data"]); if (OrderStatusRecordReceived != null) { OrderStatusRecordReceived.Invoke(tradeStatusRecord); } break; case "profit": ProfitRecord profitRecord = new ProfitRecord((JSONObject)responseBody["data"]); if (ProfitRecordReceived != null) { ProfitRecordReceived.Invoke(profitRecord); } break; case "news": NewsRecord newsRecord = new NewsRecord((JSONObject)responseBody["data"]); if (NewsRecordReceived != null) { NewsRecordReceived.Invoke(newsRecord); } break; case "keepAlive": KeepAliveRecord keepAliveRecord = new KeepAliveRecord((JSONObject)responseBody["data"]); if (KeepAliveRecordReceived != null) { KeepAliveRecordReceived.Invoke(keepAliveRecord); } break; case "candle": StreamingCandleRecord candleRecord = new StreamingCandleRecord((JSONObject)responseBody["data"]); if (CandleRecordReceived != null) { CandleRecordReceived.Invoke(candleRecord); } break; case "error": StreamingErrorRecord streamingErrorRecord = new StreamingErrorRecord((JSONObject)responseBody["data"]); if (ErrorRecordReceived != null) { ErrorRecordReceived.Invoke(streamingErrorRecord); } break; default: throw new APICommunicationException("Unknown streaming record received"); } }