Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://sufeinet.com",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
                Allowautoredirect = false//默认为False就是不根据重定向自动跳转
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请求的Cookie
            string cookie = result.Cookie;

            //获取302跳转URl
            string redirectUrl = result.RedirectUrl;

            item = new HttpItem()
            {
                URL = redirectUrl,//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
                Cookie = cookie
            };
            //请求的返回值对象
            result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            cookie = result.Cookie;
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //===================================header======================================

            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
                //ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            string cookie = result.Cookie;
            //Header
            WebHeaderCollection header = result.Header;

            if (header != null)
            {
                string Vary = header["Vary"];
                string XCache = header["X-Cache"];
                string XServer = header["X-Server"];
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 发送短信
 /// </summary>
 /// <param name="receiver">短信接收人手机号码</param>
 /// <param name="content">短信内容</param>
 /// <returns>发送状态</returns>
 public static SMSCode SendMessage(string receiver, string content)
 {
     try
     {
         //创建Httphelper对象
         HttpHelper http = new HttpHelper();
         //创建Httphelper参数对象
         HttpItem item = new HttpItem()
         {
             URL = string.Format("{0}?phone={1}&content=验证码:{2}", SmsAPI, receiver, content),//URL     必需项    
             Method = "get",//可选项 默认为Get   
             ContentType = "text/plain"//返回类型    可选项有默认值 ,
         };
         item.Header.Add("apikey", Apikey);
         //请求的返回值对象
         HttpResult result = http.GetHtml(item);
         JObject jo = JObject.Parse(result.Html);
         JToken value = null;
         if (jo.TryGetValue("result", out value))
         {
             return EnumHelper.IntToEnum<SMSCode>(Convert.ToInt32(value.ToString()));
         }
         return SMSCode.SystemBusy;
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog("短信发送失败", ex);
         return SMSCode.Exception;
     }
 }
Ejemplo n.º 4
0
    /// <summary>
    /// 检查用户是否有效
    /// </summary>
    /// <param name="accesstoken">全局令牌</param>
    /// <param name="openusername">kinfarid</param>
    /// <param name="salt">盐值</param>
    private ReturnData Api_CheckUserValid(string weburl, string accesstoken, string openusername, string salt)
    {
        #region webapi验证
        PostData <string> postdata = new PostData <string>()
        {
            token = accesstoken, data = string.Format(@"{{""username"":""{0}"",""salt"":""{1}""}}", openusername, salt)
        };
        //赋值令牌
        postdata.token = accesstoken;
        //创建Httphelper对象
        CsharpHttpHelper.HttpHelper http = new CsharpHttpHelper.HttpHelper();
        //创建Httphelper参数对象
        CsharpHttpHelper.HttpItem item = new CsharpHttpHelper.HttpItem()
        {
            URL          = weburl,                                             //URL     必需项
            Method       = "post",                                             //URL     可选项 默认为Get
            ContentType  = "application/json;charset=urf-8",                   //返回类型    可选项有默认值 application/x-www-form-urlencoded 键值对
            PostDataType = CsharpHttpHelper.Enum.PostDataType.String,          //默认为字符串,同时支持Byte和文件方法
            PostEncoding = System.Text.Encoding.UTF8,                          //默认为Default,
            Postdata     = CsharpHttpHelper.HttpHelper.ObjectToJson(postdata), //Post要发送的数据
        };
        //请求的返回值对象
        CsharpHttpHelper.HttpResult result = http.GetHtml(item);
        //获取请请求的Html
        ReturnData rData = CsharpHttpHelper.HttpHelper.JsonToObject <ReturnData>(result.Html) as ReturnData;

        return(rData);

        #endregion
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
                ResultCookieType = ResultCookieType.CookieCollection
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请求的Cookie
            CookieCollection cookie = result.CookieCollection;

            // 第二次使用Cookie

            //创建Httphelper参数对象
            item = new HttpItem()
            {
                URL = "http://www.sufeinet.com/thread-9989-1-1.html",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
                CookieCollection = cookie,//把Cookie写入请求串中
                ResultCookieType = ResultCookieType.CookieCollection
            };
            //请求的返回值对象
            result = http.GetHtml(item);

            //获取Html
            string html = result.Html;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 从WebAPI中获取列表数据
        /// </summary>
        /// <returns></returns>
        private static DataTable GetGirdData(ExcelInfo info)
        {
            if (info.IsExportSelectData)
            {
                if (info.Data == null)
                {
                    info.Data = new DataTable();
                }
                return info.Data;
            }
            try
            {
                if (info.Type.Equals("post", StringComparison.OrdinalIgnoreCase))
                {
                    //创建Httphelper参数对象
                    HttpItem item = new HttpItem()
                    {
                        URL = info.Api,//URL     必需项
                        Method = "post",//可选项 默认为Get
                        ContentType = "application/json; charset=utf-8",//返回类型
                        Postdata = JsonConvert.SerializeObject(info.Condition)
                    };

                    //请求的返回值对象
                    HttpResult result = http.GetHtml(item);
                    var responseJson = JsonConvert.DeserializeObject<JsonBaseModel<DataTable>>(result.Html);
                    if (!responseJson.HasError && responseJson.Message != "logout")
                    {
                        return responseJson.Result;
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        dt.Columns.Add(info.ColumnInfoList[0].Field);
                        DataRow dr = dt.NewRow();
                        //接口报错
                        if (responseJson.HasError)
                        {
                            dr[0] = responseJson.Message;
                        }
                        if (responseJson.Message == "logout")
                        {
                            dr[0] = "登录超时,请刷新页面重试";
                        }
                        dt.Rows.Add(dr);
                        return dt;
                    }
                }
                else
                {
                    throw new ArgumentOutOfRangeException("不支持Get协议获取数据");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            string url = HttpHelper.URLEncode("http://member1.taobao.com/member/user_profile.jhtml?user_id=欧影点点");
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL =url,//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            string cookie = result.Cookie;

            string parameters = "a=123456&b=456789&c=456456";
            //得到一个参数集合
            NameValueCollection list = HttpHelper.GetNameValueCollection(parameters);

            string a = list["a"];
            string b = list["b"];
            string c = list["c"];

            Response.Write(string.Format("a={0}<br/>b={1}<br/>c={2}", a, b, c));

            list["a"] = list["a"] + "修改过我";

            list["c"] = list["c"] + "修改过我";
             a = list["a"];
             b = list["b"];
             c = list["c"];

             Response.Write(string.Format("<br/><br/>a={0}<br/>b={1}<br/>c={2}", a, b, c));

            //使用指定的编码对象对 URL 字符串进行编码。
            string URLEncode = HttpHelper.URLEncode(parameters);

            //使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串。
            string URLDecode = HttpHelper.URLDecode(URLEncode);

            Response.Write(string.Format("<br/><br/>URLEncode={0}<br/>URLDecode={1}<br/>", URLEncode, URLDecode));

            //使用指定的编码对象对 URL 字符串进行编码。
            URLEncode = HttpHelper.URLEncode(parameters, System.Text.Encoding.UTF8);

            //使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串。
            URLDecode = HttpHelper.URLDecode(URLEncode, System.Text.Encoding.UTF8);

            Response.Write(string.Format("<br/><br/>URLEncode={0}<br/>URLDecode={1}<br/>", URLEncode, URLDecode));

            string host = HttpHelper.GetUrlHost("http://www.sufeinet.com");

            string ip = HttpHelper.GetUrlIp("http://www.sufeinet.com");
        }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string u = HttpHelper.GetUrlIp("http://www.sufeinet.com");

            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com/template/veikei_dz_life_20130810_plus/images/logo.png?2014-06-06",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ResultType = ResultType.Byte
            };
            HttpResult result = http.GetHtml(item);

            Image img = HttpHelper.GetImage(result.ResultByte);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ////创建Httphelper对象
            //HttpHelper http = new HttpHelper();
            ////创建Httphelper参数对象
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://www.sufeinet.com",//URL     必需项
            //    Method = "get",//URL     可选项 默认为Get
            //    ContentType = "text/html",//返回类型    可选项有默认值
            //    CerPath = "D:\\123.cer"
            //};

            ////请求的返回值对象
            //HttpResult result = http.GetHtml(item);
            ////获取请请求的Html
            //string html = result.Html;
            ////获取请求的Cookie
            //string cookie = result.Cookie;

            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
            };
            item.ClentCertificates = new X509CertificateCollection();
            //配置多个证书在这里设置
            item.ClentCertificates.Add(new X509Certificate("d:\\123.cer","123456"));

            //配置多个证书在这里设置
            item.ClentCertificates.Add(new X509Certificate("d:\\456.cer"));

            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            string cookie = result.Cookie;
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://workroom.sufeinet.com/Hezuo.aspx",//URL     必需项
            };
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie;
            string urlll = result.RedirectUrl;

            Response.Write(result.Html);
            ////===================================状态码======================================

            ////创建Httphelper对象
            //HttpHelper http = new HttpHelper();
            ////创建Httphelper参数对象
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://www.sufeinet.com",//URL     必需项
            //    Method = "get",//URL     可选项 默认为Get
            //    ContentType = "text/html",//返回类型    可选项有默认值
            //    //ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            //};
            ////请求的返回值对象
            //HttpResult result = http.GetHtml(item);
            ////获取请请求的Html
            //string html = result.Html;
            ////获取请求的Cookie
            //string cookie = result.Cookie;

            ////状态码
            //HttpStatusCode code = result.StatusCode;
            ////状态描述
            //string Des = result.StatusDescription;
            //if (code == HttpStatusCode.OK)
            //{
            //    //状态为200
            //}
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 获取页面html内容
 /// </summary>
 /// <param name="url"></param>
 /// <returns></returns>
 private static string GetHTML(string url, string ProxyIp)
 {
     try
     {
         //创建Httphelper参数对象
         HttpItem item = new HttpItem()
         {
             URL = url,//URL     必需项
             Method = "get",//可选项 默认为Get
             ContentType = "text/html",//返回类型    可选项有默认值
             ProxyIp = ProxyIp
         };
         //请求的返回值对象
         HttpResult result = http.GetHtml(item);
         return result.Html;
     }
     catch (Exception ex)
     {
         TaskLog.IpProxyLogError.WriteLogE(string.Format("url:{0},ip:{1}获取HTML内容出错", url, ProxyIp), ex);
         return "<HTML></HTML>";
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 获取页面html内容
 /// </summary>
 /// <param name="url"></param>
 /// <returns></returns>
 private static string GetHTML(string url, string ProxyIp)
 {
     try
     {
         HttpHelper http = new HttpHelper();
         //创建Httphelper参数对象
         HttpItem item = new HttpItem()
         {
             URL = url,//URL     必需项
             Method = "get",//可选项 默认为Get
             ContentType = "text/html",//返回类型    可选项有默认值
             ProxyIp = ProxyIp
         };
         //请求的返回值对象
         HttpResult result = http.GetHtml(item);
         return result.Html;
     }
     catch (Exception)
     {
         return "<HTML></HTML>";
     }
 }
Ejemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ////创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Method = "get",//URL     可选项 默认为Get
                ContentType = "text/html",//返回类型    可选项有默认值
                Expect100Continue = false
                //ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            //string html = result.Html;

            //List<AItem> alist = HttpHelper.GetAList(html);

            ////创建Httphelper对象
            //HttpHelper http = new HttpHelper();
            ////创建Httphelper参数对象
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://www.sufeinet.com",//URL     必需项
            //    Method = "get",//URL     可选项 默认为Get
            //    ContentType = "text/html",//返回类型    可选项有默认值
            //    //ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            //};
            ////请求的返回值对象
            //HttpResult result = http.GetHtml(item);
            ////获取请请求的Html
            //string html = result.Html;

            //List<ImgItem> imglist = HttpHelper.GetImgList(html);

            ////创建Httphelper对象
            //HttpHelper http = new HttpHelper();
            ////创建Httphelper参数对象
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://www.sufeinet.com",//URL     必需项
            //    Method = "get",//URL     可选项 默认为Get
            //    ContentType = "text/html",//返回类型    可选项有默认值
            //    //ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            //};
            ////请求的返回值对象
            //HttpResult result = http.GetHtml(item);
            ////获取请请求的Html
            //string html = result.Html;

            //html = HttpHelper.ReplaceNewLine(html);
            //html = HttpHelper.StripHTML(html);

            string html = "苏飞论坛";
            string str = HttpHelper.GetBetweenHtml(html, "苏", "论坛");

            byte[] b = HttpHelper.StringToByte("苏飞");
            //可指定编码
            b = HttpHelper.StringToByte("苏飞", Encoding.UTF8);

            string s = HttpHelper.ByteToString(b);
            s = HttpHelper.ByteToString(b, Encoding.UTF8);

            string title = HttpHelper.GetHtmlTitle(html);
        }
Ejemplo n.º 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Method = "post",//URL     可选项 默认为Get
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
                PostDataType = PostDataType.String,//默认为字符串,同时支持Byte和文件方法
                PostEncoding = System.Text.Encoding.UTF8,//默认为Default,
                Postdata = "a=123&c=456&d=789",//Post要发送的数据
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            string cookie = result.Cookie;

            ////要Post的数据
            //string postdate = "a=123&c=456&d=789";
            ////将Post数据转为字节数组
            //byte[] bytedate = System.Text.Encoding.UTF8.GetBytes(postdate);
            ////创建Httphelper对象
            //HttpHelper http = new HttpHelper();
            ////创建Httphelper参数对象
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://www.sufeinet.com",//URL     必需项
            //    Method = "post",//URL     可选项 默认为Get
            //    ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            //    PostDataType = PostDataType.Byte,
            //    PostdataByte = bytedate
            //};
            ////请求的返回值对象
            //HttpResult result = http.GetHtml(item);
            ////获取请请求的Html
            //string html = result.Html;
            ////获取请求的Cookie
            //string cookie = result.Cookie;

            ////要Post的数据
            //string postfile = @"D:\postdata.txt";
            ////将Post数据转为字节数组

            ////创建Httphelper对象
            //HttpHelper http = new HttpHelper();
            ////创建Httphelper参数对象
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://www.sufeinet.com",//URL     必需项
            //    Method = "post",//URL     可选项 默认为Get
            //    ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            //    PostDataType = PostDataType.FilePath,
            //    Postdata = postfile
            //};
            ////请求的返回值对象
            //HttpResult result = http.GetHtml(item);
            ////获取请请求的Html
            //string html = result.Html;
            ////获取请求的Cookie
            //string cookie = result.Cookie;
        }
Ejemplo n.º 15
0
 private string HttpDownload(string url, out DateTime date)
 {
     //创建Httphelper参数对象
     HttpItem item = new HttpItem()
     {
         URL = string.Format("{0}?tk={1}", url, DateTime.Now.Ticks.ToString()),//URL     必需项
         Method = "get",//URL     可选项 默认为Get
         ContentType = "text/html",//返回类型    可选项有默认值
     };
     //请求的返回值对象
     HttpResult result = http.GetHtml(item);
     date = DateTime.Now;
     //获取请请求的Html
     return result.Html;
 }
Ejemplo n.º 16
0
 private static string GetHTML(string url, string ProxyIp)
 {
     //创建Httphelper参数对象
     HttpItem item = new HttpItem()
     {
         URL = url,//URL     必需项
         Method = "get",//可选项 默认为Get
         ContentType = "text/plain",//返回类型
         ProxyIp = ProxyIp
     };
     //请求的返回值对象
     HttpResult result = http.GetHtml(item);
     if (result.Html.Equals("无法连接到远程服务器"))
     {
         return null;
     }
     try
     {
         JObject jo = JObject.Parse(result.Html);
         JToken value = null;
         //查询结果状态
         if (jo.TryGetValue("status", out value))
         {
             if (value.ToString().Equals("200"))
             {
                 return result.Html;
             }
         }
         return null;
     }
     catch (Exception)
     {
         return null;
     }
 }
Ejemplo n.º 17
0
    public override string Process()
    {
        Hashtable ps     = Core.Utility.ParseJson(Data as string) as Hashtable;
        string    action = ps["Action"] as string;

        if (action == "GetMessages")
        {
            AccountInfo cu = ServerImpl.Instance.GetCurrentUser(Context);
            int         page = Convert.ToInt32(ps["Page"]), pagecount = 0;
            if (ps.ContainsKey("Time"))
            {
                if (Convert.ToInt32(ps["Time"]) != 5)
                {
                    DateTime now = DateTime.Now;
                    DateTime to  = new DateTime(now.Year, now.Month, now.Day);
                    to       = to.AddDays(1);
                    ps["To"] = to;
                    switch (Convert.ToInt32(ps["Time"]))
                    {
                    case 1:
                    {
                        ps["From"] = to.AddDays(-7);
                        break;
                    }

                    case 2:
                    {
                        ps["From"] = to.AddMonths(-1);
                        break;
                    }

                    case 3:
                    {
                        ps["From"] = to.AddMonths(-3);
                        break;
                    }

                    case 4:
                    {
                        ps["From"] = to.AddYears(-100);
                        break;
                    }
                    }
                }
            }
            List <Message> msgs = MessageImpl.Instance.GetMessages(
                cu.ID, Convert.ToInt32(ps["Peer"]),
                Convert.ToDateTime(ps["From"]),
                Convert.ToDateTime(ps["To"]),
                ref page, Convert.ToInt32(ps["PageSize"]), out pagecount,
                Convert.ToInt32(ps["MsgID"]),
                ps.ContainsKey("Content") ? Convert.ToString(ps["Content"]) : ""
                );
            return(Utility.RenderHashJson(
                       "Result", true,
                       "Messages", msgs,
                       "Page", page,
                       "PageCount", pagecount
                       ));
        }
        else if (action == "GetGroupMembers")
        {
            int         groupId                = Convert.ToInt32(ps["ID"]);
            AccountInfo groupInfo              = AccountImpl.Instance.GetUserInfo(groupId);
            AccountInfo creatorInfo            = AccountImpl.Instance.GetUserInfo(groupInfo.Creator);
            List <AccountInfo.Details> members = new List <AccountInfo.Details>();
            Hashtable managers = new Hashtable();
            if (groupInfo.SubType == 3)
            {
                foreach (AccountInfo info in MessageImpl.Instance.GetChatRoomUsers(groupInfo.ID))
                {
                    members.Add(info.DetailsJson);
                }
            }
            else
            {
                foreach (int member in groupInfo.Friends)
                {
                    members.Add(AccountImpl.Instance.GetUserInfo(member).DetailsJson);
                }
                foreach (int member in groupInfo.GetGroupManagers())
                {
                    AccountInfo u = AccountImpl.Instance.GetUserInfo(member);
                    if (u.ID != creatorInfo.ID)
                    {
                        managers[u.ID] = u.DetailsJson;
                    }
                }
            }
            return(Utility.RenderHashJson(
                       "Result", true,
                       "Members", members,
                       "Managers", managers,
                       "GroupInfo", groupInfo,
                       "GroupCreator", creatorInfo.DetailsJson
                       ));
        }
        else if (action == "Login")
        {
            String      sessionId    = Guid.NewGuid().ToString().ToUpper();
            AccountInfo current_user = null;
            if (!ps.ContainsKey("User"))
            {
                current_user = ServerImpl.Instance.GetCurrentUser(Context);
                if (current_user != null && !current_user.IsTemp)
                {
                    Core.ServerImpl.Instance.Login(sessionId, Context, current_user.ID, Convert.ToBoolean(ps["ClientMode"]), null);
                }
                else
                {
                    current_user = null;
                }
            }
            else
            {
                string token = ps["Token"].ToString();
                if (string.IsNullOrWhiteSpace(token))
                {
#if DEBUG
                    if (true)
#else
                    if (Core.AccountImpl.Instance.Validate(name, ps["Password"].ToString()))
#endif
                    {
                        int         id        = AccountImpl.Instance.GetUserID(name);
                        AccountInfo user_info = AccountImpl.Instance.GetUserInfo(id);
                        if (user_info == null)
                        {
                            throw new Exception("用户不存在或密码错误!");
                        }
                        Core.ServerImpl.Instance.Login(sessionId, Context, user_info.ID, Convert.ToBoolean(ps["ClientMode"]), null);
                        current_user = AccountImpl.Instance.GetUserInfo(id);
                    }
                    else
                    {
                        throw new Exception("用户不存在或密码错误!");
                    }
                }
                else
                {
                    string webapi       = System.Configuration.ConfigurationManager.AppSettings["webapi"].ToString();
                    string appid        = System.Configuration.ConfigurationManager.AppSettings["appid"].ToString();
                    string appsecret    = System.Configuration.ConfigurationManager.AppSettings["appsecret"].ToString();
                    string temptoken    = token;
                    string openusername = "";

                    #region webapi验证
                    PostData <string> postdata = new PostData <string>()
                    {
                        token = temptoken, appid = appid, appsecret = appsecret, data = "{}"
                    };
                    //赋值令牌
                    postdata.token = temptoken;
                    //创建Httphelper对象
                    CsharpHttpHelper.HttpHelper http = new CsharpHttpHelper.HttpHelper();
                    //创建Httphelper参数对象
                    CsharpHttpHelper.HttpItem item = new CsharpHttpHelper.HttpItem()
                    {
                        URL          = webapi + "/api/oath/Account/GetAccessToken",        //URL     必需项
                        Method       = "post",                                             //URL     可选项 默认为Get
                        ContentType  = "application/json;charset=urf-8",                   //返回类型    可选项有默认值 application/x-www-form-urlencoded 键值对
                        PostDataType = CsharpHttpHelper.Enum.PostDataType.String,          //默认为字符串,同时支持Byte和文件方法
                        PostEncoding = System.Text.Encoding.UTF8,                          //默认为Default,
                        Postdata     = CsharpHttpHelper.HttpHelper.ObjectToJson(postdata), //Post要发送的数据
                    };
                    //请求的返回值对象
                    CsharpHttpHelper.HttpResult result = http.GetHtml(item);
                    //获取请请求的Html
                    var rData = CsharpHttpHelper.HttpHelper.JsonToObject <ReturnData>(result.Html) as ReturnData;
                    #endregion

                    if (rData.Status == 1)
                    {
                        //成功
                        var so = CsharpHttpHelper.HttpHelper.JsonToObject <Dictionary <string, object> >(rData.Data.ToString()) as Dictionary <string, object>;
                        if (so != null && so.Count > 0)
                        {
                            int userid    = 0;
                            var name_salt = so["UserID"].ToString();  //用户名和盐值
                            temptoken = so["AccessToken"].ToString(); //全局令牌
                            string[] arr = name_salt.Split('♂');
                            if (arr.Length == 2)
                            {
                                openusername = arr[0];
                                var        salt      = arr[1];
                                ReturnData rDataUser = Api_CheckUserValid(webapi + "api/CMS/Login/CheckUserValid", temptoken, openusername, salt);
                                if (rDataUser != null)
                                {
                                    if (rDataUser.Status == 1)//成功
                                    {
                                        userid = AccountImpl.Instance.GetUserByOpenID(openusername);
                                        if (userid == 0)
                                        {
                                            var rUser = CsharpHttpHelper.HttpHelper.JsonToObject <Dictionary <string, object> >(rDataUser.Data.ToString()) as Dictionary <string, object>;
                                            if (so != null && so.Count > 0)
                                            {
                                                var user_name = rUser["user_name"].ToString();
                                                var nick_name = rUser["nick_name"].ToString();
                                                var salt1     = rUser["salt"].ToString();
                                                var telphone  = rUser["telphone"].ToString();
                                                var email     = rUser["email"].ToString();

                                                userid = AccountImpl.Instance.CreateUser("kf" + user_name, nick_name, user_name + salt1, email, 0, 0, user_name);
                                            }
                                            else
                                            {
                                                throw new Exception(rDataUser.Message);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("无效的关联信息!" + rDataUser.Message + rDataUser.Data ?? "");
                                    }
                                }
                            }
                            AccountInfo user_info = AccountImpl.Instance.GetUserInfo(userid);
                            if (user_info == null)
                            {
                                throw new Exception("用户不存在或密码错误!");
                            }
                            Core.ServerImpl.Instance.Login(sessionId, Context, user_info.ID, Convert.ToBoolean(ps["ClientMode"]), null);
                            current_user = AccountImpl.Instance.GetUserInfo(userid);
                        }
                        else
                        {
                            throw new Exception("无效的token!");
                        }
                    }
                }

                int group_id = 0;

                if (current_user != null && ps.ContainsKey("Join"))
                {
                    string groupName = ps["Join"] as string;
                    group_id = AccountImpl.Instance.GetUserID(groupName);
                    AccountInfo peerInfo = AccountImpl.Instance.GetUserInfo(group_id);
                    if (peerInfo != null)
                    {
                        if (peerInfo.Type == 1 && !peerInfo.ContainsMember(current_user.ID))
                        {
                            AccountImpl.Instance.AddFriend(current_user.ID, peerInfo.ID);
                            SessionManagement.Instance.SendToGroupMembers(peerInfo.ID, "GLOBAL:ACCOUNTINFO_CHANGED", Utility.RenderHashJson("Details", peerInfo.DetailsJson));
                        }
                        else if (peerInfo.Type == 0 && !peerInfo.ContainsFriend(current_user.ID))
                        {
                            AccountImpl.Instance.AddFriend(current_user.ID, peerInfo.ID);
                        }
                    }
                }

                if (current_user == null)
                {
                    return(Utility.RenderHashJson(
                               "Result", true,
                               "IsLogin", false
                               ));
                }
                else
                {
                    if (current_user.IsTemp && ps.ContainsKey("EmbedCode") && Convert.ToInt32(ps["EmbedCode"]) != 0)
                    {
                        System.Data.DataRow row           = AccountImpl.Instance.GetEmbedCode(Convert.ToInt32(ps["EmbedCode"]));
                        string                embedConfig = row["EmbedConfig"].ToString();
                        Hashtable             data        = Utility.ParseJson(embedConfig) as Hashtable;
                        System.Data.DataTable dt          = AccountImpl.Instance.GetServiceEmbedData(data["Users"].ToString());
                        Hashtable             users       = new Hashtable();
                        foreach (DataRow user_row in dt.Rows)
                        {
                            AccountInfo info = AccountImpl.Instance.GetUserInfo(Convert.ToInt32(user_row["ID"]));
                            users[info.ID] = info.DetailsJson;
                        }
                        return(Utility.RenderHashJson(
                                   "Result", true,
                                   "IsLogin", true,
                                   "UserInfo", current_user.DetailsJson,
                                   "SessionID", sessionId,
                                   "JoinGroup", group_id,
                                   "CompanyInfo", ServerImpl.Instance.CommonStorageImpl.GetCompanyInfo(),
                                   "CSDetails", dt.Rows,
                                   "CSUsers", users
                                   ));
                    }
                    else
                    {
                        return(Utility.RenderHashJson(
                                   "Result", true,
                                   "IsLogin", true,
                                   "UserInfo", current_user.DetailsJson,
                                   "SessionID", sessionId,
                                   "JoinGroup", group_id
                                   ));
                    }
                }
            }
        }
        else if (action == "CreateTempGroup")
        {
            AccountInfo cu           = ServerImpl.Instance.GetCurrentUser(Context);
            int         id           = AccountImpl.Instance.CreateTempGroup(AccountImpl.AdminstratorID, ps["Members"].ToString() + "," + cu.ID.ToString());
            AccountInfo info         = AccountImpl.Instance.GetUserInfo(id);
            List <int>  notify_users = new List <int>();
            foreach (int friendid in info.Friends)
            {
                if (cu.ID != friendid && cu.ID != 2)
                {
                    notify_users.Add(friendid);
                }
            }
            SessionManagement.Instance.SendToMultiUsers(notify_users.ToArray(), "GLOBAL:CREATE_TEMP_GROUP", Utility.RenderHashJson("GroupInfo", info.DetailsJson));
            return(Utility.RenderHashJson("GroupInfo", info.DetailsJson));
        }
        else if (action == "ExitTempGroup")
        {
            AccountInfo cu        = ServerImpl.Instance.GetCurrentUser(Context);
            AccountInfo groupInfo = AccountImpl.Instance.GetUserInfo(Convert.ToInt32(ps["GroupID"]));
            int[]       members   = groupInfo.Friends;

            AccountImpl.Instance.RemoveFromGroup(
                ServerImpl.Instance.GetCurrentUser(Context).ID,
                groupInfo.ID
                );
            if (groupInfo.Friends.Length == 1)
            {
                AccountImpl.Instance.DeleteGroup(groupInfo.ID, groupInfo.Creator);
            }
            foreach (int memberid in members)
            {
                if (memberid != AccountImpl.AdminstratorID && SessionManagement.Instance.IsOnline(memberid))
                {
                    SessionManagement.Instance.Send(
                        memberid, "GLOBAL:EXIT_TEMP_GROUP",
                        Utility.RenderHashJson("User", cu, "GroupID", groupInfo.ID, "Group", groupInfo.DetailsJson)
                        );
                }
            }
            return(Utility.RenderHashJson("Result", true, "Group", groupInfo));
        }
        else if (action == "AddToTempGroup")
        {
            AccountInfo        groupInfo = AccountImpl.Instance.GetUserInfo(Convert.ToInt32(ps["GroupID"]));
            List <AccountInfo> users     = new List <AccountInfo>();
            foreach (string id in ps["IDS"].ToString().Split(new char[] { ',' }))
            {
                AccountInfo user = AccountImpl.Instance.GetUserInfo(Convert.ToInt32(id));
                if (!groupInfo.ContainsMember(user.ID))
                {
                    users.Add(user);
                }
            }
            if (users.Count > 0)
            {
                AccountImpl.Instance.AddUsersToGroup(Utility.ParseIntArray(ps["IDS"].ToString()), groupInfo.ID);
                var notify_data = Utility.RenderHashJson("GroupID", groupInfo.ID, "GroupInfo", groupInfo, "Users", users);
                foreach (int friendid in groupInfo.Friends)
                {
                    if (friendid != 2 && SessionManagement.Instance.IsOnline(friendid))
                    {
                        SessionManagement.Instance.Send(friendid, "GLOBAL:ADD_TEMP_GROUP", notify_data);
                    }
                }
            }

            List <int> notify_users = new List <int>();
            foreach (AccountInfo u in users)
            {
                notify_users.Add(u.ID);
            }
            SessionManagement.Instance.NotifyResetListCache(notify_users.ToArray(), false, false, new AccountInfo[] { groupInfo });
            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "GetMultiUsersInfo")
        {
            Hashtable infos = new Hashtable();
            if (Convert.ToBoolean(ps["ByName"]))
            {
                foreach (string name in ps["Data"].ToString().Split(new char[] { ',' }))
                {
                    int id = AccountImpl.Instance.GetUserID(name);
                    infos[name] = AccountImpl.Instance.GetUserInfo(id).DetailsJson;
                }
            }
            else
            {
                foreach (string id in ps["Data"].ToString().Split(new char[] { ',' }))
                {
                    infos[id] = AccountImpl.Instance.GetUserInfo(Convert.ToInt32(id)).DetailsJson;
                }
            }
            return(Utility.RenderHashJson("Infos", infos));
        }
        else if (action == "GetMessageRecordUsers")
        {
            AccountInfo cu = ServerImpl.Instance.GetCurrentUser(Context);
            DataTable   dt = MessageImpl.Instance.GetMessageRecordUsers(cu.ID);
            return(Utility.RenderHashJson("Users", dt.Rows));
        }
        else if (action == "NewComment")
        {
            ServerImpl.Instance.CommonStorageImpl.NewComment(
                UserID,
                Convert.ToInt32(ps["ReceiverID"]),
                ps["Content"] as string,
                ps["Tel"] as string,
                ps["Mail"] as string,
                ps["Name"] as string
                );

            AccountImpl.Instance.RefreshUserInfo(UserID);

            return(Utility.RenderHashJson(
                       "Result", true
                       ));
        }
        else if (action == "GetUnreadComment")
        {
            AccountInfo info      = AccountImpl.Instance.GetUserInfo(UserID);
            DataTable   dtComment = ServerImpl.Instance.CommonStorageImpl.GetUnreadComment(info.IsAdmin ? 0 : info.ID, 0);
            return(Utility.RenderHashJson("Comments", dtComment.Rows));
        }
        else if (action == "HasUnreadComment")
        {
            AccountInfo info  = AccountImpl.Instance.GetUserInfo(UserID);
            int         count = ServerImpl.Instance.CommonStorageImpl.HasUnreadComment(info.ID);
            return(Utility.RenderHashJson("Count", count));
        }
        else if (action == "ReLogin")
        {
            SessionManagement.Instance.NewSession(UserID, ps["SessionID"].ToString());

            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "MarkStatus")
        {
            AccountInfo cu = ServerImpl.Instance.GetCurrentUser(Context);
            SessionManagement.Instance.MarkStatus(cu.ID, ps["Status"].ToString());
            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "SendAddFriendRequest")
        {
            string peerName = ps["Peer"].ToString();
            int    peerId   = AccountImpl.Instance.GetUserID(peerName);

            if (peerId == UserID)
            {
                throw new Exception("不能添加自己为好友!");
            }

            AccountInfo peerInfo    = AccountImpl.Instance.GetUserInfo(peerId);
            AccountInfo currentUser = AccountImpl.Instance.GetUserInfo(UserID);

            if (peerInfo == null || (peerInfo.Type == 1 && peerInfo.SubType == 1))
            {
                throw new Exception(String.Format("用户(或群组) \"{0}\" 不存在!", peerName));
            }

            if (peerInfo.Type == 0)
            {
                AccountInfo cu = currentUser;
                if ((peerInfo.SubType == 1 && cu.SubType == 1) || currentUser.ContainsFriend(peerInfo.ID))
                {
                    throw new Exception(String.Format("用户 \"{0}({1})\" 已经是您的好友!", peerInfo.Nickname, peerName));
                }

                MessageImpl.Instance.NewMessage(
                    peerInfo.ID, AccountImpl.AdminstratorID,
                    Utility.RenderHashJson("Type", "AddFriendRequest", "Peer", currentUser, "Info", ps["Info"] as string),
                    null, false
                    );
            }
            else
            {
                if (currentUser.ContainsFriend(peerInfo.ID))
                {
                    throw new Exception(String.Format("您已加入群 \"{0}({1})\"!", peerInfo.Nickname, peerName));
                }

                if (peerInfo.Creator != AccountImpl.AdminID)
                {
                    MessageImpl.Instance.NewMessage(
                        peerInfo.Creator, AccountImpl.AdminstratorID,
                        Utility.RenderHashJson(
                            "Type", "AddGroupRequest",
                            "User", currentUser,
                            "Group", peerInfo,
                            "Info", ps["Info"] as string
                            ),
                        null, false
                        );
                }
            }

            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "RemoveFromGroup")
        {
            int user  = Convert.ToInt32(ps["User"]);
            int group = Convert.ToInt32(ps["Group"]);

            AccountInfo cu        = ServerImpl.Instance.GetCurrentUser(Context);
            AccountInfo groupInfo = AccountImpl.Instance.GetUserInfo(group);
            AccountInfo userInfo  = AccountImpl.Instance.GetUserInfo(user);

            AccountImpl.Instance.RemoveFromGroup(user, group);

            SessionManagement.Instance.SendToGroupMembers(group, "GLOBAL:REMOVE_FROM_GROUP", Utility.RenderHashJson("GroupID", groupInfo.ID, "User", userInfo));
            SessionManagement.Instance.Send(user, "GLOBAL:REMOVE_COMM_FRIEND", Utility.RenderHashJson("CommFriend", groupInfo.DetailsJson));

            string content = Utility.RenderHashJson(
                "Type", "ExitGroupNotify",
                "User", userInfo,
                "Group", groupInfo
                );
            MessageImpl.Instance.NewMessage(groupInfo.ID, AccountImpl.AdminstratorID, content, null, false);

            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "AddFriend")
        {
            String peerName = ps["Peer"].ToString();
            int    peerId   = AccountImpl.Instance.GetUserID(peerName);

            AccountInfo peerInfo    = AccountImpl.Instance.GetUserInfo(peerId);
            AccountInfo currentUser = AccountImpl.Instance.GetUserInfo(UserID);

            if (!currentUser.ContainsFriend(peerInfo.ID))
            {
                AccountImpl.Instance.AddFriend(UserID, peerInfo.ID);

                string content = Utility.RenderHashJson(
                    "Type", "AddFriendNotify",
                    "User", currentUser,
                    "Peer", peerInfo,
                    "Info", ps["Info"] as string
                    );

                MessageImpl.Instance.NewMessage(peerInfo.ID, AccountImpl.AdminstratorID, content, null, false);
                MessageImpl.Instance.NewMessage(UserID, AccountImpl.AdminstratorID, content, null, false);

                SessionManagement.Instance.Send(peerInfo.ID, "GLOBAL:ADD_COMM_FRIEND", Utility.RenderHashJson("CommFriend", currentUser.DetailsJson));
                SessionManagement.Instance.Send(UserID, "GLOBAL:ADD_COMM_FRIEND", Utility.RenderHashJson("CommFriend", peerInfo.DetailsJson));
            }
            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "AddToGroup")
        {
            int         user      = Convert.ToInt32(ps["User"]);
            int         group     = Convert.ToInt32(ps["Group"]);
            AccountInfo userInfo  = AccountImpl.Instance.GetUserInfo(user);
            AccountInfo groupInfo = AccountImpl.Instance.GetUserInfo(group);

            AccountImpl.Instance.AddFriend(user, group);

            SessionManagement.Instance.SendToGroupMembers(group, "GLOBAL:ADD_TO_GROUP", Utility.RenderHashJson("GroupID", group, "User", userInfo.DetailsJson));
            SessionManagement.Instance.Send(user, "GLOBAL:ADD_COMM_FRIEND", Utility.RenderHashJson("CommFriend", groupInfo.DetailsJson));

            string content = Utility.RenderHashJson(
                "Type", "AddToGroupNotify",
                "User", AccountImpl.Instance.GetUserInfo(user),
                "Group", AccountImpl.Instance.GetUserInfo(group)
                );
            MessageImpl.Instance.NewMessage(groupInfo.ID, AccountImpl.AdminstratorID, content, null, false);

            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "Register")
        {
            int id = AccountImpl.Instance.CreateUser(
                ps["Name"].ToString(),
                ps["Nickname"].ToString(),
                ps["Password"].ToString(),
                ps["EMail"].ToString(),
                -1,
                0,
                ""
                );

            AccountInfo newUser = AccountImpl.Instance.GetUserInfo(id);
            Custom.CustomServerImpl.AfterCreateUser(ServerImpl.Instance, AccountImpl.Instance, SessionManagement.Instance, newUser);

            return(Utility.RenderHashJson("Info", newUser));
        }
        else if (action == "RemoveSession")
        {
            AccountInfo cu = ServerImpl.Instance.GetCurrentUser(Context);
            if (cu != null)
            {
                string sessionId1 = ps["SessionID"].ToString();
                SessionManagement.Instance.RemoveSession(cu.ID, sessionId1);
                string data = Utility.RenderHashJson(
                    "User", cu.ID,
                    "State", SessionManagement.Instance.IsOnline(cu.ID) ? "Online" : "Offline",
                    "Details", cu.DetailsJson
                    );
                SessionManagement.Instance.Send("UserStateChanged", data);
            }
            return(Utility.RenderHashJson("Result", true));
        }
        else if (action == "CreateTempUser")
        {
            String password = Guid.NewGuid().ToString().Replace("-", "").ToUpper();

#if DEBUG
            string ip = "117.136.10.171";
#else
            string ip = Context.Request.ServerVariables["REMOTE_ADDR"];
#endif

            int         id    = AccountImpl.Instance.CreateTempUser(ip);
            AccountInfo cu    = AccountImpl.Instance.GetUserInfo(id);
            Hashtable   items = new Hashtable();
            items["ResetTempUserPassword"] = password;
            AccountImpl.Instance.UpdateUserInfo(cu.ID, items);

            return(Utility.RenderHashJson("Info", cu.DetailsJson, "Password", password));
        }

        throw new NotImplementedException(String.Format("Command \"{0}\" isn't implemented", action));
    }