using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace LYFZ.WeixinServers.LoginApi { public partial class app_auth : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod.ToUpper() == "GET") return; if (Request.QueryString["type"] != null) { string strOptType = Request.QueryString["type"]; if (!string.IsNullOrEmpty(strOptType)) { if (strOptType.StartsWith("sys-")) { string strUser, strUserPsw; if (VerifySysParam(out strUser, out strUserPsw)) { LoginModel.user model = GlobalCache.GetUserInfo(strUser, strUserPsw); if (model == null) { Response.Write("{\"code\":201, \"msg\":\"账号或密码不对\"}"); return; } if (model.user_type != 0) { Response.Write("{\"code\":201, \"msg\":\"账号操作权限不足\"}"); return; } switch (strOptType) { case "sys-add": { OptSysAdd(); } break; case "sys-delete": { OptSysDelete(); } break; case "sys-modify": { OptSysModify(); } break; case "sys-query": { OptSysQuery(); } break; default: break; } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } else { string strKfAccount, strKfPassword; if (VerifyParam(out strKfAccount, out strKfPassword)) { LoginModel.kf_particulars model = GlobalCache.DalKfParticulars.GetModel(strKfAccount, strKfPassword); if (model == null) { Response.Write("{\"code\":201, \"msg\":\"没有该客服账号\"}"); return; } switch (strOptType) { case "add": { OptAdd(model); } break; case "delete": { OptDelete(model); } break; case "modify": { OptModify(model); } break; case "query": { OptQuery(model); } break; default: break; } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } public bool VerifySysParam(out string strUser, out string strUserPsw) { strUser = strUserPsw = ""; if (this.Request.Form["user"] != null && this.Request.Form["user_psw"] != null) { strUser = this.Request.Form["user"]; strUserPsw = this.Request.Form["user_psw"]; if (!string.IsNullOrEmpty(strUser) && !string.IsNullOrEmpty(strUserPsw)) return true; } return false; } public void OptSysAdd() { bool hasnull = false; Dictionary PostParam = new Dictionary(); string[] not_null_field = { "ent_id", "app_type_name", "app_id"}; foreach (string str in not_null_field) { if (Request.Form[str] == null) { hasnull = true; break; } PostParam.Add(str, Request.Form[str]); } if (hasnull) { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } else { try { LoginModel.app_authorization model = new LoginModel.app_authorization(); model.ent_id = PostParam["ent_id"]; model.app_type_name = PostParam["app_type_name"]; model.app_id = PostParam["app_id"]; model.authorize_status = 0;// Convert.ToInt32(PostParam["app_auth_status"]); // 0:表示未授权, 1:表示授权成功; model.create_time = DateTime.Now; if (string.IsNullOrEmpty(model.ent_id) || string.IsNullOrEmpty(model.app_id)) { Response.Write("{\"code\":201, \"msg\":\"企业id和app对象id不能空\"}"); return; } GlobalCache.DalAppAuthorize.Add(model, "id"); Response.Write("{\"code\":200, \"msg\":\"添加企业app对象成功\"}"); } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"操作失败:" + ex.Message + "\"}"); } } } public void OptSysDelete() { if (Request.Form["ent_id"] != null && Request.Form["app_id"] != null) { string strEntId = Request.Form["ent_id"]; string strAppId = Request.Form["app_id"]; if (!string.IsNullOrEmpty(strEntId) && !string.IsNullOrEmpty(strAppId)) { try { GlobalCache.DalAppAuthorize.DeleteEx(strEntId, strAppId); Response.Write("{\"code\":200, \"msg\":\"删除成功\"}"); } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } public void OptSysModify() { // 不提供修改; } public void OptSysQuery() { if (Request.Form["ent_id"] != null) { string strEntId = Request.Form["ent_id"]; if (!string.IsNullOrEmpty(strEntId)) { try { List listModel = new List(); DataSet ds = GlobalCache.DalAppAuthorize.GetList("ent_id = '" + strEntId + "'", "id"); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { listModel.Add(GlobalCache.DalAppAuthorize.DataRowToModel(dr)); } string strJson = JsonConvert.SerializeObject(listModel); Response.Write(strJson); } else { Response.Write("{\"code\":201, \"msg\":\"没有数据\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"查询的企业id参数空!\"}"); } } else { try { List listModel = new List(); DataSet ds = GlobalCache.DalAppAuthorize.GetAllList("id"); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { listModel.Add(GlobalCache.DalAppAuthorize.DataRowToModel(dr)); } string strJson = JsonConvert.SerializeObject(listModel); Response.Write(strJson); } else { Response.Write("{\"code\":201, \"msg\":\"没有数据\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } } public bool VerifyParam(out string strKfAccount, out string strKfPassword) { strKfAccount = strKfPassword = ""; if (Request.Form["kf_account"] != null && Request.Form["kf_psw"] != null) { strKfAccount = Request.Form["kf_account"]; strKfPassword = Request.Form["kf_psw"]; if (!string.IsNullOrEmpty(strKfAccount) && !string.IsNullOrEmpty(strKfPassword)) return true; } return false; } public void OptAdd(LoginModel.kf_particulars kf) { bool hasnull = false; Dictionary PostParam = new Dictionary(); string[] not_null_field = {"app_type_name", "app_id" }; foreach (string str in not_null_field) { if (Request.Form[str] == null) { hasnull = true; break; } PostParam.Add(str, Request.Form[str]); } if (hasnull) { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } else { try { LoginModel.app_authorization model = new LoginModel.app_authorization(); model.ent_id = kf.ent_id; model.app_type_name = PostParam["app_type_name"]; model.app_id = PostParam["app_id"]; model.authorize_status = 0;//Convert.ToInt32(PostParam["app_auth_status"]); model.create_time = DateTime.Now; if (string.IsNullOrEmpty(model.ent_id) || string.IsNullOrEmpty(model.app_id)) { Response.Write("{\"code\":201, \"msg\":\"企业id和app对象id不能空\"}"); return; } GlobalCache.DalAppAuthorize.Add(model, "id"); Response.Write("{\"code\":200, \"msg\":\"添加企业app对象成功\"}"); } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"操作失败:" + ex.Message + "\"}"); } } } public void OptDelete(LoginModel.kf_particulars kf) { if ( Request.Form["app_id"] != null) { string strAppId = Request.Form["app_id"]; if ( !string.IsNullOrEmpty(strAppId)) { try { GlobalCache.DalAppAuthorize.DeleteEx(kf.ent_id, strAppId); Response.Write("{\"code\":200, \"msg\":\"删除成功\"}"); } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } public void OptModify(LoginModel.kf_particulars kf) { } public void OptQuery(LoginModel.kf_particulars kf) { if (Request.Form["app_id"] != null) { string strAppId = Request.Form["app_id"]; if (!string.IsNullOrEmpty(strAppId)) { try { List listModel = new List(); DataSet ds = GlobalCache.DalEnterpriseAppEntry.GetList("ent_id = '" + kf.ent_id + "' and app_id ='" + strAppId + "'", "id"); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { listModel.Add(GlobalCache.DalEnterpriseAppEntry.DataRowToModel(dr)); } string strJson = JsonConvert.SerializeObject(listModel); Response.Write(strJson); } else { Response.Write("{\"code\":201, \"msg\":\"没有数据\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"查询的企业id参数空!\"}"); } } else { try { List listModel = new List(); DataSet ds = GlobalCache.DalEnterpriseAppEntry.GetList("ent_id = '" + kf.ent_id + "'", "id"); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { listModel.Add(GlobalCache.DalEnterpriseAppEntry.DataRowToModel(dr)); } string strJson = JsonConvert.SerializeObject(listModel); Response.Write(strJson); } else { Response.Write("{\"code\":201, \"msg\":\"没有数据\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } } } }