public HttpResponseMessage UserLogin(UserInfoModel model) { string Result = string.Empty; try { //请求中包含的固定参数 model.SOURCE = ParametersFilter.FilterSqlHtml(model.SOURCE, 24); model.CREDENTIALS = ParametersFilter.FilterSqlHtml(model.CREDENTIALS, 24); model.ADDRESS = HttpHelper.IPAddress(); model.TERMINAL = ParametersFilter.FilterSqlHtml(model.TERMINAL, 1); model.INDEX = ParametersFilter.FilterSqlHtml(model.INDEX, 24); model.METHOD = ParametersFilter.FilterSqlHtml(model.METHOD, 24); //去除用户参数中包含的特殊字符 model.UserAccount = ParametersFilter.FilterSqlHtml(model.UserAccount, 30); model.UserPasswd = ParametersFilter.FilterSqlHtml(model.UserPasswd, 30); model.UserMobile = ParametersFilter.StripSQLInjection(model.UserMobile); //model.UserEmail = ParametersFilter.StripSQLInjection(model.UserEmail); if (model.TERMINAL == "2") { if (model.UserAccount != null) { model.UserMobile = ""; } else { model.UserAccount = ""; } } //返回结果 Result = ApiHelper.HttpRequest(username, password, Url, model); ///写日志 string RequestAction = "api/" + username + "/" + HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString() + ":"; LogHelper.LogResopnse(RequestAction + Result); //解析返回结果 JObject jsons = (JObject)JsonConvert.DeserializeObject(Result); if (jsons["DATA"][0]["result"].ToString() == "登录成功!") { model.UserMobile = jsons["DATA"][0]["UserMobile"].ToString(); //返回凭证 jsons["CREDENTIALS"] = AuthHelper.AuthUserSet(model); Result = JsonConvert.SerializeObject(jsons); } } catch (Exception ex) { LogHelper.LogError(ex.ToString()); } HttpResponseMessage Respend = new HttpResponseMessage { Content = new StringContent(Result, Encoding.GetEncoding("UTF-8"), "application/json") }; return(Respend); }
public HttpResponseMessage UserInfo(UserInfoModel model) { string Result = string.Empty; try { //请求中包含的固定参数 model.SOURCE = ParametersFilter.FilterSqlHtml(model.SOURCE, 24); model.CREDENTIALS = ParametersFilter.FilterSqlHtml(model.CREDENTIALS, 24); model.ADDRESS = HttpHelper.IPAddress(); model.TERMINAL = ParametersFilter.FilterSqlHtml(model.TERMINAL, 1); model.INDEX = ParametersFilter.FilterSqlHtml(model.INDEX, 24); model.METHOD = ParametersFilter.FilterSqlHtml(model.METHOD, 24); model.DATA = System.Web.HttpUtility.UrlDecode(model.DATA); #region MyRegion //DATA装换为json字符串 string datatojson = ApiHelper.DATAToJson(model.DATA); string UserAccount = JObject.Parse(datatojson)["UserAccount"].ToString(); //图片Model ImgModel imgModel = new ImgModel(); imgModel.ImgIp = ApiHelper.ImgURL(); imgModel.ImgDisk = SingleXmlInfo.GetInstance().GetWebApiConfig("imgDisk"); imgModel.ImgRoot = SingleXmlInfo.GetInstance().GetWebApiConfig("imgRoot"); imgModel.ImgAttribute = "user"; imgModel.UserAccount = UserAccount; imgModel.ImgName = "userAvatar"; imgModel.ImgString = model.UserAvatar; //URL编码 model.DATA = System.Web.HttpUtility.UrlEncode(model.DATA); //保存的图片名称 model.UserAvatar = imgModel.ImgIp + imgModel.UserAccount + "/" + imgModel.ImgAttribute + "/" + imgModel.ImgName + ".jpg"; //返回结果 Result = ApiHelper.HttpRequest(username, password, Url, model); ////解析返回结果 JObject jsons = (JObject)JsonConvert.DeserializeObject(Result); if (jsons["DATA"][0]["Result"].ToString() == "1") { ApiHelper.HttpRequest(ApiHelper.GetImgUploadURL("imgUploadIp", "imgUpload"), imgModel); model.UserMobile = jsons["DATA"][0]["UserMobile"].ToString(); model.UserAccount = jsons["DATA"][0]["UserAccount"].ToString(); //返回凭证 jsons["CREDENTIALS"] = AuthHelper.AuthUserSet(model); Result = JsonConvert.SerializeObject(jsons); } #endregion #region Redis_DATA //UserCheckBLL B = new UserCheckBLL(); //Dictionary<string, string> redisData = B.UserInfo_Redis(model.DATA); //string imgStr = model.UserAvatar; //model.UserAvatar = redisData["UserAvatar"]; //string Str = JsonConvert.SerializeObject(model, JSetting); ////返回结果 //Result = ApiHelper.HttpRequest(username, password, Url, Str); //////解析返回结果 //JObject jsons = (JObject)JsonConvert.DeserializeObject(Result); //if (jsons["DATA"][0]["Result"].ToString() == "1") //{ // // CharConversion.SaveImg(imgStr, model.UserAvatar, "~/Avatar/"); // //实例化Redis请求参数 // RedisModel.BaseModel redis = new RedisModel.BaseModel(); // redis.RedisIP = SingleXmlInfo.GetInstance().GetWebApiConfig("redisAddress"); // redis.RedisPort = SingleXmlInfo.GetInstance().GetWebApiConfig("redisPort"); // redis.RedisPassword = SingleXmlInfo.GetInstance().GetWebApiConfig("redisPassword"); // redis.RedisKey = "PAY_USER_Info_ " + redisData["UserAccount"]; // redis.RedisValue = ApiHelper.DictionaryToStr(redisData); // redis.LifeCycle = "50000"; // redis.RedisFunction = "StringSet"; // //获取Redis中的验证码 // string b = ApiHelper.HttpRequest(ApiHelper.GetRedisURL(redis.RedisFunction), redis); //} #endregion ///写日志 string RequestAction = "api/" + username + "/" + HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString() + ":"; LogHelper.LogResopnse(RequestAction + Result); } catch (Exception ex) { LogHelper.LogError(ex.ToString()); } HttpResponseMessage Respend = new HttpResponseMessage { Content = new StringContent(Result, Encoding.GetEncoding("UTF-8"), "application/json") }; return(Respend); }
public HttpResponseMessage MobileLogin(UserInfoModel model) { string Result = string.Empty; try { //请求中包含的固定参数 model.SOURCE = ParametersFilter.FilterSqlHtml(model.SOURCE, 24); model.CREDENTIALS = ParametersFilter.FilterSqlHtml(model.CREDENTIALS, 24); model.ADDRESS = HttpHelper.IPAddress(); model.TERMINAL = ParametersFilter.FilterSqlHtml(model.TERMINAL, 1); model.INDEX = ParametersFilter.FilterSqlHtml(model.INDEX, 24); model.METHOD = ParametersFilter.FilterSqlHtml(model.METHOD, 24); model.UserMobile = ParametersFilter.FilterSqlHtml(model.UserMobile, 11); model.Verification = ParametersFilter.FilterSqlHtml(model.Verification, 6); //获取Redis中的验证码 string GetRedisAuthCode = ApiHelper.HttpRequest(ApiHelper.GetAuthCodeURL("smsCodeIp", "sms", "VerifyAuthCode"), model); JObject jsons = (JObject)JsonConvert.DeserializeObject(GetRedisAuthCode); //判断验证返回值 if (jsons["result"].ToString() == "2") { Result = "{\"DATA\":[{\"result\":\"验证码已过时\"}]}"; } else if (jsons["result"].ToString() == "1") { Result = ApiHelper.HttpRequest(username, password, Url, model); ///写日志 string RequestAction = "api/" + username + "/" + HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString() + ":"; LogHelper.LogResopnse(RequestAction + Result); JObject jsonData = (JObject)JsonConvert.DeserializeObject(Result); if (jsonData["DATA"][0]["result"].ToString() == "登录成功!") { model.UserAccount = jsonData["DATA"][0]["UserAccount"].ToString(); //返回凭证 jsonData["CREDENTIALS"] = AuthHelper.AuthUserSet(model); Result = JsonConvert.SerializeObject(jsonData); } } else { Result = "{\"DATA\":[{\"result\":\"验证码错误\"}]}"; } } catch (Exception ex) { LogHelper.LogError(ex.ToString()); } HttpResponseMessage Respend = new HttpResponseMessage { Content = new StringContent(Result, Encoding.GetEncoding("UTF-8"), "application/json") }; return(Respend); }