Exemplo n.º 1
0
        /// <summary>
        /// 查询数据
        /// </summary>
        protected DataTable get_search_list(int _pagesize, out int _totalcount)
        {
            //组合查询条件
            string strWhere = "(title like '%" + keyword + "%' or content like '%" + keyword + "%')";
            //创建一个DataTable
            DataTable dt = new DataTable();

            dt.Columns.Add("title", Type.GetType("System.String"));
            dt.Columns.Add("remark", Type.GetType("System.String"));
            dt.Columns.Add("link_url", Type.GetType("System.String"));
            dt.Columns.Add("add_time", Type.GetType("System.String"));

            Hoto.BLL.search bll = new Hoto.BLL.search();
            DataSet         ds  = bll.GetList(_pagesize, page, strWhere, "add_time desc", out _totalcount);

            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr1      = ds.Tables[0].Rows[i];
                    string  link_url = get_url_rewrite(dr1["channel_id"].ToString(), Convert.ToInt32(dr1["id"]));
                    if (!string.IsNullOrEmpty(link_url))
                    {
                        DataRow dr = dt.NewRow();
                        dr["title"]    = dr1["title"];                                       //标题
                        dr["remark"]   = HotoUtils.DropHTML(dr1["content"].ToString(), 255); //简介
                        dr["link_url"] = link_url;                                           //链接地址
                        dr["add_time"] = dr1["add_time"];                                    //发布时间
                        dt.Rows.Add(dr);
                    }
                }
            }

            return(dt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 裁剪图片并保存
        /// </summary>
        public bool cropSaveAs(string fileName, string newFileName, int maxWidth, int maxHeight, int cropWidth, int cropHeight, int X, int Y)
        {
            string fileExt = HotoUtils.GetFileExt(fileName); //文件扩展名,不含“.”

            if (!IsImage(fileExt))
            {
                return(false);
            }
            string newFileDir = HotoUtils.GetMapPath(newFileName.Substring(0, newFileName.LastIndexOf(@"/") + 1));

            //检查是否有该路径,没有则创建
            if (!Directory.Exists(newFileDir))
            {
                Directory.CreateDirectory(newFileDir);
            }
            try
            {
                string fileFullPath   = HotoUtils.GetMapPath(fileName);
                string toFileFullPath = HotoUtils.GetMapPath(newFileName);
                return(HotoThumbnail.MakeThumbnailImage(fileFullPath, toFileFullPath, 180, 180, cropWidth, cropHeight, X, Y));
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 判断管理员是否已经登录(解决Session超时问题)
 /// </summary>
 public bool IsAdminLogin()
 {
     //如果Session为Null
     if (Session[HotoKeys.SESSION_ADMIN_INFO] != null)
     {
         return(true);
     }
     else
     {
         //检查Cookies
         string adminname = HotoUtils.GetCookie("AdminName", "DTcms"); //解密用户名
         string adminpwd  = HotoUtils.GetCookie("AdminPwd", "DTcms");
         if (adminname != "" && adminpwd != "")
         {
             Hoto.BLL.manager   bll   = new Hoto.BLL.manager();
             Hoto.Model.manager model = bll.GetModel(adminname, adminpwd);
             if (model != null)
             {
                 Session[HotoKeys.SESSION_ADMIN_INFO] = model;
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 取得Access Token
        /// </summary>
        /// <param name="code">临时Authorization Code,官方提示10分钟过期</param>
        /// <param name="state">防止CSRF攻击,成功授权后回调时会原样带回</param>
        /// <returns>Dictionary</returns>
        public static JsonData get_access_token(string code, string state)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("kaixin");
            string       send_url = "https://api.kaixin001.com/oauth2/access_token?grant_type=authorization_code&code=" + code + "&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&state=" + state + "&redirect_uri=" + HotoUtils.UrlEncode(config.return_uri);
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                JsonData jd = JsonMapper.ToObject(result);
                if (jd.Count > 0)
                {
                    return(jd);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 判断用户是否已经登录(解决Session超时问题)
 /// </summary>
 public bool IsUserLogin()
 {
     //如果Session为Null
     if (HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] != null)
     {
         return(true);
     }
     else
     {
         //检查Cookies
         string username = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms"); //解密用户名
         string password = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms");
         if (username != "" && password != "")
         {
             Hoto.BLL.users   bll   = new Hoto.BLL.users();
             Hoto.Model.users model = bll.GetModel(username, password, 0);
             if (model != null)
             {
                 HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model;
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 获取登录用户自己的详细信息
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <param name="open_id">用户openid</param>
        /// <returns>Dictionary</returns>
        public static JsonData get_info(string access_token, string open_id)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("qq");
            string       send_url = "https://graph.qq.com/user/get_info?access_token=" + access_token + "&oauth_consumer_key=" + config.oauth_app_id + "&openid=" + open_id;
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                JsonData jd = JsonMapper.ToObject(result);
                if (jd.Count > 0)
                {
                    return(jd);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 批量删除节点
 /// </summary>
 public bool Remove(XmlNodeList xnList)
 {
     try
     {
         string      filePath = HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING);
         XmlDocument doc      = new XmlDocument();
         doc.Load(filePath);
         XmlNode xn = doc.SelectSingleNode("urls");
         foreach (XmlElement xe in xnList)
         {
             for (int i = xn.ChildNodes.Count - 1; i >= 0; i--)
             {
                 XmlElement xe2 = (XmlElement)xn.ChildNodes.Item(i);
                 if (xe2.Attributes["name"].Value.ToLower() == xe.Attributes["name"].Value.ToLower())
                 {
                     xn.RemoveChild(xe2);
                 }
             }
         }
         doc.Save(filePath);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// ²éÕÒ²»´æÔÚµÄͼƬ²¢É¾³ýÒÑɾ³ýµÄͼƬ¼°Êý¾Ý
        /// </summary>
        public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.article_albums> models, int article_id)
        {
            StringBuilder idList = new StringBuilder();

            if (models != null)
            {
                foreach (Model.article_albums modelt in models)
                {
                    if (modelt.id > 0)
                    {
                        idList.Append(modelt.id + ",");
                    }
                }
            }
            string        id_list = HotoUtils.DelLastChar(idList.ToString(), ",");
            StringBuilder strSql  = new StringBuilder();

            strSql.Append("select id,big_img,small_img from dt_article_albums where article_id=" + article_id);
            if (!string.IsNullOrEmpty(id_list))
            {
                strSql.Append(" and id not in(" + id_list + ")");
            }
            DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString());

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int rows = DbHelperSQL.ExecuteSql(conn, trans, "delete from dt_article_albums where id=" + dr["id"].ToString()); //ɾ³ýÊý¾Ý¿â
                if (rows > 0)
                {
                    HotoUtils.DeleteFile(dr["big_img"].ToString());   //ɾ³ýԭͼ
                    HotoUtils.DeleteFile(dr["small_img"].ToString()); //ɾ³ýËõÂÔͼ
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 导入节点
 /// </summary>
 public bool Import(XmlNodeList xnList)
 {
     try
     {
         string      filePath = HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING);
         XmlDocument doc      = new XmlDocument();
         doc.Load(filePath);
         XmlNode xn = doc.SelectSingleNode("urls");
         foreach (XmlElement xe in xnList)
         {
             if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite")
             {
                 if (xe.Attributes["name"] != null)
                 {
                     XmlNode n = doc.ImportNode(xe, true);
                     xn.AppendChild(n);
                 }
             }
         }
         doc.Save(filePath);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// 取得临时的Access Token
        /// </summary>
        /// <param name="code">临时Authorization Code,官方提示10分钟过期</param>
        /// <param name="state">防止CSRF攻击,成功授权后回调时会原样带回</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_access_token(string code, string state)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("qq");
            string       send_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&code=" + code + "&state=" + state + "&redirect_uri=" + HotoUtils.UrlEncode(config.return_uri);
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                string[] parm                   = result.Split('&');
                string   access_token           = parm[0].Split('=')[1]; //取得access_token
                string   expires_in             = parm[1].Split('=')[1]; //Access Token的有效期,单位为秒
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("access_token", access_token);
                dic.Add("expires_in", expires_in);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 查找不存在的文件并删除已删除的附件及数据
        /// </summary>
        public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.download_attach> models, int article_id)
        {
            StringBuilder idList = new StringBuilder();

            if (models != null)
            {
                foreach (Model.download_attach modelt in models)
                {
                    if (modelt.id > 0)
                    {
                        idList.Append(modelt.id + ",");
                    }
                }
            }
            string        id_list = HotoUtils.DelLastChar(idList.ToString(), ",");
            StringBuilder strSql  = new StringBuilder();

            strSql.Append("select id,file_path from dt_download_attach where article_id=" + article_id);
            if (!string.IsNullOrEmpty(id_list))
            {
                strSql.Append(" and id not in(" + id_list + ")");
            }
            DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString());

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int rows = DbHelperSQL.ExecuteSql(conn, trans, "delete from dt_download_attach where id=" + dr["id"].ToString()); //删除数据库
                if (rows > 0)
                {
                    HotoUtils.DeleteFile(dr["file_path"].ToString()); //删除文件
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 页面请求事件处理
        /// </summary>
        /// <param name="sender">事件的源</param>
        /// <param name="e">包含事件数据的 EventArgs</param>
        private void ReUrl_BeginRequest(object sender, EventArgs e)
        {
            HttpContext context     = ((HttpApplication)sender).Context;
            string      requestPath = context.Request.Path;                                                                                   //获得当前页面,包含目录
            string      requestPage = requestPath.Substring(requestPath.LastIndexOf("/"));                                                    //获得当前页面,不包含目录

            Hoto.Model.siteconfig siteConfig = new Hoto.BLL.siteconfig().loadConfig(HotoUtils.GetXmlMapPath(HotoKeys.FILE_SITE_XML_CONFING)); //获得站点配置信息

            bool isRewritePath = IsUrlRewrite(siteConfig.webpath, requestPath);                                                               //排除不需要URL重写的目录

            switch (siteConfig.staticstatus)
            {
            case 0:     //关闭重写
                if (isRewritePath && IsAspxFile(requestPath))
                {
                    context.RewritePath(siteConfig.webpath + HotoKeys.DIRECTORY_REWRITE_ASPX + "/" + requestPage);
                }
                break;

            case 1:     //伪URL重写
                if (isRewritePath)
                {
                    RewriteUrl(context, siteConfig.webpath, requestPath, requestPage);
                }
                break;

            case 2:     //全静态
                if (requestPath.ToLower().Equals("/index.aspx"))
                {
                    context.RewritePath(siteConfig.webpath + HotoKeys.DIRECTORY_REWRITE_HTML + "/index." + siteConfig.staticextension);
                }
                break;
            }
        }
Exemplo n.º 13
0
 //删除更新的旧文件
 public void DeleteFile(int id, string filePath)
 {
     Model.download_attach model = GetModel(id);
     if (model != null && model.file_path != filePath)
     {
         HotoUtils.DeleteFile(model.file_path);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// 取得节点配制信息
        /// </summary>
        public Model.url_rewrite GetInfo(string attrValue)
        {
            Model.url_rewrite model    = new Model.url_rewrite();
            string            filePath = HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING);
            XmlDocument       doc      = new XmlDocument();

            doc.Load(filePath);
            XmlNode     xn     = doc.SelectSingleNode("urls");
            XmlNodeList xnList = xn.ChildNodes;

            if (xnList.Count > 0)
            {
                foreach (XmlElement xe in xnList)
                {
                    if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower())
                    {
                        if (xe.Attributes["name"] != null)
                        {
                            model.name = xe.Attributes["name"].Value;
                        }
                        if (xe.Attributes["path"] != null)
                        {
                            model.path = xe.Attributes["path"].Value;
                        }
                        if (xe.Attributes["pattern"] != null)
                        {
                            model.pattern = xe.Attributes["pattern"].Value;
                        }
                        if (xe.Attributes["page"] != null)
                        {
                            model.page = xe.Attributes["page"].Value;
                        }
                        if (xe.Attributes["querystring"] != null)
                        {
                            model.querystring = xe.Attributes["querystring"].Value;
                        }
                        if (xe.Attributes["templet"] != null)
                        {
                            model.templet = xe.Attributes["templet"].Value;
                        }
                        if (xe.Attributes["channel"] != null)
                        {
                            model.channel = xe.Attributes["channel"].Value;
                        }
                        if (xe.Attributes["type"] != null)
                        {
                            model.type = xe.Attributes["type"].Value;
                        }
                        if (xe.Attributes["inherit"] != null)
                        {
                            model.inherit = xe.Attributes["inherit"].Value;
                        }
                        return(model);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 15
0
 /// <summary>
 /// 删除附件文件
 /// </summary>
 public void DeleteFile(List <Model.download_attach> models)
 {
     if (models != null)
     {
         foreach (Model.download_attach modelt in models)
         {
             HotoUtils.DeleteFile(modelt.file_path);
         }
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// 返回一个随机用户名
        /// </summary>
        public string GetRandomName(int length)
        {
            string temp = HotoUtils.Number(length, true);

            if (Exists(temp))
            {
                return(GetRandomName(length));
            }
            return(temp);
        }
Exemplo n.º 17
0
 /// <summary>
 /// ɾ³ýÏà²áͼƬ
 /// </summary>
 public void DeleteFile(List <Model.article_albums> models)
 {
     if (models != null)
     {
         foreach (Model.article_albums modelt in models)
         {
             HotoUtils.DeleteFile(modelt.big_img);
             HotoUtils.DeleteFile(modelt.small_img);
         }
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// 返回URL映射列表
        /// </summary>
        public Hashtable GetList()
        {
            Hashtable ht = HotoCacheHelper.Get <Hashtable>(HotoKeys.CACHE_SITE_URLS);

            if (ht == null)
            {
                HotoCacheHelper.Insert(HotoKeys.CACHE_SITE_URLS, dal.GetList(), HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING));
                ht = HotoCacheHelper.Get <Hashtable>(HotoKeys.CACHE_SITE_URLS);
            }
            return(ht);
        }
Exemplo n.º 19
0
 /// <summary>
 /// 增加节点
 /// </summary>
 public bool Add(Model.url_rewrite model)
 {
     try
     {
         string      filePath = HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING);
         XmlDocument doc      = new XmlDocument();
         doc.Load(filePath);
         XmlNode    xn = doc.SelectSingleNode("urls");
         XmlElement xe = doc.CreateElement("rewrite");
         if (!string.IsNullOrEmpty(model.name))
         {
             xe.SetAttribute("name", model.name);
         }
         if (!string.IsNullOrEmpty(model.path))
         {
             xe.SetAttribute("path", model.path);
         }
         if (!string.IsNullOrEmpty(model.pattern))
         {
             xe.SetAttribute("pattern", model.pattern);
         }
         if (!string.IsNullOrEmpty(model.page))
         {
             xe.SetAttribute("page", model.page);
         }
         if (!string.IsNullOrEmpty(model.querystring))
         {
             xe.SetAttribute("querystring", model.querystring);
         }
         if (!string.IsNullOrEmpty(model.templet))
         {
             xe.SetAttribute("templet", model.templet);
         }
         if (!string.IsNullOrEmpty(model.channel))
         {
             xe.SetAttribute("channel", model.channel.ToString());
         }
         if (!string.IsNullOrEmpty(model.type))
         {
             xe.SetAttribute("type", model.type);
         }
         if (!string.IsNullOrEmpty(model.inherit))
         {
             xe.SetAttribute("inherit", model.inherit);
         }
         xn.AppendChild(xe);
         doc.Save(filePath);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// 遍历站点目录,排除不需要重写的URL地址
        /// </summary>
        /// <param name="dirPath">站点安装目录,以“/”结尾</param>
        /// <param name="requestPath">获取的URL地址</param>
        /// <returns>布尔值</returns>
        private bool IsUrlRewrite(string dirPath, string requestPath)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(HotoUtils.GetMapPath(dirPath));

            foreach (DirectoryInfo dir in dirInfo.GetDirectories())
            {
                if (requestPath.ToLower().StartsWith(dirPath + dir.Name.ToLower() + "/"))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 21
0
 /// <summary>
 /// 移除购物车
 /// </summary>
 /// <param name="Key">主键 0为清理所有的购物车信息</param>
 public static void Clear(string Key)
 {
     if (Key == "0")//为0的时候清理全部购物车cookies
     {
         HotoUtils.WriteCookie(HotoKeys.COOKIE_SHOPPING_CART, "", -43200);
     }
     else
     {
         IDictionary <string, int> dic = GetCart();
         if (dic != null)
         {
             dic.Remove(Key);
             AddCookies(JsonMapper.ToJson(dic));
         }
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// 获取登录用户自己的基本资料
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <param name="open_id">用户openid</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_user_info(string access_token, string open_id)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("qq");
            string       send_url = "https://graph.qq.com/user/get_user_info?access_token=" + access_token + "&oauth_consumer_key=" + config.oauth_app_id + "&openid=" + open_id;
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            //反序列化JSON
            Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);

            return(dic);
        }
Exemplo n.º 23
0
 /// <summary>
 /// 获取OAuth配置信息
 /// </summary>
 /// <param name="oauth_name"></param>
 public static oauth_config get_config(string oauth_name)
 {
     //读取接口配置信息
     Model.app_oauth model = new BLL.app_oauth().GetModel(oauth_name);
     if (model != null)
     {
         //读取站点配置信息
         Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(HotoKeys.FILE_SITE_XML_CONFING);
         //赋值
         oauth_config config = new oauth_config();
         config.oauth_name    = model.api_path.Trim();
         config.oauth_app_id  = model.app_id.Trim();
         config.oauth_app_key = model.app_key.Trim();
         config.return_uri    = HotoUtils.DelLastChar(siteConfig.weburl, "/") + siteConfig.webpath + "api/oauth/" + model.api_path + "/return_url.aspx";
         return(config);
     }
     return(null);
 }
Exemplo n.º 24
0
        /// <summary>
        /// OnInit事件,检查用户是否已经登录
        /// </summary>
        void UserPage_Init(object sender, EventArgs e)
        {
            turl = HotoUtils.GetCookie(HotoKeys.COOKIE_URL_REFERRER);
            if (string.IsNullOrEmpty(turl) || turl == HttpContext.Current.Request.Url.ToString().ToLower())
            {
                turl = linkurl("usercenter", "index");
            }
            if (IsUserLogin())
            {
                //自动登录,跳转URL
                HttpContext.Current.Response.Redirect(turl);
                return;
            }
            //检查是否已授权
            if (HttpContext.Current.Session["oauth_name"] == null || HttpContext.Current.Session["oauth_access_token"] == null || HttpContext.Current.Session["oauth_openid"] == null)
            {
                HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,用户授权已过期,请重新登录!"));
                return;
            }
            Hoto.Model.user_oauth oauthModel = new Hoto.BLL.user_oauth().GetModel(HttpContext.Current.Session["oauth_name"].ToString(), HttpContext.Current.Session["oauth_openid"].ToString());
            if (oauthModel != null)
            {
                //检查用户是否存在
                Hoto.Model.users model = new Hoto.BLL.users().GetModel(oauthModel.user_name);
                if (model == null)
                {
                    HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,授权用户不存在或已被删除!"));
                    return;
                }

                //记住登录状态,防止Session提前过期
                HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model;
                HttpContext.Current.Session.Timeout = 45;
                HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms", model.user_name);
                HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms", model.password);
                //更新最新的Access Token
                oauthModel.oauth_access_token = HttpContext.Current.Session["oauth_access_token"].ToString();
                new Hoto.BLL.user_oauth().Update(oauthModel);
                //自动登录,跳转URL
                HttpContext.Current.Response.Redirect(turl);
                return;
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 获取登录用户自己的详细信息
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <returns>JsonData</returns>
        public static Dictionary <string, object> get_info(string access_token)
        {
            string send_url = "https://i.feixin.10086.cn/api/user.json?access_token=" + access_token;
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 26
0
        public static string tenpay_notify = ""; //支付完成后的回调处理页面;

        static TenpayUtil()
        {
            //读取XML配置信息
            string      fullPath = HotoUtils.GetMapPath("~/xmlconfig/tenpay.config");
            XmlDocument doc      = new XmlDocument();

            doc.Load(fullPath);
            XmlNode _bargainor_id  = doc.SelectSingleNode(@"Root/bargainor_id");
            XmlNode _tenpay_key    = doc.SelectSingleNode(@"Root/tenpay_key");
            XmlNode _tenpay_return = doc.SelectSingleNode(@"Root/tenpay_return");
            XmlNode _tenpay_notify = doc.SelectSingleNode(@"Root/tenpay_notify");

            //读取站点配置信息
            Model.siteconfig model = new BLL.siteconfig().loadConfig(HotoKeys.FILE_SITE_XML_CONFING);

            bargainor_id  = _bargainor_id.InnerText;
            tenpay_key    = _tenpay_key.InnerText;
            tenpay_return = HotoUtils.DelLastChar(model.weburl, "/") + _tenpay_return.InnerText;
            tenpay_notify = HotoUtils.DelLastChar(model.weburl, "/") + _tenpay_notify.InnerText;
        }
Exemplo n.º 27
0
        /// <summary>
        /// 取得用户openid
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_open_id(string access_token)
        {
            string send_url = "https://graph.qq.com/oauth2.0/me?access_token=" + access_token;
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            //取得文字出现
            int str_start = result.IndexOf('(') + 1;
            int str_last  = result.LastIndexOf(')') - 1;

            //取得JSON字符串
            result = result.Substring(str_start, (str_last - str_start));
            //反序列化JSON
            Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);

            return(dic);
        }
Exemplo n.º 28
0
        /// <summary>
        /// OnInit事件,检查用户是否已经登录
        /// </summary>
        void UserPage_Init(object sender, EventArgs e)
        {
            turl = linkurl("usercenter", "index");
            if (HttpContext.Current.Request.Url != null && HttpContext.Current.Request.UrlReferrer != null)
            {
                if (HttpContext.Current.Request.Url.ToString().ToLower() != HttpContext.Current.Request.UrlReferrer.ToString().ToLower())
                {
                    turl = HttpContext.Current.Request.UrlReferrer.ToString();
                }
            }
            HotoUtils.WriteCookie(HotoKeys.COOKIE_URL_REFERRER, turl); //记住上一页面

            Hoto.Model.users model = GetUserInfo();
            if (model != null)
            {
                //写入登录日志
                //new Hoto.BLL.user_login_log().Add(model.id, model.user_name, "自动登录", HotoRequest.GetIP());
                //自动登录,跳转URL
                HttpContext.Current.Response.Redirect(turl);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// 查询用户access_token的授权相关信息
        /// </summary>
        /// <param name="access_token">Access Token</param>
        /// <returns>Dictionary<T></returns>
        public static Dictionary <string, object> get_token_info(string access_token)
        {
            string send_url = "https://api.weibo.com/oauth2/get_token_info";
            string param    = "access_token=" + access_token;
            //发送并接受返回值
            string result = HotoUtils.HttpPost(send_url, param);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// 取得Access Token
        /// </summary>
        /// <param name="code">临时Authorization Code</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_access_token(string code)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("feixin");
            string       send_url = "https://i.feixin.10086.cn/oauth2/access_token?grant_type=authorization_code&code=" + code + "&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&redirect_uri=" + HotoUtils.UrlEncode(config.return_uri);
            //发送并接受返回值
            string result = HotoUtils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }