diff --git a/.gitignore b/.gitignore index d1a0fd9..5c86336 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ NotUse obj .psd packages -.user \ No newline at end of file +.user +bin diff --git a/KJDService/Dll/MySql.Data.dll b/KJDService/Dll/MySql.Data.dll new file mode 100644 index 0000000..54f5e60 Binary files /dev/null and b/KJDService/Dll/MySql.Data.dll differ diff --git a/KJDService/Dll/Newtonsoft.Json.dll b/KJDService/Dll/Newtonsoft.Json.dll new file mode 100644 index 0000000..20dae62 Binary files /dev/null and b/KJDService/Dll/Newtonsoft.Json.dll differ diff --git a/KJDService/KJD_WebService.sln b/KJDService/KJD_WebService.sln new file mode 100644 index 0000000..56d335f --- /dev/null +++ b/KJDService/KJD_WebService.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36221.1 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KJD_WebService", "KJD_WebService\KJD_WebService.csproj", "{A6C03FE1-142A-4C97-99A9-67FD915836B6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {373F414C-6CDF-49C0-B074-A7D07D7B82B7} + EndGlobalSection +EndGlobal diff --git a/KJDService/KJD_WebService/BLL/ShopManage.cs b/KJDService/KJD_WebService/BLL/ShopManage.cs new file mode 100644 index 0000000..5a4bfa8 --- /dev/null +++ b/KJDService/KJD_WebService/BLL/ShopManage.cs @@ -0,0 +1,404 @@ +using KJD_Web.Model; +using KJD_Web.Model.ShopModel; +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; +using System.Web.Security; + +namespace KJD_Web.BLL +{ + public class ShopManage + { + public string GetShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); + var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); + var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); + var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); + var s_page = RegexUtils.GetStringQuery(ref inputData, "page"); + int page = 0; + int.TryParse(s_page, out page); + var s_page_size = RegexUtils.GetStringQuery(ref inputData, "page_size"); + int page_size; + int.TryParse(s_page_size, out page_size); + if (page_size == 0) + page_size = 50; + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.shop where 1=1"; + if (isAdmin) + sql += " and (cookie='' or shop_id!='')"; + if (!isAdmin) + sql += " and (user_name='" + user_name + "' or sub_user_name='" + user_name + "')"; + if (!string.IsNullOrWhiteSpace(search_user_name)) + sql += " and user_name like '%" + search_user_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_login_name)) + sql += " and login_name like '%" + search_login_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + sql += " and notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_id)) + sql += " and shop_id like '%" + search_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_name)) + sql += " and shop_account like '%" + search_name + "%'"; + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select id,login_name,login_pass,cookie,shop_id,shop_account,sub_user_name,user_name,company_name,notes,login_status" + + " from kjd.shop where 1=1"; + if (isAdmin) + sql += " and (cookie='' or shop_id!='')"; + if (!isAdmin) + sql += " and (user_name='" + user_name + "' or sub_user_name='" + user_name + "')"; + if (!string.IsNullOrWhiteSpace(search_user_name)) + sql += " and user_name like '%" + search_user_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_login_name)) + sql += " and login_name like '%" + search_login_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + sql += " and notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_id)) + sql += " and shop_id like '%" + search_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_name)) + sql += " and shop_account like '%" + search_name + "%'"; + sql += " order by id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + List shopList=new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializerObjectToString(shopList); + //return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + //获取一个手机登录号码下的所有店铺(以便有则更新,无则新增) + public string GetOneLoginNameShop(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,shop_id,shop_account,sub_user_name,user_name from kjd.shop where user_name='" + + user_name + "' and login_name='" + login_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializerObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + //获取一个手机登录号码下特定ID的店铺 + public string GetOneIdShop(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,shop_id,shop_account,sub_user_name,user_name from kjd.shop where user_name='" + + user_name + "' and login_name='" + login_name + "' and shop_id='" + shop_id + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializerObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string AddShop(string inputData, bool isAdmin=false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); + string sub_user_name = RegexUtils.GetStringQuery(ref inputData, "sub_user_name"); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); + string group_name = RegexUtils.GetStringQuery(ref inputData, "group_name"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from kjd.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from kjd.shop where login_name='" + login_name + "' and user_name='" + user_name + + "' and shop_id='" + shop_id + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist>0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"店铺" + login_name +" " + shop_account + "已存在\"}"; + } + + sql = "insert into kjd.shop (login_name,login_pass,cookie,shop_account,shop_id,sub_user_name,user_name,group_name,notes,add_time,mdy_time) " + + "values ('" + login_name + "','" + login_pass + "','" + cookie + "','" + shop_account + "','" + shop_id + "','" + + sub_user_name + "','" + user_name + "','" + group_name + "','" + notes + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string MdyShop(string inputData, bool isAdmin=false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); + string sub_user_name = RegexUtils.GetStringQuery(ref inputData, "sub_user_name"); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string new_shop_id = RegexUtils.GetStringQuery(ref inputData, "new_shop_id"); + string old_shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); + string group_name = RegexUtils.GetStringQuery(ref inputData, "group_name"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.shop set"; + if (login_pass != null) + sql += " login_pass='" + login_pass + "',"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (new_shop_id != null) + sql += " shop_id='" + new_shop_id + "',"; + if (shop_account != null) + sql += " shop_account='" + shop_account + "',"; + if (sub_user_name != null) + sql += " sub_user_name='" + sub_user_name + "',"; + if (group_name != null) + sql += " group_name='" + group_name + "',"; + if (notes != null) + sql += " notes='" + notes + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "' and (user_name='" + user_name + "' or sub_user_name='" + user_name + "')"; + if (!string.IsNullOrEmpty(old_shop_id)) + sql += " and shop_id='" + old_shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string MdyCookieAndLoginStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.shop set"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + + public string DelShop(string inputData, bool isAdmin=false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.shop where user_name='" + user_name + "' and login_name='" + login_name + "'"; + if (!string.IsNullOrEmpty(shop_id)) + sql += " and shop_id='" + shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/BLL/UpadteManage.cs b/KJDService/KJD_WebService/BLL/UpadteManage.cs new file mode 100644 index 0000000..6007b39 --- /dev/null +++ b/KJDService/KJD_WebService/BLL/UpadteManage.cs @@ -0,0 +1,44 @@ +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.BLL +{ + public class UpadteManage + { + public string GetUpdate(string inputData) + { + //string time1 = Encryption(time); + //return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount + + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":20000,\"msg\":\"校验失败\"}"; + + var version = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "version"), out version); + var serverVersion = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateVersion"].ConnectionString; + var UpdateFiles = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateFiles"].ConnectionString; + var UpdateExe = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExe"].ConnectionString; + var UpdateExeChk = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExeChk"].ConnectionString; + + if (version > 0) + { + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFiles + "\"}"; + } + else + { + return "{\"code\":501,\"msg\":\"failed\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/BLL/UserManage.cs b/KJDService/KJD_WebService/BLL/UserManage.cs new file mode 100644 index 0000000..3e167d6 --- /dev/null +++ b/KJDService/KJD_WebService/BLL/UserManage.cs @@ -0,0 +1,410 @@ +using KJD_Web.Model; +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Web; +using System.Web.UI.WebControls; + +namespace KJD_Web.BLL +{ + public class UserManage + { + public string CheckUserLogin(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from kjd.user where user_name='" + + mobile + "' and password='" + password + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["user_name"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + company_name = row["company_name"].ToString(), + }; + if (string.IsNullOrEmpty(user.company_name)) + { + user.company_name = "-"; + } + var data = JsonUtils.SerializerObjectToString(user); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + return "{\"code\":1,\"msg\":\"用户名或密码错误\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string AddSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name")); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name")); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile")); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "company")); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from kjd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into kjd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,parent_user_name,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\""+ mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"子账户创建成功!\"}"; + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string GetSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var group = RegexUtils.GetStringQuery(ref inputData, "group"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from kjd.user where parent_user_name='" + + user_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializerObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string UpdateSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name")); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name")); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile")); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from kjd.user where parent_user_name='" + // + user_name + "'"; + sql = "update kjd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + + public string DelUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.user where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":200,\"msg\":\"删除失败,请稍后重试\"}"; + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string GetAllUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id"); + var search = RegexUtils.GetStringQuery(ref inputData, "search"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "select * from kjd.user where group_id=3"; + string sql = "select * from kjd.user where 1=1"; + if (!string.IsNullOrEmpty(group_id)) + sql+=" and group_id=" + group_id + " "; + if (!string.IsNullOrEmpty(search)) + sql += " and (user_name like '%" + search + + "%' or nick_name like '%" + search + + "%' or company_name like '%" + search + "%')"; + sql += " order by id desc"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializerObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string AddUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name")); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name")); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile")); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company")); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from kjd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into kjd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string UpdateUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name")); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name")); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile")); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company")); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from kjd.user where parent_user_name='" + // + user_name + "'"; + sql = "update kjd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(company_name)) + sql += " company_name='" + company_name + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + + + public string ChangePassword(string inputData) + { + var userName = RegexUtils.GetStringJson(ref inputData, "user_name"); + var password = RegexUtils.GetStringJson(ref inputData, "password"); + var newPassword = RegexUtils.GetStringJson(ref inputData, "new_password"); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select user_id,password from pepdtp.user where user_id='" + + userName + "' and password='" + password + "'"; + + var dw = mySql.ExecuteDataTableRow(sql); + if (dw != null) + { + UserLoginResultParam user = new UserLoginResultParam + { + user_name = dw["user_id"].ToString(), + password = dw["password"].ToString(), + }; + sql = "update pepdtp.user set password = '" + newPassword + "' where user_id='" + userName + "'"; + var result = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (result) + { + return "{\"code\":0,\"msg\":\"密码修改成功!\"}"; + } + else + return "{\"code\":19999,\"msg\":\"密码修改失败!请稍后再试。\"}"; + } + else + { + mySql.Close(); + return "{\"code\":1,\"msg\":\"原密码错误。\"}"; + } + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Global.asax b/KJDService/KJD_WebService/Global.asax new file mode 100644 index 0000000..ae7cf35 --- /dev/null +++ b/KJDService/KJD_WebService/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.cs" Inherits="KJD_Web.Global" Language="C#" %> diff --git a/KJDService/KJD_WebService/Global.asax.cs b/KJDService/KJD_WebService/Global.asax.cs new file mode 100644 index 0000000..3037e85 --- /dev/null +++ b/KJDService/KJD_WebService/Global.asax.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Security; +using System.Web.SessionState; + +namespace KJD_Web +{ + public class Global : System.Web.HttpApplication + { + + protected void Application_Start(object sender, EventArgs e) + { + + } + + protected void Session_Start(object sender, EventArgs e) + { + + } + + protected void Application_BeginRequest(object sender, EventArgs e) + { + string hPath = Request.Url.LocalPath.ToString(); + if (!hPath.Contains(".asmx") && hPath.Contains("/user/")) + { + hPath = hPath.Replace("/user/", "/UserService.asmx/"); + Context.RewritePath(hPath); + } + else if (!hPath.Contains(".asmx") && hPath.Contains("/shop/")) + { + hPath = hPath.Replace("/shop/", "/ShopService.asmx/"); + Context.RewritePath(hPath); + } + else if (!hPath.Contains(".asmx") && hPath.Contains("/update/")) + { + hPath = hPath.Replace("/update/", "/UpdateService.asmx/"); + Context.RewritePath(hPath); + } + } + + protected void Application_AuthenticateRequest(object sender, EventArgs e) + { + + } + + protected void Application_Error(object sender, EventArgs e) + { + + } + + protected void Session_End(object sender, EventArgs e) + { + + } + + protected void Application_End(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/KJD_WebService.csproj b/KJDService/KJD_WebService/KJD_WebService.csproj new file mode 100644 index 0000000..957c18c --- /dev/null +++ b/KJDService/KJD_WebService/KJD_WebService.csproj @@ -0,0 +1,163 @@ + + + + + Debug + AnyCPU + + + 2.0 + {A6C03FE1-142A-4C97-99A9-67FD915836B6} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + KJD_Web + KJD_WebService + v4.5.2 + true + + 44313 + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + false + + + true + pdbonly + true + bin\ + TRACE + prompt + 4 + false + + + + + ..\Dll\MySql.Data.dll + + + False + ..\Dll\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + + + + + + + + + + + + + Global.asax + + + + + + + + ShopService.asmx + Component + + + UpdateService.asmx + Component + + + UserService.asmx + Component + + + + + + + + + + + + Web.config + + + Web.config + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 49977 + / + http://localhost:9000/ + False + False + + + False + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/KJDService/KJD_WebService/KJD_WebService.csproj.user b/KJDService/KJD_WebService/KJD_WebService.csproj.user new file mode 100644 index 0000000..a48a5b1 --- /dev/null +++ b/KJDService/KJD_WebService/KJD_WebService.csproj.user @@ -0,0 +1,38 @@ + + + + true + + 44313 + + + + + Debug|Any CPU + ShowAllFiles + + + + + + UserService.asmx + CurrentPage + True + False + False + False + + + + + + + + + True + False + + + + + \ No newline at end of file diff --git a/KJDService/KJD_WebService/Model/CommentParam.cs b/KJDService/KJD_WebService/Model/CommentParam.cs new file mode 100644 index 0000000..49dfa42 --- /dev/null +++ b/KJDService/KJD_WebService/Model/CommentParam.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Model +{ + public class CommentParam + { + public int id { get; set; } + public string user_id { get; set; } + public string comment { get; set; } + public DateTime add_time { get; set; } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Model/OrderParam.cs b/KJDService/KJD_WebService/Model/OrderParam.cs new file mode 100644 index 0000000..9c6954f --- /dev/null +++ b/KJDService/KJD_WebService/Model/OrderParam.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Model +{ + public class OrderParam + { + public int id { get; set; } + public string order_id { get; set; } + public string order_info { get; set; } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Model/ShopModel/ShopParam.cs b/KJDService/KJD_WebService/Model/ShopModel/ShopParam.cs new file mode 100644 index 0000000..1237a6e --- /dev/null +++ b/KJDService/KJD_WebService/Model/ShopModel/ShopParam.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Model.ShopModel +{ + public class ShopParam + { + public int id { get; set; } + public string login_name { get; set; } + public string login_pass { get; set; } + public string cookie { get; set; } + public string shop_id { get; set; } + public string shop_account { get; set; } + public string sub_user_name { get; set; } + public string user_name { get; set; } + public string company_name { get; set; } + /// + /// 备注 + /// + public string notes { get; set; } + public string login_status { get; set; } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Model/UserLoginResultParam.cs b/KJDService/KJD_WebService/Model/UserLoginResultParam.cs new file mode 100644 index 0000000..02d6528 --- /dev/null +++ b/KJDService/KJD_WebService/Model/UserLoginResultParam.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Model +{ + public class UserLoginResultParam + { + public int id { get; set; } + + /// + /// 用户名 + /// + public string user_name { get; set; } + /// + /// 父用户名 + /// + public string parent_user_name { get; set; } + /// + /// 手机号(真实登录id,与用户名相同) + /// + public string mobile { get; set; } + + public string password { get; set; } + + public string nick_name { get; set; } + + public string group_id { get; set; } + + public bool is_import { get; set; } + + public string company_name { get; set; } + + public string card_id { get; set; } + + public DateTime add_time { get; set; } + + public DateTime mdy_time { get; set; } + /// + /// 备注 + /// + public string notes { get; set; } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Properties/AssemblyInfo.cs b/KJDService/KJD_WebService/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..700aa17 --- /dev/null +++ b/KJDService/KJD_WebService/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过下列特性集 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("KJD_WebService")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("KJD_WebService")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +// 对 COM 组件不可见。如果需要 +// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID +[assembly: Guid("a6c03fe1-142a-4c97-99a9-67fd915836b6")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订版本 +// +// 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, +// 方法是按如下所示使用 "*": +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/KJDService/KJD_WebService/ShopService.asmx b/KJDService/KJD_WebService/ShopService.asmx new file mode 100644 index 0000000..9f19e16 --- /dev/null +++ b/KJDService/KJD_WebService/ShopService.asmx @@ -0,0 +1 @@ +<%@ WebService Language="C#" CodeBehind="ShopService.asmx.cs" Class="KJD_Web.ShopService" %> diff --git a/KJDService/KJD_WebService/ShopService.asmx.cs b/KJDService/KJD_WebService/ShopService.asmx.cs new file mode 100644 index 0000000..926766b --- /dev/null +++ b/KJDService/KJD_WebService/ShopService.asmx.cs @@ -0,0 +1,172 @@ +using KJD_Web.BLL; +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.Services; + +namespace KJD_Web +{ + /// + /// ShopService 的摘要说明 + /// + [WebService(Namespace = "http://tempuri.org/")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [System.ComponentModel.ToolboxItem(false)] + // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 + // [System.Web.Script.Services.ScriptService] + public class ShopService : System.Web.Services.WebService + { + private string GetRequestJsonString() + { + Context.Response.ContentType = "text/html;charset=utf-8"; + Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); + + using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流 + { + // 还原数据流 + byte[] b = new byte[s.Length]; + s.Read(b, 0, (int)s.Length); + string jsonText = Encoding.UTF8.GetString(b); // JSON字符串 + if (string.IsNullOrEmpty(jsonText)) + { + var qs = HttpContext.Current.Request.QueryString; + if (qs != null && qs.Keys.Count > 0) + { + jsonText = "{"; + foreach (var key in qs.Keys) + { + jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";"; + } + jsonText = jsonText.TrimEnd(';') + "}"; + } + } + return jsonText; + } + } + + [WebMethod] + public void get_shop_list() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().GetShop(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void get_one_login_name_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().GetOneLoginNameShop(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void add_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().AddShop(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void del_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().DelShop(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void mdy_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().MdyShop(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void mdy_shop_cookie_and_login_status() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().MdyCookieAndLoginStatus(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void admin_get_shop_list() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().GetShop(jsontext, true); + + Context.Response.Write(result); + Context.Response.End(); + } + + + [WebMethod] + public void admin_mdy_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().MdyShop(jsontext, true); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void admin_add_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().AddShop(jsontext, true); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void admin_del_shop() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new ShopManage().DelShop(jsontext, true); + + Context.Response.Write(result); + Context.Response.End(); + } + } +} diff --git a/KJDService/KJD_WebService/UpdateService.asmx b/KJDService/KJD_WebService/UpdateService.asmx new file mode 100644 index 0000000..dd87d0d --- /dev/null +++ b/KJDService/KJD_WebService/UpdateService.asmx @@ -0,0 +1 @@ +<%@ WebService Language="C#" CodeBehind="UpdateService.asmx.cs" Class="KJD_Web.UpdateService" %> diff --git a/KJDService/KJD_WebService/UpdateService.asmx.cs b/KJDService/KJD_WebService/UpdateService.asmx.cs new file mode 100644 index 0000000..8cace63 --- /dev/null +++ b/KJDService/KJD_WebService/UpdateService.asmx.cs @@ -0,0 +1,70 @@ +using KJD_Web.BLL; +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.Services; + +namespace KJD_Web +{ + /// + /// UpdateService 的摘要说明 + /// + [WebService(Namespace = "http://tempuri.org/")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [System.ComponentModel.ToolboxItem(false)] + // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 + // [System.Web.Script.Services.ScriptService] + public class UpdateService : System.Web.Services.WebService + { + [WebMethod] + public string hello_world() + { + return "Hello World"; + } + + private string GetRequestJsonString() + { + Context.Response.ContentType = "text/html;charset=utf-8"; + Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); + + using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流 + { + // 还原数据流 + byte[] b = new byte[s.Length]; + s.Read(b, 0, (int)s.Length); + string jsonText = Encoding.UTF8.GetString(b); // JSON字符串 + if (string.IsNullOrEmpty(jsonText)) + { + var qs = HttpContext.Current.Request.QueryString; + if (qs != null && qs.Keys.Count > 0) + { + jsonText = "{"; + foreach (var key in qs.Keys) + { + jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";"; + } + jsonText = jsonText.TrimEnd(';') + "}"; + } + } + return jsonText; + } + } + + + [WebMethod] + public void get_update() + { + var jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UpadteManage().GetUpdate(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + } +} diff --git a/KJDService/KJD_WebService/UserService.asmx b/KJDService/KJD_WebService/UserService.asmx new file mode 100644 index 0000000..d109427 --- /dev/null +++ b/KJDService/KJD_WebService/UserService.asmx @@ -0,0 +1 @@ +<%@ WebService Language="C#" CodeBehind="UserService.asmx.cs" Class="KJD_Web.UserService" %> diff --git a/KJDService/KJD_WebService/UserService.asmx.cs b/KJDService/KJD_WebService/UserService.asmx.cs new file mode 100644 index 0000000..64e6b81 --- /dev/null +++ b/KJDService/KJD_WebService/UserService.asmx.cs @@ -0,0 +1,359 @@ +using KJD_Web.BLL; +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.Services; + +namespace KJD_Web +{ + /// + /// UserService 的摘要说明 + /// + [WebService(Namespace = "http://tempuri.org/")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [System.ComponentModel.ToolboxItem(false)] + // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 + // [System.Web.Script.Services.ScriptService] + public class UserService : System.Web.Services.WebService + { + [WebMethod] + public string hello_world() + { + return "Hello World"; + } + + private string GetRequestJsonString() + { + Context.Response.ContentType = "text/html;charset=utf-8"; + Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); + + using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流 + { + // 还原数据流 + byte[] b = new byte[s.Length]; + s.Read(b, 0, (int)s.Length); + string jsonText = Encoding.UTF8.GetString(b); // JSON字符串 + if (string.IsNullOrEmpty(jsonText)) + { + var qs = HttpContext.Current.Request.QueryString; + if (qs != null && qs.Keys.Count > 0) + { + jsonText = "{"; + foreach (var key in qs.Keys) + { + jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";"; + } + jsonText = jsonText.TrimEnd(';') + "}"; + } + } + return jsonText; + } + } + + [WebMethod] + public void user_login() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().CheckUserLogin(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void change_password() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().ChangePassword(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void get_sub_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().GetSubUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void update_sub_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().UpdateSubUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void add_sub_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().AddSubUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void delete_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().DelUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void get_all_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().GetAllUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void update_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().UpdateUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void add_user() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UserManage().AddUser(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + + + #region 暂时作废 + /* + [WebMethod] + public void GetServer() + { + var softName = GetRequestJsonString(); + + var result = ""; + //result = System.Configuration.ConfigurationManager.ConnectionStrings[softName + "ServerUrl"].ConnectionString; + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void GetUpdateInfo() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new UpadteManage().CheckUpdate(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + + } + + [WebMethod] + public byte[] DownloadFile() + { + string file = Server.MapPath("").Substring(0, Server.MapPath("").LastIndexOf("\\")) + "\\bin\\test.txt"; + + System.IO.FileStream fs = null; + if (System.IO.File.Exists(file)) + { + try + { + fs = System.IO.File.OpenRead(file); + int b1; + System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); + while ((b1 = fs.ReadByte()) != -1) + { + tempStream.WriteByte(((byte)b1)); + } + return tempStream.ToArray(); + } + catch (Exception ex) + { + return new byte[0]; + } + finally + { + fs.Close(); + } + } + else + { + return new byte[0]; + } + } + + ///客户端: + + /// + /// 从服务器上下载文件,未用 + /// + /// 源文件:如“E:\\city.txt” + /// 目标文件:如@"d:\city.txt" + //public static void DownFile(string str1, string str2) + //{ + // CRMweb.WebService1SoapClient myWeb = new CRMweb.WebService1SoapClient(); + // byte[] bs = myWeb.DownloadFile(str1); + // System.IO.FileStream stream = new System.IO.FileStream(str2, System.IO.FileMode.CreateNew); + // stream.Write(bs, 0, bs.Length); + // stream.Flush(); + // stream.Close(); + //} + + [WebMethod] + public void AddComment() + { + string result=""; + + //// 输入为querystring + //var jsonText = GetRequestJsonString(); + //try + //{ + // var user_id = RegexUtils.GetStringJson(ref jsonText, "user_id"); + // var comment = RegexUtils.GetStringJson(ref jsonText, "comment"); + // if (string.IsNullOrEmpty(user_id)) + // result = "{\"code\":1,\"msg\":\"未指定用户Id\"}"; + // else if (string.IsNullOrEmpty(comment)) + // result = "{\"code\":2,\"msg\":\"未指定留言内容\"}"; + // else + // { + // string sql = "insert into pepdtp.comment "; + // string sql1 = "("; + // string sql2 = "("; + // if (user_id != null) { sql1 += "user_id,"; sql2 += "'" + user_id + "',"; } + // if (comment != null) { sql1 += "comment,"; sql2 += "'" + comment + "',"; } + // var tTime = "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + // sql1 += "add_time,"; + // sql2 += tTime; + // sql1 = sql1.TrimEnd(',') + ")"; + // sql2 = sql2.TrimEnd(',') + ")"; + // sql = sql + sql1 + " values " + sql2; + + // string conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; + // MysqlUtils mySql = new MysqlUtils(conn); + // bool isSuccess = mySql.ExecuteNonQuery(sql); + // if (!isSuccess) + // { + // result = "{\"code\":10001,\"msg\":\"添加留言入库出错,请稍后重试!\"}"; + // } + // else + // { + // result = "{\"code\":0,\"msg\":\"添加留言成功!\"}"; + // } + // mySql.Close(); + // } + //} + //catch (Exception ex) + //{ + // result = "{\"code\":10001,\"msg\":\"添加留言出错,请稍后重试!\"}"; + //}; + + Context.Response.Write(result); + Context.Response.End(); + } + + [WebMethod] + public void EditUser() + { + string result=""; + + // 输入为querystring + //var jsonText = GetRequestJsonString(); + //try + //{ + // //var role = RegexUtils.GetStringJson(ref jsonText, "role"); + // var name = RegexUtils.GetStringJson(ref jsonText, "name"); + // //var school = RegexUtils.GetStringJson(ref jsonText, "school"); + // var rkxd = RegexUtils.GetStringJson(ref jsonText, "rkxd"); + // var zxxkc = RegexUtils.GetStringJson(ref jsonText, "zxxkc"); + // //var is_import = RegexUtils.GetStringJson(ref jsonText, "is_import"); + // //var password = RegexUtils.GetStringJson(ref jsonText, "password"); + // //var order_id = RegexUtils.GetStringJson(ref jsonText, "order_id"); + // var user_id = RegexUtils.GetStringJson(ref jsonText, "user_id"); + // if (string.IsNullOrEmpty(user_id)) + // result = "{\"code\":1,\"msg\":\"未指定用户Id\"}"; + // else + // { + // string sql = "update pepdtp.user set "; + // //if (role != null) sql += "role=" + role + ","; + // if (name != null) sql += "name='" + name + "',"; + // //if (school != null) sql += "school='" + school + "',"; + // if (rkxd != null) sql += "rkxd='" + rkxd + "',"; + // if (zxxkc != null) sql += "zxxkc='" + zxxkc + "',"; + // //if (is_import != null) sql += "is_import='" + is_import + "',"; + // //if (password != null) sql += "password='" + password + "',"; + // //if (order_id != null) sql += "order_id='" + order_id + "',"; + // sql += "mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + // sql = sql.TrimEnd(' ').TrimEnd(','); + // if (user_id.Contains(",")) + // sql += " where user_id in ('" + user_id.Replace(",", "','") + "')"; + // else + // sql += " where user_id='" + user_id + "'"; + + // string conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; + // MysqlUtils mySql = new MysqlUtils(conn); + // bool isSuccess = mySql.ExecuteNonQuery(sql); + // if (!isSuccess) + // { + // result = "{\"code\":10001,\"msg\":\"修改用户入库出错,请稍后重试!\"}"; + // } + // else + // { + // result = "{\"code\":0,\"msg\":\"修改用户成功!\"}"; + // } + // mySql.Close(); + // } + //} + //catch (Exception ex) + //{ + // result = "{\"code\":19999,\"msg\":\"修改用户出错,请稍后重试!\"}"; + //}; + + Context.Response.Write(result); + Context.Response.End(); + } + */ + #endregion + } +} diff --git a/KJDService/KJD_WebService/Utils/EncrypUtil.cs b/KJDService/KJD_WebService/Utils/EncrypUtil.cs new file mode 100644 index 0000000..b3a6021 --- /dev/null +++ b/KJDService/KJD_WebService/Utils/EncrypUtil.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Web; + +namespace KJD_Web.Utils +{ + public class EncrypUtil + { + /// + /// 加密算法 + /// + /// 加密字符串 + /// + public static string Encryption(int s) + { + string sign = $"{s}sdhewu*/fhAAue48485ew5+5%@3485esGFFHFD"; + return GetMd5(sign); + } + + /// + /// MD5加密 + /// + /// + /// + public static string GetMd5(string instring) + { + byte[] result = Encoding.Default.GetBytes(instring.Trim()); + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] output = md5.ComputeHash(result); + return BitConverter.ToString(output).Replace("-", ""); + } + + /// + /// 获取文件MD5值 + /// + /// + /// + public static string GetFileMd5(string FilePath) + { + try + { + FileStream get_file = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); + System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); + byte[] hash_byte = get_md5.ComputeHash(get_file); + string resule = System.BitConverter.ToString(hash_byte); + resule = resule.Replace("-", ""); + get_file.Close(); + return resule; + } + catch (Exception e) + { + return e.ToString(); + } + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Utils/HtmlUtils.cs b/KJDService/KJD_WebService/Utils/HtmlUtils.cs new file mode 100644 index 0000000..d269446 --- /dev/null +++ b/KJDService/KJD_WebService/Utils/HtmlUtils.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Runtime.InteropServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Web; + +namespace KJD_Web.Utils +{ + public class HtmlUtils + { + static public string UrlDecodeUtf8(string value) + { + if (value == null) + { + return null; + } + Encoding encoding = Encoding.UTF8;//你的编码 也可能是GBK + int length = value.Length; + UrlDecoder decoder = new UrlDecoder(length, encoding); + for (int i = 0; i < length; i++) + { + char ch = value[i]; + if (ch == '+') + { + ch = ' '; + } + else if ((ch == '%') && (i < (length - 2))) + { + if ((value[i + 1] == 'u') && (i < (length - 5))) + { + int num3 = HexToInt(value[i + 2]); + int num4 = HexToInt(value[i + 3]); + int num5 = HexToInt(value[i + 4]); + int num6 = HexToInt(value[i + 5]); + if (((num3 < 0) || (num4 < 0)) || ((num5 < 0) || (num6 < 0))) + { + goto Label_010B; + } + ch = (char)((((num3 << 12) | (num4 << 8)) | (num5 << 4)) | num6); + i += 5; + decoder.AddChar(ch); + continue; + } + int num7 = HexToInt(value[i + 1]); + int num8 = HexToInt(value[i + 2]); + if ((num7 >= 0) && (num8 >= 0)) + { + byte b = (byte)((num7 << 4) | num8); + i += 2; + decoder.AddByte(b); + continue; + } + } + Label_010B: + if ((ch & 0xff80) == 0) + { + decoder.AddByte((byte)ch); + } + else + { + decoder.AddChar(ch); + } + } + return decoder.GetString(); + } + + public static int HexToInt(char h) + { + if ((h >= '0') && (h <= '9')) + { + return (h - '0'); + } + if ((h >= 'a') && (h <= 'f')) + { + return ((h - 'a') + 10); + } + if ((h >= 'A') && (h <= 'F')) + { + return ((h - 'A') + 10); + } + return -1; + } + } + /// + /// class UrlDecoder + /// + class UrlDecoder + { + // Fields + private int _bufferSize; + private byte[] _byteBuffer; + private char[] _charBuffer; + private Encoding _encoding; + private int _numBytes; + private int _numChars; + + // Methods + internal UrlDecoder(int bufferSize, Encoding encoding) + { + this._bufferSize = bufferSize; + this._encoding = encoding; + this._charBuffer = new char[bufferSize]; + } + + internal void AddByte(byte b) + { + if (this._byteBuffer == null) + { + this._byteBuffer = new byte[this._bufferSize]; + } + this._byteBuffer[this._numBytes++] = b; + } + + internal void AddChar(char ch) + { + if (this._numBytes > 0) + { + this.FlushBytes(); + } + this._charBuffer[this._numChars++] = ch; + } + + private void FlushBytes() + { + if (this._numBytes > 0) + { + this._numChars += this._encoding.GetChars(this._byteBuffer, 0, this._numBytes, this._charBuffer, this._numChars); + this._numBytes = 0; + } + } + + internal string GetString() + { + if (this._numBytes > 0) + { + this.FlushBytes(); + } + if (this._numChars > 0) + { + return new string(this._charBuffer, 0, this._numChars); + } + return string.Empty; + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Utils/JsonUtils.cs b/KJDService/KJD_WebService/Utils/JsonUtils.cs new file mode 100644 index 0000000..83ebf78 --- /dev/null +++ b/KJDService/KJD_WebService/Utils/JsonUtils.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Web; + +namespace KJD_Web.Utils +{ + public class JsonUtils + { + /// + /// 反序列化Json字符串生成对象实体 + /// + /// 对象类型 + /// json字符串 + /// 对象实体 + public static T DeserializeJsonToObject(string jsonStr) where T : class + { + try + { + JsonSerializer serializer = new JsonSerializer(); + StringReader sr = new StringReader(jsonStr); + object obj = serializer.Deserialize(new JsonTextReader(sr), typeof(T)); + T t = obj as T; + return t; + } + catch + { + return null; + } + } + + public static string SerializerObjectToString(object obj) + { + try + { + string str = JsonConvert.SerializeObject(obj, Formatting.None); + return str; + } + catch + { + return null; + } + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Utils/MySqlUtils.cs b/KJDService/KJD_WebService/Utils/MySqlUtils.cs new file mode 100644 index 0000000..96b055f --- /dev/null +++ b/KJDService/KJD_WebService/Utils/MySqlUtils.cs @@ -0,0 +1,682 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Threading; +using System.Web; + +namespace KJD_Web.Utils +{ + public class MysqlUtils + { + public string Message = ""; + + /// + /// 数据库连接字符串 + /// + private string ConnString = ""; + + /// + /// 数据库连接 + /// + private MySqlConnection Conn; + + /// + /// 数据库读取对象 + /// + private MySqlDataReader reader; + + /// + /// 数据库执行对象 + /// + private MySqlCommand cmd = new MySqlCommand(); + + /// + /// 错误信息 + /// + //public static string ErrorString = ""; + + /// + /// 超时(秒) + /// + public int TimeOut = 120; + + /// + /// 链接状态 + /// + public bool Connected + { + get { return Conn != null && Conn.State == ConnectionState.Open; } + } + + /// + /// 是否正在执行 + /// + public bool IsRunning = false; + + /// + /// 初始化数据库链接 + /// + /// 数据库链接 + public MysqlUtils(string connString) + { + ConnString = connString; + ConnTo(); + } + + /// + /// 去掉SQL中的特殊字符 + /// + /// 字符串 + /// + public string ReplaceSql(string value) + { + return ReplaceSqlSpecial(value); + } + + /// + /// 反转字符串,用于mysql反向索引 + /// + /// + /// + public static string ReverseString(string temp) + { + if (string.IsNullOrEmpty(temp)) + return null; + char[] l = temp.ToCharArray(); + Array.Reverse(l); + return new string(l); + } + + /// + /// 去掉SQL中的特殊字符 + /// + /// 字符串 + /// + public static string ReplaceSqlSpecial(string value) + { + if (string.IsNullOrEmpty(value)) + return null; + value = value.Replace("\\", "\\\\"); + value = value.Replace("'", "''"); + //value = value.Replace("\"", "\\\""); + return value; + } + + /// + /// 插入数据 + /// + /// + /// + /// + public int Insert(string table, List keys) + { + string temp = "", tempx = ""; + for (int i = 0; i < keys.Count; i++) + { + temp += ",`" + keys[i].Key + "`"; + tempx += ",'" + keys[i].Value + "'"; + } + temp = temp.Substring(1); + tempx = tempx.Substring(1); + string sql = "insert into " + table + " (" + temp + ") values (" + tempx + ") "; + return (int)ExecuteInsertId(sql); + } + + /// + /// 返回执行表 + /// + /// + /// + public DataTable ExecuteDataTable(string SqlString) + { + return ExecuteDataTable(SqlString, null); + } + + /// + /// 执行sql返回DataTable + /// + /// SQL语句 + /// Sql参数 + /// DataTable + public DataTable ExecuteDataTable(string SqlString, MySqlParameter[] parms) + { + SleepOrGo(); + bool frist = true; + Retry: + if (Conn == null || Conn.State != ConnectionState.Open) + ConnTo(); + try + { + CmdIni(); + cmd.CommandText = SqlString; + if (parms != null) + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + DataSet ds = new DataSet(); + MySqlDataAdapter adapter = new MySqlDataAdapter(); + adapter.SelectCommand = cmd; + adapter.Fill(ds); + return ds.Tables[0]; + //DataTable dt = new DataTable(); + //try + //{ + // reader = cmd.ExecuteReader(); + // dt.Load(reader); + //} + //catch + //{ + // reader = cmd.ExecuteReader(); + // dt = Read(ref reader); + //} + //return dt; + } + catch (Exception e) + { + if (frist) + { + frist = false; + ErrorDoing(e.Message); + goto Retry; + } + AddError(e.Message, SqlString); + return null; + } + finally + { + CloseReader(); + IsRunning = false; + } + } + + /// + /// 针对不同错误,执行不同的修正 + /// + /// + private void ErrorDoing(string message) + { + Message = message; + + if (string.IsNullOrEmpty(message)) + return; + if (message.Contains("Incorrect string value")) + return; + if (message.Contains("Connection must be valid and open")) + ConnTo(); + if (message.Contains("There is already an open DataReader")) + { + Thread.Sleep(500); + ConnTo(); + } + if (message.Contains("Fatal error encountered during command execution.")) + ConnTo(); + if (message.Contains(" StreamWriter ") || message.Contains("未将对象引用设置到对象的实例") || message.Contains("未将对象")) + ConnTo(); + CloseReader(); + Random ra = new Random(Guid.NewGuid().GetHashCode()); + Thread.Sleep(ra.Next(200, 2000)); + } + + /// + /// 关闭读取线程 + /// + private void CloseReader() + { + try + { + if (reader != null && !reader.IsClosed) + reader.Close(); + cmd.Dispose(); + //reader = null; + } + catch + { + } + } + + /// + /// 返回执行行 + /// + /// + /// + public DataRow ExecuteDataTableRow(string SqlString) + { + return ExecuteDataTableRow(SqlString, null); + } + + /// + /// 返回第一行 + /// + /// + /// + public DataRow ExecuteDataTableRow(string SqlString, MySqlParameter[] parms) + { + SleepOrGo(); + bool frist = true; + Retry: + if (Conn == null || Conn.State != ConnectionState.Open) + ConnTo(); + try + { + CmdIni(); + cmd.CommandText = SqlString; + if (parms != null) + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + DataSet ds = new DataSet(); + MySqlDataAdapter adapter = new MySqlDataAdapter(); + adapter.SelectCommand = cmd; + adapter.Fill(ds); + DataTable dt = ds.Tables[0]; + if (dt.Rows.Count > 0) + return dt.Rows[0]; + } + catch (Exception e) + { + if (frist) + { + frist = false; + ErrorDoing(e.Message); + goto Retry; + } + AddError(e.Message, SqlString); + } + finally + { + CloseReader(); + IsRunning = false; + } + return null; + } + + /// + /// 返回第一个执行结果 + /// + /// + /// + public int ExecuteRowCount(string SqlString) + { + string f = ExecuteFirst(SqlString, null); + int c; + int.TryParse(f, out c); + return c; + } + + /// + /// 返回第一个执行结果 + /// + /// + /// + public string ExecuteFirst(string SqlString) + { + return ExecuteFirst(SqlString, null); + } + + /// + /// 返回第一个执行结果 + /// + /// + /// + public int ExecuteFirstInt(string SqlString) + { + string id = ExecuteFirst(SqlString, null); + int i; + int.TryParse(id, out i); + return i; + } + + /// + /// 返回第一个值 + /// + /// + /// + public string ExecuteFirst(string SqlString, MySqlParameter[] parms) + { + SleepOrGo(); + bool frist = true; + Retry: + if (Conn == null || Conn.State != ConnectionState.Open) + ConnTo(); + try + { + CmdIni(); + cmd.CommandText = SqlString; + if (parms != null) + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + reader = cmd.ExecuteReader(); + if (reader.Read()) + return reader[0].ToString(); + return ""; + } + catch (Exception e) + { + if (e.Message.Contains("Illegal mix of collations")) + return null; + if (frist) + { + frist = false; + ErrorDoing(e.Message); + goto Retry; + } + AddError(e.Message, SqlString); + } + finally + { + CloseReader(); + IsRunning = false; + } + return null; + } + + /// + /// 返回插入ID + /// + /// + /// + public long ExecuteInsertId(string SqlString) + { + return ExecuteInsertId(SqlString, null); + } + + /// + /// 返回第一个值 + /// + /// + /// + public long ExecuteInsertId(string SqlString, MySqlParameter[] parms) + { + SleepOrGo(); + bool frist = true; + Retry: + if (Conn == null || Conn.State != ConnectionState.Open) + ConnTo(); + try + { + CmdIni(); + cmd.CommandText = SqlString; + if (parms != null) + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + long id = cmd.LastInsertedId; + return id; + } + catch (Exception e) + { + if (e.Message.Contains(" for key 'PRIMARY'") && e.Message.Contains("Duplicate entry")) + return 0; + if (frist) + { + frist = false; + ErrorDoing(e.Message); + goto Retry; + } + AddError(e.Message, SqlString); + } + finally + { + CloseReader(); + IsRunning = false; + } + return 0; + } + + /// + /// 无返回 + /// + /// + /// + public bool ExecuteNonQuery(string SqlString) + { + return ExecuteNonQuery(SqlString, null); + } + + /// + /// 只保留mysql可识别的字符串 + /// + /// + public string JustUtf8Words(string text) + { + JustUtf8Words(ref text); + return text; + } + + /// + /// 只保留mysql可识别的字符串 + /// + /// + public void JustUtf8Words(ref string text) + { + if (string.IsNullOrEmpty(text)) + return; + var cs = text.ToCharArray(); + List cc = new List(); + foreach (char c in cs) + { + if (c > 7814 && c < 8416 || c > 57096 && c < 59501 || c > 63707 && c < 64309 || c > 65505 || c < 0) + { + if (cc.Contains(c)) + continue; + text = text.Replace(c.ToString(), ""); + cc.Add(c); + } + } + } + + /// + /// 执行无返回SQL语句 + /// + /// SQL语句 + /// Sql参数 + ///是否执行成功 + public bool ExecuteNonQuery(string SqlString, MySqlParameter[] parms) + { + SleepOrGo(); + bool frist = true; + Retry: + if (Conn == null || Conn.State != ConnectionState.Open) + ConnTo(); + try + { + CmdIni(); + cmd.CommandText = SqlString; + if (parms != null) + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + return true; + } + catch (Exception e) + { + if (e.Message.Contains("Illegal mix of collations") || e.Message.Contains("Incorrect string value") + || e.Message.Contains(" for key 'PRIMARY'") && e.Message.Contains("Duplicate entry")) + return false; + + if (frist) + { + frist = false; + ErrorDoing(e.Message); + goto Retry; + } + AddError(e.Message, SqlString); + return false; + } + finally + { + CloseReader(); + IsRunning = false; + } + } + + /// + /// 判断是否存在 + /// + /// + /// + public bool ExecuteExists(string SqlString) + { + return ExecuteExists(SqlString, null); + } + + /// + /// 查询是否存在 + /// + /// SQL语句 + /// SQL参数 + /// 是否存在 + public bool ExecuteExists(string SqlString, MySqlParameter[] parms) + { + SleepOrGo(); + bool frist = true; + Retry: + if (Conn == null || Conn.State != ConnectionState.Open) + ConnTo(); + try + { + + CmdIni(); + cmd.CommandText = SqlString; + if (parms != null) + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + reader = cmd.ExecuteReader(); + if (reader.Read()) + return true; + return false; + } + catch (Exception e) + { + if (frist) + { + frist = false; + ErrorDoing(e.Message); + goto Retry; + } + AddError(e.Message, SqlString); + return false; + } + finally + { + CloseReader(); + IsRunning = false; + } + } + + /// + /// 停止还是前进 + /// + private void SleepOrGo() + { + int i = 0; + while (IsRunning && i < 300) + { + Thread.Sleep(100); + i++; + } + IsRunning = true; + } + + /// + /// 初始化CMD + /// + private void CmdIni() + { + if (reader != null && !reader.IsClosed) + reader.Close(); + if (cmd != null) + cmd.Dispose(); + cmd = new MySqlCommand(); + cmd.Connection = Conn; + cmd.CommandType = CommandType.Text; + cmd.CommandTimeout = TimeOut; + } + + /// + /// 连接数据库 + /// + private void ConnTo() + { + Close(); + try + { + Conn = new MySqlConnection(ConnString); + Conn.Open(); + } + catch (Exception e) + { + AddError(e.Message, ConnString); + } + } + + /// + /// 错误信息 + /// + /// + /// + private void AddError(string message, string sql) + { + if (string.IsNullOrEmpty(message) || message.Contains("Illegal mix of collations")) + return; + ErrorDoing(message); + string errStr = "数据库连接错误:" + message + "\r\nSQL语句:" + sql; + try + { + if (!Directory.Exists("Log")) + { + Directory.CreateDirectory("Log"); + } + File.AppendAllText("Log\\log-" + DateTime.Now.ToString("yyyyMMdd") + ".txt", errStr); + } + catch (Exception ex) + { + } + } + + /// + /// 关闭数据库链接 + /// + public void Close() + { + IsRunning = false; + try + { + if (Conn != null && Conn.State == ConnectionState.Open) + Conn.Close(); + Conn = null; + + try + { + if (reader != null && !reader.IsClosed) + reader.Close(); + } + catch + { + } + reader = null; + } + catch + { + } + } + } + + public class MysqlKeyValues + { + public List List = new List(); + } + + public class MysqlKeyValue + { + public MysqlKeyValue(string key, object value) + { + Key = key; + Value = value == null ? "" : MysqlUtils.ReplaceSqlSpecial(value.ToString()); + } + + public string Key = ""; + public string Value; + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Utils/RegexUtils.cs b/KJDService/KJD_WebService/Utils/RegexUtils.cs new file mode 100644 index 0000000..614cac3 --- /dev/null +++ b/KJDService/KJD_WebService/Utils/RegexUtils.cs @@ -0,0 +1,658 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Web; + +namespace KJD_Web.Utils +{ + public static class RegexUtils + { + /// + /// 返回正则对象所有结果 + /// + /// + /// + /// + public static MatchCollection GetMatchRegex(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + return Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + } + /// + /// 返回正则对象所有结果 + /// + /// + /// + /// + public static MatchCollection GetMatchRegex(ref string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + return Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + } + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatchRegexString(ref string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[0].Groups[1].Value.ToString(); + } + return null; + } + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatchMaxRegexString(ref string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[mc.Count - 1].Groups[1].Value.ToString(); + } + return null; + } + /// + /// 返回匹配的数值 + /// + /// + /// + /// + public static int GetMatchInt(ref string HtmlString, string RegexString) + { + string id = GetMatchRegexString(ref HtmlString, RegexString); + int i; + int.TryParse(id, out i); + return i; + } + + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatchRegexString(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[0].Groups[1].ToString(); + } + return null; + } + /// + /// 是否存在匹配 + /// + /// + /// + /// + public static bool MatchRegex(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return false; + } + return Regex.IsMatch(HtmlString, RegexString, RegexOptions.IgnoreCase); + } + /// + /// 根据正则删除表达式所匹配的内容 + /// + /// + /// + /// + public static string Clear(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + return Regex.Replace(HtmlString, RegexString, "", RegexOptions.IgnoreCase); + } + /// + /// 清除HTML代码 + /// + /// + /// 返回文字内容 + public static string ClearHtml(string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + return Regex.Replace(Regex.Replace(HtmlString, + @"(|||)", ""), "(<[^>]*?>)", "").Trim(); + } + /// + /// 清除HTML代码 + /// + /// + /// 返回文字内容 + public static string ClearHtml(ref string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + return Regex.Replace(Regex.Replace(HtmlString, + @"(|||)", ""), "(<[^>]*?>)", "").Trim(); + } + /// + /// 清除HTML代码 + /// + /// + /// 返回文字内容 + public static void ClearHtmlX(ref string HtmlString) + { + if (string.IsNullOrEmpty(HtmlString)) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return; + } + HtmlString = Regex.Replace(Regex.Replace(HtmlString, + @"(|||)", ""), "(<[^>]*?>)", ""); + } + + /// + /// 清除HTML代码A标签 + /// + /// + /// 返回文字内容 + public static string ClearA(string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + HtmlString = Regex.Replace(HtmlString, "(]*>)", "", RegexOptions.IgnoreCase); + return HtmlString.Trim(); + } + /// + /// 去除空格和特殊空白 + /// + /// + /// + public static string Trim(string text) + { + if (string.IsNullOrEmpty(text)) + return ""; + return text.Replace("\t", " ").Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ").Trim(); + } + + /// + /// 清除HTML代码A标签 + /// + /// + /// 返回文字内容 + public static string ClearTitle(string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + HtmlString = Regex.Replace(HtmlString, "(title=\"[^\"]*\")", ""); + return HtmlString.Trim(); + } + /// + /// 获取值 + /// + /// + /// + /// + public static string GetValue(string html, string reg) + { + return GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + } + /// + /// 清理多余的HTML元素 + /// + /// + /// + public static string ClearNone(string html) + { + if (string.IsNullOrEmpty(html)) + return null; + if (html.Contains("\0") && html.IndexOf("\0") > 0) + html = html.Substring(0, html.IndexOf("\0")); + string h = Clear(html, @"(<\!doctype[^>]*?>)"); + h = Clear(h, @"(]*?>)"); + h = Clear(h, @"()"); + h = Clear(h, @"()"); + h = Clear(h, @"()"); + h = Clear(h, @"(]*?>)"); + h = Clear(h, @"()"); + h = Clear(h, @"(]*?>)"); + h = Clear(h, @"(\s*alt\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*style\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*title\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*id\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*class\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*align\s*=[""'\s]*[^>]*?['""]+)"); + h = h.Replace("\r\n", " "); + h = h.Replace("\n", " ").Replace("\r", " ").Replace("\t", " "); + h = h.Replace(" ", " "); + h = h.Replace(" ", " "); + h = h.Replace(" ", " "); + h = h.Replace(" ", " "); + return h.Replace(" ", " ").Replace(" ", " "); + } + /// + /// 返回执行结果数 + /// + /// + /// + /// + public static int GetRegexCount(string html, string regex) + { + if (html == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + regex); + return 0; + } + return Regex.Matches(html, regex, RegexOptions.IgnoreCase).Count; + } + + + /// + /// 根据正则删除表达式所匹配的内容 + /// + /// + /// + /// + public static string Relpace(string HtmlString, string RegexString, string NewString) + { + if (HtmlString == null) + return null; + return Regex.Replace(HtmlString, RegexString, NewString, RegexOptions.IgnoreCase); + } + /// + /// 根据正则删除表达式所匹配的内容 + /// + /// + /// + /// + public static void Relpace(ref string HtmlString, string RegexString, string NewString) + { + if (HtmlString == null) + return; + HtmlString = Regex.Replace(HtmlString, RegexString, NewString, RegexOptions.IgnoreCase); + } + /// + /// 关键词在文本中出现的次数 + /// + /// + /// + /// + public static int GetStringCount(ref byte[] b, string keyword) + { + if (string.IsNullOrEmpty(keyword)) + return 0; + int c = 0; + bool had; + byte[] b1 = Encoding.UTF8.GetBytes(keyword); + for (int i = 0; i < b.Length - b1.Length; i++) + { + had = false; + for (int j = 0; j < b1.Length; j++) + { + if (b[i + j] != b1[j]) + { + had = true; + break; + } + } + if (had) + { + c++; + i += b1.Length - 1; + } + } + return c; + } + /// + /// 是否存在 + /// + /// + /// + /// + public static bool Exists(string html, string reg) + { + if (string.IsNullOrEmpty(html) || string.IsNullOrEmpty(reg)) + return false; + return new Regex(reg).IsMatch(html); + } + /// + /// 是否是数字 + /// + /// + /// + public static bool IsNumber(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9\.]+$"); + return reg1.IsMatch(str); + } + /// + /// 是否是字母 + /// + /// + /// + public static bool IsChar(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z]+$"); + return reg1.IsMatch(str); + } + /// + /// 是否是字母 + /// + /// + /// + public static bool IsCharOrNumber(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z0-9]+$"); + return reg1.IsMatch(str); + } + + /// + /// 是否是中文字符串列 + /// + /// + /// + public static bool IsWordList(string word) + { + char[] xj = word.ToCharArray(); + for (int j = 0; j < xj.Length; j++) + if (!IsWord(xj[j])) + return false; + return true; + } + /// + /// 是否是字符 + /// + /// + /// + private static bool IsWord(int ascii) + { + if (ascii == 32 || ascii == 35) //空格 + return true; + if (ascii < 58 && ascii > 47) //数字 + return true; + if (ascii < 48 && ascii > 31) //符号 + return true; + if (ascii < 91 && ascii > 64) //小写字母 + return true; + if (ascii < 123 && ascii > 96) //大写字母 + return true; + if (ascii < 40892 && ascii > 13311) //中文字符串 + return true; + return false; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static bool GetBoolValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + if (!string.IsNullOrEmpty(temp) && (temp.ToLower() == "true" || temp == "1")) + return true; + return false; + } + /// + /// 获取值 + /// + /// + /// + /// + public static int GetIntValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + int i; + if (int.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static long GetLongValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + long i; + if (long.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static double GetDoubleValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + double i; + if (double.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static DateTime GetDateValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + DateTime i; + if (DateTime.TryParse(temp, out i)) + return i; + return DateTime.MinValue; + } + /// + /// 获取值 + /// + /// + /// + /// + public static decimal GetDecimalValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + decimal i = 0; + if (decimal.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static decimal GetDecimalJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d-\.]+)"); + decimal i = 0; + if (decimal.TryParse(temp, out i)) + return i; + return 0; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static int GetIntJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d-]+)"); + int i; + if (int.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 时间戳转字符串时间 + /// + /// + /// + /// + public static string GetIntTimeToString(ref string html, string reg) + { + return GetIntTimeToString(ref html, reg, 0); + } + /// + /// 时间戳转字符串时间 + /// + /// + /// + /// 添加时间 + /// + public static string GetIntTimeToString(ref string html, string reg, int addTime) + { + int time = GetIntJson(ref html, reg) + addTime; + DateTime dt = TimeUtils.StampToDateTime(time); + return dt.ToString("yyyy-MM-dd HH:mm:ss"); + } + + /// + /// 获取值 + /// + /// + /// + /// + public static long GetLongJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)"); + long i; + if (long.TryParse(temp, out i)) + return i; + return 0; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static string GetStringJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]+?)[""]"); + if (temp == null) + temp = GetMatchRegexString(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]*?)[""]"); + if (temp == null) + temp = GetMatchRegexString(html, @"[']" + reg + @"['][\s]*:[\s]*[']([^']*?)[']"); + if (temp == null) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)"); + + return temp; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static string GetStringInput(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"]*?name=['""]" + reg + @"[""'][^>]+?value=[""']([^>]+)[""'][^>]*>"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"]*?value=[""']([^>]+)[""'][^>]+?name=['""]" + reg + @"[""'][^>]*>"); + return temp; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static string GetStringQuery(ref string queryString, string key) + { + queryString = "&" + queryString; + int nIndex = queryString.IndexOf("&" + key + "="); + if (nIndex == -1) + return null; + + string temp = queryString.Substring(nIndex).Replace("&" + key + "=", ""); + nIndex = temp.IndexOf('&'); + if (nIndex > -1) + temp = temp.Substring(0, nIndex); + + return temp; + } + + public static string FliterHtmlTag(string htmlStr) + { + if (String.IsNullOrEmpty(htmlStr)) + { + return ""; + } + + string regEx_style = "]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式 + string regEx_script = "]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式 + string regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式 + htmlStr = Regex.Replace(htmlStr, regEx_style, "");//删除css + htmlStr = Regex.Replace(htmlStr, regEx_script, "");//删除js + htmlStr = Regex.Replace(htmlStr, regEx_html, "");//删除html标记 + htmlStr = Regex.Replace(htmlStr, "\\s*|\t|\r|\n", "");//去除tab、空格、空行 + htmlStr = htmlStr.Replace("\"", "");//去除异常的引号 + + return htmlStr.Trim(); + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Utils/TimeUtils.cs b/KJDService/KJD_WebService/Utils/TimeUtils.cs new file mode 100644 index 0000000..86c8e6d --- /dev/null +++ b/KJDService/KJD_WebService/Utils/TimeUtils.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Utils +{ + public class TimeUtils + { + /// + /// 时间戳转为C#格式时间 + /// + /// + /// + public static DateTime StampToDateTime(int timeStamp) + { + DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); + long lTime = long.Parse(timeStamp + "0000000"); + TimeSpan toNow = new TimeSpan(lTime); + return dateTimeStart.Add(toNow); + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/Web.Debug.config b/KJDService/KJD_WebService/Web.Debug.config new file mode 100644 index 0000000..b9a9fde --- /dev/null +++ b/KJDService/KJD_WebService/Web.Debug.config @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/KJDService/KJD_WebService/Web.Release.config b/KJDService/KJD_WebService/Web.Release.config new file mode 100644 index 0000000..755e745 --- /dev/null +++ b/KJDService/KJD_WebService/Web.Release.config @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/KJDService/KJD_WebService/Web.config b/KJDService/KJD_WebService/Web.config new file mode 100644 index 0000000..8d4f150 --- /dev/null +++ b/KJDService/KJD_WebService/Web.config @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KJDService/KJD_WebService/packages.config b/KJDService/KJD_WebService/packages.config new file mode 100644 index 0000000..08df8e6 --- /dev/null +++ b/KJDService/KJD_WebService/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file