protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.methodTxt.Text)) { this.resultLit.Text = "调用方法未填写,请填写后重试!"; return; } if (string.IsNullOrEmpty(this.argsTxt.Text)) { this.resultLit.Text = "调用参数未填写,请填写后重试!"; return; } string data = "type=" + this.methodTxt.Text + "&Client=android&" + this.argsTxt.Text; data = SiteHelper.Encrypt(data, "qazwsxedcrfvtgbyhnujmikoyhbgtrew").Replace("+", ","); HttpWebRequest webrequest = WebRequest.Create(string.Format("{0}/api/operations/RequestControler.ashx?data={1}", apiUrl, data)) as HttpWebRequest; WebResponse wr = webrequest.GetResponse(); System.IO.Stream stream = wr.GetResponseStream(); System.IO.StreamReader sr = new System.IO.StreamReader(stream); string result = sr.ReadToEnd(); result = SiteHelper.Decrypt(result, "qazwsxedcrfvtgbyhnujmikoyhbgtrew"); this.resultLit.Text = result; }
public void ProcessRequest(HttpContext context) { context.Response.CacheControl = "no-cache"; context.Response.AddHeader("Pragma", "no-cache"); context.Response.ContentType = "text/plain"; string requestData = ""; try { string clientData = context.Request["data"]; if (clientData != null && clientData.Length > 0) { clientData = clientData.Replace(",", "+"); //解密字符串 requestData = SiteHelper.Decrypt(clientData, ClientEncryptionKey); if (requestData.Length > 0) { Hashtable ht = SiteHelper.GetHashTableByQueryString(requestData); if (ht["type"] == null || ht["type"].ToString().Trim().Length <= 0) { throw new Exception("参数不完整"); } if ((ht["UID"] == null || ht["UID"].ToString().Trim().Length <= 0) && ht["type"].ToString().Trim() != "Login") { throw new Exception("参数不完整"); } string typeName = ht["type"].ToString(); Assembly assembly = Assembly.GetExecutingAssembly(); object obj = assembly.CreateInstance("YR.Web.api.operations.privacy." + typeName); IApiAction2 action = (IApiAction2)obj; //调用相对应的接口方法 string result = action.Execute(ht); string encrypt_data = SiteHelper.Encrypt(result, EncryptionKey); context.Response.Write(encrypt_data); Logger.Info("运维API接口调用(成功),访问ip:" + context.Request.UserHostAddress + ",参数:" + requestData + ",返回值:" + result); } else { throw new Exception("参数校验失败"); } } else { throw new Exception("数据为空"); } } catch (Exception e) { string result = SiteHelper.GetJsonFromHashTable(null, "faild", "系统异常," + e.Message); string encrypt_data = SiteHelper.Encrypt(result, EncryptionKey); context.Response.Write(encrypt_data); Logger.Error("运维API接口调用(失败),访问ip:" + context.Request.UserHostAddress + ",参数:" + requestData + ",异常:" + e.Message); } }
public void ProcessRequest(HttpContext context) { context.Response.CacheControl = "no-cache"; context.Response.AddHeader("Pragma", "no-cache"); context.Response.ContentType = "text/plain"; NameValueCollection myHeader = new NameValueCollection(); myHeader = context.Request.Headers; int total = myHeader.Count; string equipmentID = ""; bool hasEquipmentID = false; string strKey; for (int i = 0; i < total; i++) { strKey = myHeader.GetKey(i); if ("EquipmentID".Equals(strKey)) { equipmentID = myHeader.Get(strKey); hasEquipmentID = true; } } //if (!hasEquipmentID) //{ // throw new Exception("参数校验失败"); //} string requestData = ""; try { string clientData = context.Request["data"]; if (clientData != null && clientData.Length > 0) { clientData = clientData.Replace(",", "+"); //解密字符串 requestData = SiteHelper.Decrypt(clientData, ClientEncryptionKey); if (requestData.Length > 0) { Hashtable ht = SiteHelper.GetHashTableByQueryString(requestData); if (ht["type"] == null || ht["type"].ToString().Trim().Length <= 0) { throw new Exception("参数不完整"); } if ((ht["UID"] == null || ht["UID"].ToString().Trim().Length <= 0) && ht["type"].ToString().Trim() != "Login") { throw new Exception("参数不完整"); } string typeName = ht["type"].ToString(); if (typeName == "GetOrderCommentTags") { throw new Exception("无效接口"); } /*if (typeName == "SendVerificationCode") * { * if (!string.IsNullOrEmpty(ip)) * { * ICache Cache = CacheFactory.GetCache(); * string keyid = "sms_send_times@" + ip; * int sms_send_times = 1; * if (string.IsNullOrEmpty(Cache.Get<string>(keyid))) * { * DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); * Cache.Set(keyid, sms_send_times, dt - DateTime.Now); * } * else * { * string tims = Cache.Get<string>(keyid); * int.TryParse(tims, out sms_send_times); * sms_send_times += 1; * DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); * Cache.Set(keyid, sms_send_times, dt - DateTime.Now); * } * Cache.Dispose(); * if (sms_send_times >= MaxSendTimes) * { * Logger.Error("发送短信,访问ip:" + ip + ",参数:" + requestData); * throw new Exception("短信发送已超过当天最大次数"); * } * } * }*/ Assembly assembly = Assembly.GetExecutingAssembly(); object obj = assembly.CreateInstance("YR.Web.api.app.privacy." + typeName); IApiAction2 action = (IApiAction2)obj; //调用相对应的接口方法 string result = action.Execute(ht); if (ht["UID"] != null && ht["UID"].ToString().Trim().Length > 0) { string uid = ht["UID"].ToString(); context.Response.AddHeader("EquipmentID", new UserInfoManager().GetDeviceIDByUserID(uid)); } string encrypt_data = SiteHelper.Encrypt(result, EncryptionKey); context.Response.Write(encrypt_data); if (!"GetNearVehicles".Equals(typeName) && !"GetNearParking".Equals(typeName)) { Logger.Info("API接口调用(成功),访问ip:" + context.Request.UserHostAddress + equipmentID + ",参数:" + requestData + ",返回值:" + result); } else { Logger.Info("API接口调用(成功),访问ip:" + context.Request.UserHostAddress + equipmentID + ",参数:" + requestData); } } else { throw new Exception("参数校验失败"); } } else { throw new Exception("数据为空"); } } catch (Exception e) { string result = SiteHelper.GetJsonFromHashTable(null, "faild", "系统异常," + e.Message); string encrypt_data = SiteHelper.Encrypt(result, EncryptionKey); context.Response.Write(encrypt_data); Logger.Error("API接口调用(失败),访问ip:" + context.Request.UserHostAddress + equipmentID + ",参数:" + requestData + ",异常:" + e); } }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["PageNum"])) { pageNum = int.Parse(ConfigurationManager.AppSettings["PageNum"].ToString()); } RequestControler rc = (RequestControler)HttpContext.Current.Handler; Hashtable res = rc.HashtableResult; if (res["ParkingID"] == null || res["PageNum"] == null || res["CurrentPage"] == null || res["ParkingID"].ToString().Trim().Length <= 0 || res["PageNum"].ToString().Trim().Length <= 0 || res["CurrentPage"].ToString().Trim().Length <= 0) { Response.Write(SiteHelper.Encrypt(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"), rc.EncryptionKey)); Response.End(); } else { try { //pageNum = int.Parse(res["PageNum"].ToString().Trim()); currentPage = int.Parse(res["CurrentPage"].ToString().Trim()); parkingID = res["ParkingID"].ToString().Trim(); } catch { Response.Write(SiteHelper.Encrypt(SiteHelper.GetJsonFromHashTable(null, "faild", "数据格式不正确"), rc.EncryptionKey)); Response.End(); } VehicleParkingManager pm = new VehicleParkingManager(); DataTable vehicles = pm.GetVehiclesByParkingId(parkingID, currentPage, pageNum); if (vehicles == null || vehicles.Rows.Count <= 0) { Response.Write(SiteHelper.Encrypt(SiteHelper.GetJsonFromHashTable(null, "faild", "亲,没有数据了"), rc.EncryptionKey)); Response.End(); } else { foreach (DataRow dr in vehicles.Rows) { dr["ThumbImageUrl"] = SiteHelper.GetImageDomainServer() + dr["ThumbImageUrl"].ToString(); decimal electricity = 0; decimal.TryParse(dr["Electricity"].ToString(), out electricity); int dianliang = Decimal.ToInt32(electricity); dr["Electricity"] = dianliang + "%"; string lng = dr["Longitude"].ToString(); string lat = dr["Latitude"].ToString(); if (!string.IsNullOrEmpty(lng) && !string.IsNullOrEmpty(lat)) { string latlng = GetBaiduCord(double.Parse(lat), double.Parse(lng), "1", "5"); if (!string.IsNullOrEmpty(latlng)) { dr["Longitude"] = latlng.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[1]; dr["Latitude"] = latlng.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0]; if (res["Client"] != null && "iOS" == res["Client"].ToString()) { LatLng ll = new LatLng(double.Parse(lng), double.Parse(lat)); ll = SiteHelper.TransformFromWGSToGCJ(ll); dr["Longitude"] = ll.latitude; dr["Latitude"] = ll.longitude; } else { if (dr["Address"].ToString().Trim().Length <= 0) { dr["Address"] = SiteHelper.GetLocationByGPS(dr["Latitude"].ToString(), dr["Longitude"].ToString()); } } } } } Response.Write(SiteHelper.Encrypt(JsonHelper.DataTableToJson("success", "获取数据成功", vehicles, "VehicleInfo"), rc.EncryptionKey)); Response.End(); } } }