Beispiel #1
0
 private static string GetHtml(string url)
 {
     HttpHelper http = new HttpHelper();
     HttpItem item = new HttpItem()
     {
         URL = url,// "http://www.shgtj.gov.cn/2011/gcjsxx/xmxx/ghxzyj/",//URL     必需项
         Method = "get",//URL     可选项 默认为Get
         IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
         Cookie = "",//字符串Cookie     可选项
         Referer = "",//来源URL     可选项
         Postdata = "",//Post数据     可选项GET时不需要写
         Timeout = 100000,//连接超时时间     可选项默认为100000
         ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
         UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值
         ContentType = "text/html",//返回类型    可选项有默认值
         Allowautoredirect = false,//是否根据301跳转     可选项
         //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
         //Connectionlimit = 1024,//最大连接数     可选项 默认为1024
         ProxyIp = "",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数
         //ProxyPwd = "123456",//代理服务器密码     可选项
         //ProxyUserName = "******",//代理服务器账户名     可选项
         ResultType = ResultType.String
     };
     HttpResult result = http.GetHtml(item);
     return result.Html;
 }
 public FrmPlotWaterLineGuide(PlotWaterLine pPlotLine)
 {
     InitializeComponent();
     //http页面请求类
     httpHelper = new HttpHelper();
     //构造函数传递当前生产线
     mPlotLine = pPlotLine;
     //网页请求语言设置
     if (mPlotLine.Chaset != null && mPlotLine.Chaset.Length > 0)
     {
         CmbChaset.Text = mPlotLine.Chaset;
     }
     else
     {
         CmbChaset.SelectedIndex = 0;
     }
     //网页请求方法设置
     if (mPlotLine.Method != null && mPlotLine.Method.Length > 0)
     {
         CmbMethod.Text = mPlotLine.Method;
     }
     else
     {
         CmbMethod.SelectedIndex = 0;
     }
 }
Beispiel #3
0
        static CrawlerManager()
        {
            httpHelper = new HttpHelper();
            item = new HttpItem();

            mCanAttemper = true;
            MaxThreads = 30;
        }
Beispiel #4
0
        public JObject oldLogin(string account, string password)
        {
            //调登陆接口
            JObject j1   = new JObject();
            string  post = "{\"account\":\"" + account + "\",\"password\":\"" + password + "\"}";


            DotNet4.Utilities.HttpHelper hh = new DotNet4.Utilities.HttpHelper();
            HttpItem hi = new HttpItem()
            {
                URL         = LoginService._STURLInterface + "/api/login/loginPost",
                UserAgent   = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
                Accept      = "application/json",
                Method      = "POST",
                ContentType = "application/json",
                Postdata    = post,
                Referer     = "http://59.173.8.184:27001/login",
                KeepAlive   = true,
            };

            hi.Header.Add("Accept-Encoding", "gzip,deflate");
            hi.Header.Add("Accept-Language", "zh-Hans-CN,zh-Hans;q=0.5");

            HttpResult hr = hh.GetHtml(hi);

            JObject json = (JObject)Json_Check(hr.Html);

            if (json != null && json["head"]["respCode"] != null && json["head"]["respCode"].ToString() == "0")
            {
                string       userandpwd = EncryptDES(account + "----" + password + "----" + null, "ab123456");
                string       strpath    = System.Environment.CurrentDirectory;
                StreamWriter sw         = new StreamWriter(strpath + "\\" + "account.txt", false, Encoding.UTF8);

                sw.WriteLine(userandpwd);
                sw.Close();

                j1["login"] = json;

                //企业接口
                //string url = FactoryRecord121._STURLInterface + "/api/prodcution/qryQualityRegister";
                var reqModel = new Jobject()
                {
                    head = new head
                    {
                        channelCode = "010200000000010000000001",
                        userIp      = "172.16.4.1",
                        reqTime     = "20170101120000111",
                        ticket      = "WT2017010112000011100000000",
                        token       = "abeadedf-dcd8-4f22-a035-569168006ec1"
                    },
                    body = new body
                    {
                        status   = "",
                        area     = "",
                        page     = "",
                        pageSize = ""
                    }
                };

                JObject jsonpost   = new JObject();
                JObject jsonheader = new JObject();
                JObject jsonbody   = new JObject();
                jsonheader["channelCode"] = "010200000000010000000001";
                jsonheader["userIp"]      = "172.16.4.1";
                jsonheader["reqTime"]     = "20170101120000111";
                jsonheader["ticket"]      = "WT2017010112000011100000000";
                jsonheader["token"]       = "abeadedf-dcd8-4f22-a035-569168006ec1";
                jsonbody["enterprise"]    = null;
                jsonbody["status"]        = "";
                jsonbody["area"]          = "";
                jsonbody["page"]          = "";
                jsonbody["pageSize"]      = "";
                jsonpost["head"]          = jsonheader;
                jsonpost["body"]          = jsonbody;
                string post2 = "requestBody=" + JsonConvert.SerializeObject(jsonpost).ToString();
                //post2 = "requestBody={\"head\":{\"channelCode\":\"010200000000010000000001\",\"userIp\":\"172.16.4.1\",\"reqTime\":\"20170101120000111\",\"ticket\":\"WT2017010112000011100000000\",\"token\":\"abeadedf-dcd8-4f22-a035-569168006ec1\"},\"body\":{\"enterprise\":null,\"status\":\"\",\"area\":\"\",\"page\":\"\",\"pageSize\":\"\"}}";

                //var pro = "requestBody=" + JsonConvert.SerializeObject(reqModel);
                hi = new HttpItem()
                {
                    URL          = LoginService._STURLInterface + "/api/prodcution/qryQualityRegister",
                    UserAgent    = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
                    Accept       = "application/json",
                    Method       = "POST",
                    ContentType  = "application/x-www-form-urlencoded",
                    PostDataType = PostDataType.Byte,
                    PostdataByte = Encoding.Default.GetBytes(post2),
                    Referer      = "http://59.173.8.184:27001/login",
                    KeepAlive    = true,
                };
                hi.Header.Add("Accept-Encoding", "gzip,deflate");
                hi.Header.Add("Accept-Language", "zh-Hans-CN,zh-Hans;q=0.5");
                hr       = hh.GetHtml(hi);
                json     = (JObject)Json_Check(hr.Html);
                j1["en"] = json;
            }
            return(j1);
        }
