| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- 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<string, string> PostParam = new Dictionary<string, string>();
- 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<LoginModel.app_authorization> listModel = new List<LoginModel.app_authorization>();
- 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<LoginModel.app_authorization> listModel = new List<LoginModel.app_authorization>();
- 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<string, string> PostParam = new Dictionary<string, string>();
- 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<LoginModel.enterprise_app_entry> listModel = new List<LoginModel.enterprise_app_entry>();
- 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<LoginModel.enterprise_app_entry> listModel = new List<LoginModel.enterprise_app_entry>();
- 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 + "\"}");
- }
- }
- }
- }
- }
|