ent-app-auth.aspx.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. namespace LYFZ.WeixinServers.LoginApi
  10. {
  11. public partial class app_auth : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. if (Request.HttpMethod.ToUpper() == "GET")
  16. return;
  17. if (Request.QueryString["type"] != null)
  18. {
  19. string strOptType = Request.QueryString["type"];
  20. if (!string.IsNullOrEmpty(strOptType))
  21. {
  22. if (strOptType.StartsWith("sys-"))
  23. {
  24. string strUser, strUserPsw;
  25. if (VerifySysParam(out strUser, out strUserPsw))
  26. {
  27. LoginModel.user model = GlobalCache.GetUserInfo(strUser, strUserPsw);
  28. if (model == null)
  29. {
  30. Response.Write("{\"code\":201, \"msg\":\"账号或密码不对\"}");
  31. return;
  32. }
  33. if (model.user_type != 0)
  34. {
  35. Response.Write("{\"code\":201, \"msg\":\"账号操作权限不足\"}");
  36. return;
  37. }
  38. switch (strOptType)
  39. {
  40. case "sys-add":
  41. {
  42. OptSysAdd();
  43. }
  44. break;
  45. case "sys-delete":
  46. {
  47. OptSysDelete();
  48. }
  49. break;
  50. case "sys-modify":
  51. {
  52. OptSysModify();
  53. }
  54. break;
  55. case "sys-query":
  56. {
  57. OptSysQuery();
  58. }
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. else
  65. {
  66. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  67. }
  68. }
  69. else
  70. {
  71. string strKfAccount, strKfPassword;
  72. if (VerifyParam(out strKfAccount, out strKfPassword))
  73. {
  74. LoginModel.kf_particulars model = GlobalCache.DalKfParticulars.GetModel(strKfAccount, strKfPassword);
  75. if (model == null)
  76. {
  77. Response.Write("{\"code\":201, \"msg\":\"没有该客服账号\"}");
  78. return;
  79. }
  80. switch (strOptType)
  81. {
  82. case "add":
  83. {
  84. OptAdd(model);
  85. }
  86. break;
  87. case "delete":
  88. {
  89. OptDelete(model);
  90. }
  91. break;
  92. case "modify":
  93. {
  94. OptModify(model);
  95. }
  96. break;
  97. case "query":
  98. {
  99. OptQuery(model);
  100. }
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. else
  107. {
  108. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  109. }
  110. }
  111. }
  112. else
  113. {
  114. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  115. }
  116. }
  117. else
  118. {
  119. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  120. }
  121. }
  122. public bool VerifySysParam(out string strUser, out string strUserPsw)
  123. {
  124. strUser = strUserPsw = "";
  125. if (this.Request.Form["user"] != null && this.Request.Form["user_psw"] != null)
  126. {
  127. strUser = this.Request.Form["user"];
  128. strUserPsw = this.Request.Form["user_psw"];
  129. if (!string.IsNullOrEmpty(strUser) && !string.IsNullOrEmpty(strUserPsw))
  130. return true;
  131. }
  132. return false;
  133. }
  134. public void OptSysAdd()
  135. {
  136. bool hasnull = false;
  137. Dictionary<string, string> PostParam = new Dictionary<string, string>();
  138. string[] not_null_field = { "ent_id", "app_type_name", "app_id"};
  139. foreach (string str in not_null_field)
  140. {
  141. if (Request.Form[str] == null)
  142. {
  143. hasnull = true;
  144. break;
  145. }
  146. PostParam.Add(str, Request.Form[str]);
  147. }
  148. if (hasnull)
  149. {
  150. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  151. }
  152. else
  153. {
  154. try
  155. {
  156. LoginModel.app_authorization model = new LoginModel.app_authorization();
  157. model.ent_id = PostParam["ent_id"];
  158. model.app_type_name = PostParam["app_type_name"];
  159. model.app_id = PostParam["app_id"];
  160. model.authorize_status = 0;// Convert.ToInt32(PostParam["app_auth_status"]); // 0:表示未授权, 1:表示授权成功;
  161. model.create_time = DateTime.Now;
  162. if (string.IsNullOrEmpty(model.ent_id) || string.IsNullOrEmpty(model.app_id))
  163. {
  164. Response.Write("{\"code\":201, \"msg\":\"企业id和app对象id不能空\"}");
  165. return;
  166. }
  167. GlobalCache.DalAppAuthorize.Add(model, "id");
  168. Response.Write("{\"code\":200, \"msg\":\"添加企业app对象成功\"}");
  169. }
  170. catch (Exception ex)
  171. {
  172. Response.Write("{\"code\":201, \"msg\":\"操作失败:" + ex.Message + "\"}");
  173. }
  174. }
  175. }
  176. public void OptSysDelete()
  177. {
  178. if (Request.Form["ent_id"] != null && Request.Form["app_id"] != null)
  179. {
  180. string strEntId = Request.Form["ent_id"];
  181. string strAppId = Request.Form["app_id"];
  182. if (!string.IsNullOrEmpty(strEntId) && !string.IsNullOrEmpty(strAppId))
  183. {
  184. try
  185. {
  186. GlobalCache.DalAppAuthorize.DeleteEx(strEntId, strAppId);
  187. Response.Write("{\"code\":200, \"msg\":\"删除成功\"}");
  188. }
  189. catch (Exception ex)
  190. {
  191. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  192. }
  193. }
  194. else
  195. {
  196. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  197. }
  198. }
  199. else
  200. {
  201. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  202. }
  203. }
  204. public void OptSysModify()
  205. {
  206. // 不提供修改;
  207. }
  208. public void OptSysQuery()
  209. {
  210. if (Request.Form["ent_id"] != null)
  211. {
  212. string strEntId = Request.Form["ent_id"];
  213. if (!string.IsNullOrEmpty(strEntId))
  214. {
  215. try
  216. {
  217. List<LoginModel.app_authorization> listModel = new List<LoginModel.app_authorization>();
  218. DataSet ds = GlobalCache.DalAppAuthorize.GetList("ent_id = '" + strEntId + "'", "id");
  219. if (ds != null && ds.Tables.Count > 0)
  220. {
  221. foreach (DataRow dr in ds.Tables[0].Rows)
  222. {
  223. listModel.Add(GlobalCache.DalAppAuthorize.DataRowToModel(dr));
  224. }
  225. string strJson = JsonConvert.SerializeObject(listModel);
  226. Response.Write(strJson);
  227. }
  228. else
  229. {
  230. Response.Write("{\"code\":201, \"msg\":\"没有数据\"}");
  231. }
  232. }
  233. catch (Exception ex)
  234. {
  235. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  236. }
  237. }
  238. else
  239. {
  240. Response.Write("{\"code\":201, \"msg\":\"查询的企业id参数空!\"}");
  241. }
  242. }
  243. else
  244. {
  245. try
  246. {
  247. List<LoginModel.app_authorization> listModel = new List<LoginModel.app_authorization>();
  248. DataSet ds = GlobalCache.DalAppAuthorize.GetAllList("id");
  249. if (ds != null && ds.Tables.Count > 0)
  250. {
  251. foreach (DataRow dr in ds.Tables[0].Rows)
  252. {
  253. listModel.Add(GlobalCache.DalAppAuthorize.DataRowToModel(dr));
  254. }
  255. string strJson = JsonConvert.SerializeObject(listModel);
  256. Response.Write(strJson);
  257. }
  258. else
  259. {
  260. Response.Write("{\"code\":201, \"msg\":\"没有数据\"}");
  261. }
  262. }
  263. catch (Exception ex)
  264. {
  265. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  266. }
  267. }
  268. }
  269. public bool VerifyParam(out string strKfAccount, out string strKfPassword)
  270. {
  271. strKfAccount = strKfPassword = "";
  272. if (Request.Form["kf_account"] != null && Request.Form["kf_psw"] != null)
  273. {
  274. strKfAccount = Request.Form["kf_account"];
  275. strKfPassword = Request.Form["kf_psw"];
  276. if (!string.IsNullOrEmpty(strKfAccount) && !string.IsNullOrEmpty(strKfPassword))
  277. return true;
  278. }
  279. return false;
  280. }
  281. public void OptAdd(LoginModel.kf_particulars kf) {
  282. bool hasnull = false;
  283. Dictionary<string, string> PostParam = new Dictionary<string, string>();
  284. string[] not_null_field = {"app_type_name", "app_id" };
  285. foreach (string str in not_null_field)
  286. {
  287. if (Request.Form[str] == null)
  288. {
  289. hasnull = true;
  290. break;
  291. }
  292. PostParam.Add(str, Request.Form[str]);
  293. }
  294. if (hasnull)
  295. {
  296. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  297. }
  298. else
  299. {
  300. try
  301. {
  302. LoginModel.app_authorization model = new LoginModel.app_authorization();
  303. model.ent_id = kf.ent_id;
  304. model.app_type_name = PostParam["app_type_name"];
  305. model.app_id = PostParam["app_id"];
  306. model.authorize_status = 0;//Convert.ToInt32(PostParam["app_auth_status"]);
  307. model.create_time = DateTime.Now;
  308. if (string.IsNullOrEmpty(model.ent_id) || string.IsNullOrEmpty(model.app_id))
  309. {
  310. Response.Write("{\"code\":201, \"msg\":\"企业id和app对象id不能空\"}");
  311. return;
  312. }
  313. GlobalCache.DalAppAuthorize.Add(model, "id");
  314. Response.Write("{\"code\":200, \"msg\":\"添加企业app对象成功\"}");
  315. }
  316. catch (Exception ex)
  317. {
  318. Response.Write("{\"code\":201, \"msg\":\"操作失败:" + ex.Message + "\"}");
  319. }
  320. }
  321. }
  322. public void OptDelete(LoginModel.kf_particulars kf)
  323. {
  324. if ( Request.Form["app_id"] != null)
  325. {
  326. string strAppId = Request.Form["app_id"];
  327. if ( !string.IsNullOrEmpty(strAppId))
  328. {
  329. try
  330. {
  331. GlobalCache.DalAppAuthorize.DeleteEx(kf.ent_id, strAppId);
  332. Response.Write("{\"code\":200, \"msg\":\"删除成功\"}");
  333. }
  334. catch (Exception ex)
  335. {
  336. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  337. }
  338. }
  339. else
  340. {
  341. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  342. }
  343. }
  344. else
  345. {
  346. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  347. }
  348. }
  349. public void OptModify(LoginModel.kf_particulars kf) { }
  350. public void OptQuery(LoginModel.kf_particulars kf)
  351. {
  352. if (Request.Form["app_id"] != null)
  353. {
  354. string strAppId = Request.Form["app_id"];
  355. if (!string.IsNullOrEmpty(strAppId))
  356. {
  357. try
  358. {
  359. List<LoginModel.enterprise_app_entry> listModel = new List<LoginModel.enterprise_app_entry>();
  360. DataSet ds = GlobalCache.DalEnterpriseAppEntry.GetList("ent_id = '" + kf.ent_id + "' and app_id ='" + strAppId + "'", "id");
  361. if (ds != null && ds.Tables.Count > 0)
  362. {
  363. foreach (DataRow dr in ds.Tables[0].Rows)
  364. {
  365. listModel.Add(GlobalCache.DalEnterpriseAppEntry.DataRowToModel(dr));
  366. }
  367. string strJson = JsonConvert.SerializeObject(listModel);
  368. Response.Write(strJson);
  369. }
  370. else
  371. {
  372. Response.Write("{\"code\":201, \"msg\":\"没有数据\"}");
  373. }
  374. }
  375. catch (Exception ex)
  376. {
  377. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  378. }
  379. }
  380. else
  381. {
  382. Response.Write("{\"code\":201, \"msg\":\"查询的企业id参数空!\"}");
  383. }
  384. }
  385. else
  386. {
  387. try
  388. {
  389. List<LoginModel.enterprise_app_entry> listModel = new List<LoginModel.enterprise_app_entry>();
  390. DataSet ds = GlobalCache.DalEnterpriseAppEntry.GetList("ent_id = '" + kf.ent_id + "'", "id");
  391. if (ds != null && ds.Tables.Count > 0)
  392. {
  393. foreach (DataRow dr in ds.Tables[0].Rows)
  394. {
  395. listModel.Add(GlobalCache.DalEnterpriseAppEntry.DataRowToModel(dr));
  396. }
  397. string strJson = JsonConvert.SerializeObject(listModel);
  398. Response.Write(strJson);
  399. }
  400. else
  401. {
  402. Response.Write("{\"code\":201, \"msg\":\"没有数据\"}");
  403. }
  404. }
  405. catch (Exception ex)
  406. {
  407. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  408. }
  409. }
  410. }
  411. }
  412. }