| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace LYFZ.WeixinServers.LoginApi
- {
- public partial class industry : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Request.HttpMethod.ToUpper() == "GET")
- return;
- #if ff
- Stream s = Request.InputStream;
- byte[] b = new byte[s.Length];
- s.Read(b, 0, (int)s.Length);
- string post = Encoding.UTF8.GetString(b);
- string xmlData = "";
- try
- {
- Request.InputStream.Seek(0, SeekOrigin.Begin);//强制调整指针位置
- using (var streamReader = new StreamReader(Request.InputStream))
- {
- var decryptMsg = string.Empty;
- xmlData = streamReader.ReadToEnd();
- System.Diagnostics.Debug.Write(xmlData, "加密的微信消息:");
- }
- }
- catch (Exception ex)
- {
-
- }
- #endif
- 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
- {
- }
- }
- else
- {
- Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
- }
- }
- else
- {
- Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
- }
- }
- // 获取POST返回来的数据
- private string PostInput()
- {
- try
- {
- System.IO.Stream s = Request.InputStream;
- int count = 0;
- byte[] buffer = new byte[1024];
- StringBuilder builder = new StringBuilder();
- while ((count = s.Read(buffer, 0, 1024)) > 0)
- {
- builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
- }
- s.Flush();
- s.Close();
- s.Dispose();
- return builder.ToString();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 参数校验
- /// </summary>
- /// <param name="strEntId">企业id</param>
- /// <param name="strAppId">app对象id</param>
- /// <param name="strAppType">app对象类型</param>
- /// <param name="strAppWxId">app对象的微信号</param>
- /// <returns>若参数有效返回true,参数无效或空返回false</returns>
- public bool VerifySysParam(out string strUser, out string strUserPsw)
- {
- strUser = strUserPsw = "";
- if (this.Request.Form["user"] != null && this.Request.Form["user_psw"] != null )
- {
- strUser = Request.Form["user"];
- strUserPsw = Request.Form["user_psw"];
- if (string.IsNullOrEmpty(strUser) || string.IsNullOrEmpty(strUserPsw) )
- return false;
- return true;
- }
- return false;
- }
- /// <summary>
- /// 添加行业的操作
- /// </summary>
- public void OptSysAdd()
- {
- if ( Request.Form["ind_name"] != null && Request.Form["ind_note"] != null )
- {
- LoginModel.industry model = new LoginModel.industry();
- model.ind_id = GlobalCache.GuidString();
- model.ind_name = Request.Form["ind_name"];
- model.ind_note = Request.Form["ind_note"];
- if ( !string.IsNullOrEmpty(model.ind_name) && !string.IsNullOrEmpty(model.ind_note) )
- {// 参数有效;
- try
- {
- LoginDal.industry dal = new LoginDal.industry();
- dal.Add(model, "id");
- Response.Write("{\"code\":200, \"msg\":\"添加行业成功\"}");
- }
- catch
- {
- Response.Write("{\"code\":201, \"msg\":\"添加行业失败\"}");
- }
- }
- else
- {// 参数无效;
- Response.Write("{\"code\":201, \"msg\":\"行业参数无效\"}");
- }
- }
- }
- /// <summary>
- /// 删除行业的操作
- /// </summary>
- public void OptSysDelete()
- {
- if (Request.Form["ind_name"] != null )
- {
- string strIndName = Request.Form["ind_name"];
- if (!string.IsNullOrEmpty(strIndName))
- {
- try
- {
- LoginDal.industry dal = new LoginDal.industry();
- LoginModel.industry model = new LoginModel.industry();
- DataSet ds = dal.GetList("ind_name = '" + strIndName + "'", "id");
- if ( ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 )
- {
- model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
- dal.Delete(model.id);
- Response.Write("{\"code\":200, \"msg\":\"删除行业成功\"}");
- }
- else
- {
- Response.Write("{\"code\":201, \"msg\":\"未找到该行业信息,可能已被删除\"}");
- }
- }
- catch
- {
- Response.Write("{\"code\":201, \"msg\":\"数据库操作失败\"}");
- }
- }
- else
- {
- Response.Write("{\"code\":201, \"msg\":\"行业名称未填\"}");
- return;
- }
- }
- }
- /// <summary>
- /// 修改行业的操作(不必做)
- /// </summary>
- public void OptSysModify()
- {
-
- }
- /// <summary>
- /// 查询行业的操作
- /// </summary>
- public void OptSysQuery()
- {
- LoginDal.industry dal = new LoginDal.industry();
- LoginModel.industry model = new LoginModel.industry();
- List<LoginModel.industry> ListModel = new List<LoginModel.industry>();
- if (Request.Form["ind_name"] != null)
- {// 查询某一个;
- string strIndName = Request.Form["ind_name"];
- try
- {
- DataSet ds = dal.GetList("ind_name = '" + strIndName + "'", "id");
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
- ListModel.Add(model);
- string strJson = JsonConvert.SerializeObject(ListModel);
- Response.Write(strJson);
- }
- else
- {
- Response.Write("{\"code\":201, \"msg\":\"没有该行业信息\"}");
- }
- }
- catch
- {
- Response.Write("{\"code\":201, \"msg\":\"数据操作失败\"}");
- }
- }
- else
- {// 查询所有;
- try
- {
- DataSet ds = dal.GetAllList("id");
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- foreach ( DataRow dr in ds.Tables[0].Rows )
- {
- model = dal.DataRowToModel(dr);
- ListModel.Add(model);
- }
- string strJson = JsonConvert.SerializeObject(ListModel);
- Response.Write(strJson);
- }
- else
- {
- Response.Write("{\"code\":201, \"msg\":\"没有该行业信息\"}");
- }
- }
- catch
- {
- Response.Write("{\"code\":201, \"msg\":\"数据操作失败\"}");
- }
- }
- }
- }
- }
|