Beispiel #5
0
        /// <summary>
        /// 获取有权限的门禁列表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private string GetDoorList(DataRow row)
        {
            #region 获取基本传参
            string CommID = string.Empty;
            if (row.Table.Columns.Contains("CommID"))
            {
                CommID = row["CommID"].ToString();
            }
            string RoomID = string.Empty;
            if (row.Table.Columns.Contains("RoomID"))
            {
                RoomID = row["RoomID"].ToString();
            }
            #endregion
            #region 获取小区配置和房间配置
            Tb_Community tb_Community = GetCommunityByCommID(CommID);
            if (null == tb_Community)
            {
                return(new ApiResult(false, "未配置该小区").toJson());
            }
            string erpConnStr = GetConnectionStr(tb_Community);
            LiLingEntranceConfig lilingEntranceConfig = null;
            dynamic RoomConfig = null;
            using (IDbConnection conn = new SqlConnection(erpConnStr))
            {
                dynamic Config = conn.QueryFirstOrDefault("SELECT * FROM Tb_LiLing_Entrance_Config WHERE CommID = @CommID", new { CommID });
                if (null == Config)
                {
                    return(new ApiResult(false, "该小区未配置门禁信息").toJson());
                }
                try
                {
                    lilingEntranceConfig = JsonConvert.DeserializeObject <LiLingEntranceConfig>(Convert.ToString(Config.Config));
                }
                catch (Exception)
                {
                    return(new ApiResult(false, "门禁配置信息有误").toJson());
                }
                if (null == lilingEntranceConfig)
                {
                    return(new ApiResult(false, "门禁配置信息为空").toJson());
                }
                RoomConfig = conn.QueryFirstOrDefault("SELECT CallNum,BlueNum,QRCodeNum FROM Tb_LiLing_Entrance_Room WHERE CommID = @CommID AND RoomID = @RoomID", new { CommID, RoomID });
                if (null == RoomConfig)
                {
                    return(new ApiResult(false, "房间权限配置信息为空").toJson());
                }
            }
            string SERVER_URL      = lilingEntranceConfig.ServerUrl;
            string CLIENT_USERNAME = lilingEntranceConfig.ClientUserName;
            string CLIENT_OSTYPE   = lilingEntranceConfig.ClientOSType;
            string CLIENT_ID       = lilingEntranceConfig.ClientID;
            string CLIENT_SECRET   = lilingEntranceConfig.ClientSecret;
            #endregion

            #region 获取AccessToken
            string access_token = string.Empty;
            string sessionId    = string.Empty;
            string Cookie       = string.Empty;
            try
            {
                string     param = $"client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&grant_type=client_credentials&userName={CLIENT_USERNAME}&osType={CLIENT_OSTYPE}";
                HttpHelper http  = new HttpHelper();
                HttpItem   item  = new HttpItem()
                {
                    URL              = SERVER_URL + "/rest/accesstoken/getAccessToken", //URL     必需项
                    Method           = "POST",                                          //URL     可选项 默认为Get
                    Timeout          = 3000,                                            //连接超时时间     可选项默认为100000
                    ReadWriteTimeout = 3000,                                            //写入Post数据超时时间     可选项默认为30000
                    IsToLower        = false,                                           //得到的HTML代码是否转成小写     可选项默认转小写
                    ContentType      = "application/x-www-form-urlencoded",
                    PostEncoding     = Encoding.UTF8,
                    Cookie           = Cookie,
                    Postdata         = param,                 //Post数据     可选项GET时不需要写
                    ResultType       = ResultType.String,     //返回数据类型,是Byte还是String
                    ProtocolVersion  = HttpVersion.Version11, //获取或设置用于请求的 HTTP 版本。默认为 System.Net.HttpVersion.Version11
                };
                HttpResult result = http.GetHtml(item);
                JObject    jObj   = JsonConvert.DeserializeObject <JObject>(result.Html);
                if (!"1".Equals(jObj["code"].ToString()) || !"success".Equals(jObj["state"].ToString()))
                {
                    GetLog().Debug("LiLingEntrance:获取AccessToken失败:" + JsonConvert.SerializeObject(jObj));
                    return(new ApiResult(false, "获取AccessToken失败,请重试").toJson());
                }
                access_token = (string)jObj["access_token"];
                sessionId    = (string)jObj["sessionId"];
                Cookie       = $"JSESSIONID={sessionId}";
            }
            catch (Exception ex)
            {
                GetLog().Error(ex.Message + Environment.CommandLine + ex.StackTrace);
                return(new ApiResult(false, "获取AccessToken异常,请重试").toJson());
            }
            #endregion

            #region 获取本项目蓝牙门禁信息
            string        neigh_no = lilingEntranceConfig.NeighStructure;
            List <string> DoorList = new List <string>();
            try
            {
                string     param = $"access_token={access_token}&neigh_no={neigh_no}";
                HttpHelper http  = new HttpHelper();
                HttpItem   item  = new HttpItem()
                {
                    URL              = SERVER_URL + "/rest/api/third/getDoorList", //URL     必需项
                    Method           = "POST",                                     //URL     可选项 默认为Get
                    Timeout          = 3000,                                       //连接超时时间     可选项默认为100000
                    ReadWriteTimeout = 3000,                                       //写入Post数据超时时间     可选项默认为30000
                    IsToLower        = false,                                      //得到的HTML代码是否转成小写     可选项默认转小写
                    ContentType      = "application/x-www-form-urlencoded",
                    PostEncoding     = Encoding.UTF8,
                    Cookie           = Cookie,
                    Postdata         = param,                 //Post数据     可选项GET时不需要写
                    ResultType       = ResultType.String,     //返回数据类型,是Byte还是String
                    ProtocolVersion  = HttpVersion.Version11, //获取或设置用于请求的 HTTP 版本。默认为 System.Net.HttpVersion.Version11
                };
                HttpResult result = http.GetHtml(item);
                JObject    jObj   = JsonConvert.DeserializeObject <JObject>(result.Html);
                if (!"1".Equals(jObj["code"].ToString()) || !"success".Equals(jObj["state"].ToString()))
                {
                    GetLog().Debug("LiLingEntrance:获取小区门禁列表失败:" + JsonConvert.SerializeObject(jObj));
                    return(new ApiResult(false, "获取小区门禁列表失败,请重试").toJson());
                }
                JArray door_list = (JArray)jObj["door_list"];
                if (null != door_list)
                {
                    foreach (JObject door in door_list)
                    {
                        DoorList.Add(door["door_name"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                GetLog().Error(ex.Message + Environment.CommandLine + ex.StackTrace);
                return(new ApiResult(false, "获取小区门禁列表异常,请重试").toJson());
            }
            #endregion

            return(new ApiResult(true, new { RoomConfig = RoomConfig, DoorList = DoorList }).toJson());
        }