コード例 #1
0
ファイル: toolWS.asmx.cs プロジェクト: fbkc/toolWebsevice
        /// <summary>
        /// 写模板
        /// </summary>
        /// <param name="hInfo"></param>
        /// <param name="uInfo"></param>
        /// <param name="username"></param>
        /// <param name="hName"></param>
        /// <returns></returns>
        public static bool WriteFile(htmlInfo hInfo, cmUserInfo uInfo, string username, string hName)
        {
            //文件输出目录
            string path = HttpContext.Current.Server.MapPath("~/test/" + username + "/");

            // 读取模板文件
            string temp = HttpContext.Current.Server.MapPath("~/templates/DetailModel.html");//模版文件

            //string str = SiteTemplate();//读取模版页面html代码
            string str = "";

            using (StreamReader sr = new StreamReader(temp, Encoding.GetEncoding("gb2312")))
            {
                str = sr.ReadToEnd();
                sr.Close();
            }
            string htmlfilename = hName;//静态文件名

            // 替换内容
            str = str.Replace("companyName_Str", uInfo.companyName);
            if (hInfo.title.Length > 6)
            {
                str = str.Replace("keywords_Str", hInfo.title + "," + hInfo.title.Substring(0, 2) + "," + hInfo.title.Substring(2, 2) + "," + hInfo.title.Substring(4, 2));
            }
            else
            {
                str = str.Replace("keywords_Str", hInfo.title);
            }
            str = str.Replace("description_Str", hInfo.articlecontent.Substring(0, 80));
            str = str.Replace("host_Str", host);
            str = str.Replace("catid_Str", hInfo.columnId);
            str = str.Replace("Id_Str", hInfo.Id.ToString());
            str = str.Replace("title_Str", hInfo.title);
            str = str.Replace("addTime_Str", hInfo.addTime);

            str = str.Replace("pinpai_Str", hInfo.pinpai);
            str = str.Replace("price_Str", hInfo.price);
            str = str.Replace("qiding_Str", hInfo.smallCount);
            str = str.Replace("gonghuo_Str", hInfo.sumCount);
            str = str.Replace("xinghao_Str", hInfo.xinghao);
            str = str.Replace("city_Str", hInfo.city);
            str = str.Replace("unit_Str", hInfo.unit);

            str = str.Replace("titleImg_Str", hInfo.titleImg);
            str = str.Replace("content_Str", hInfo.articlecontent);
            str = str.Replace("username_Str", username);
            str = str.Replace("site_Str", hInfo.realmNameId);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            // 写文件
            using (StreamWriter sw = new StreamWriter(path + htmlfilename, true))
            {
                sw.Write(str);
                sw.Flush();
                sw.Close();
            }
            return(true);
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            string uname = context.Request["uname"];

            if (!string.IsNullOrEmpty(uname))
            {
                //公司/会员信息
                cmUserInfo uInfo = bll.GetUser(string.Format("where username='******'", uname));
                string     key   = "toolWebs"; //密钥
                string     iv    = "100dh888"; //偏移量
                //string key = NetHelper.GetMD5("100dh888");
                string userTel    = HttpUtility.UrlEncode(Tools.Encode(uInfo.modile, key, iv));
                string userModile = HttpUtility.UrlEncode(Tools.Encode(uInfo.modile, key, iv));
                var    data       = new
                {
                    userInfo = uInfo,
                    userTel,   //电话号码
                    userModile //手机
                };
                string html = SqlHelper.WriteTemplate(data, "RightFloatPage.html");
                context.Response.Write(html);
            }
        }
コード例 #3
0
        public string Post(string strJson)
        {
            BLL bll = new BLL();
            //需要做一个时间,每隔多长时间才允许访问一次
            string keyValue = NetHelper.GetMD5("liu" + "100dh888");
            string username = "";
            string url      = "";

            try
            {
                JObject jo = (JObject)JsonConvert.DeserializeObject(strJson);
                //return json.WriteJson(1, "dsasdasda", new { });
                string key = jo["key"].ToString();
                if (key != keyValue)
                {
                    return(json.WriteJson(0, "参数错误", new { }));
                }
                htmlPara hPara = new htmlPara();
                username     = jo["username"].ToString();
                hPara.userId = bll.GetUserId(username);//用户名
                //公司/会员信息
                cmUserInfo uInfo = bll.GetUser(string.Format("where username='******'", username));
                hPara.title = jo["title"].ToString();
                string cid = jo["catid"].ToString();
                if (string.IsNullOrEmpty(cid))
                {
                    return(json.WriteJson(0, "行业或栏目不能为空", new { }));
                }

                //命名规则:ip/目录/用户名/show_行业id+(五位数id)
                string showName = "show_" + cid + (bll.GetMaxId() + 1).ToString() + ".html";
                url                  = host + "/" + username + "/" + showName;
                hPara.titleURL       = url;
                hPara.articlecontent = HttpUtility.UrlDecode(jo["content"].ToString(), Encoding.UTF8); //内容,UrlDecode解码
                hPara.columnId       = cid;                                                            //行业id,行业新闻id=23
                hPara.pinpai         = jo["pinpai"].ToString();
                hPara.xinghao        = jo["xinghao"].ToString();
                hPara.price          = jo["price"].ToString();
                hPara.smallCount     = jo["qiding"].ToString();
                hPara.sumCount       = jo["gonghuo"].ToString();
                hPara.unit           = jo["unit"].ToString();
                hPara.city           = jo["city"].ToString();
                hPara.titleImg       = jo["thumb"].ToString();
                hPara.companyName    = uInfo.companyName;
                hPara.com_web        = uInfo.com_web;
                hPara.ten_qq         = uInfo.ten_qq;
                hPara.addTime        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                bll.AddHtml(hPara);                          //存入数据库
                WriteFile(hPara, uInfo, username, showName); //写模板
            }
            catch (Exception ex)
            {
                return(json.WriteJson(0, ex.ToString(), new { }));
            }
            return(json.WriteJson(1, "发布成功", new { url, username }));
        }
コード例 #4
0
ファイル: toolWS.asmx.cs プロジェクト: fbkc/toolWebsevice
        public string Login(string strJson)
        {
            DateTime s, n;

            s = DateTime.Now;
            n = DateTime.Now;
            try
            {
                JObject jo       = (JObject)JsonConvert.DeserializeObject(strJson);
                string  username = jo["username"].ToString();
                string  password = jo["password"].ToString();
                string  dosubmit = jo["dosubmit"].ToString();
                string  key      = jo["key"].ToString();

                string keyValue = NetHelper.GetMD5(username + "100dh888");
                if (dosubmit != "1")
                {
                    return(json.WriteJson(0, "参数错误", new { }));
                }
                if (key != keyValue)
                {
                    return(json.WriteJson(0, "值错误", new { }));
                }
                cmUserInfo userInfo = bll.GetUser(string.Format("where username='******'", username.Trim()));
                if (userInfo == null)
                {
                    return(json.WriteJson(0, "用户名不存在", new { }));
                }
                DateTime.TryParse(userInfo.expirationTime, out s);//到期时间
                if (userInfo.password != password)
                {
                    return(json.WriteJson(0, "密码错误", new { }));
                }
                if (userInfo.isStop)
                {
                    return(json.WriteJson(0, "该用户已被停用", new { }));
                }
                if (s <= n)
                {
                    return(json.WriteJson(0, "登录失败,账号已到期", new { }));
                }
                Context.Session["SoftUser"] = userInfo;
                uname = username;
                List <realmNameInfo> rList = bll.GetRealmList("");//获取所有域名
                if (rList.Count < 1)
                {
                    return(json.WriteJson(0, "登录失败,域名为空", new { }));
                }
                realList = rList;
                return(json.WriteJson(1, "登录成功", new { cmUser = userInfo, realmList = rList }));
            }
            catch (Exception ex)
            {
                return(json.WriteJson(0, ex.ToString(), new { }));
            }
        }
コード例 #5
0
ファイル: toolWS.asmx.cs プロジェクト: fbkc/toolWebsevice
        public string Upload(Image strJson)
        {
            string     pId      = Context.Request["productId"];
            cmUserInfo model    = (cmUserInfo)Context.Session["UserModel"];
            string     username = model.username.ToString();
            string     fileUrl  = "";

            try
            {
                HttpPostedFile _upfile = Context.Request.Files["file"];
                if (_upfile == null)
                {
                    throw new Exception("请先选择文件!");
                }
                else
                {
                    string fileName = _upfile.FileName;                                            /*获取文件名: C:\Documents and Settings\Administrator\桌面\123.jpg*/
                    string suffix   = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower(); /*获取后缀名并转为小写: jpg*/
                    int    bytes    = _upfile.ContentLength;                                       //获取文件的字节大小
                    if (!(suffix == "jpg" || suffix == "gif" || suffix == "png" || suffix == "jpeg"))
                    {
                        throw new Exception("只能上传JPE,GIF,PNG文件");
                    }
                    if (bytes > 1024 * 1024 * 2)
                    {
                        throw new Exception("图片最大只能传2M");
                    }
                    string newfileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string fileDir     = HttpContext.Current.Server.MapPath("~/upfiles/" + MyInfo.user + "/");
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }
                    //string phyPath = context.Request.PhysicalApplicationPath;
                    //string savePath = phyPath + virPath;
                    string saveDir = fileDir + newfileName + "." + suffix; //文件服务器存放路径
                    fileUrl = "/upfiles/" + username + "/" + newfileName + "." + suffix;
                    _upfile.SaveAs(saveDir);                               //保存图片
                    #region 存到sql图片库
                    imageInfo img = new imageInfo();
                    img.imageId   = newfileName;
                    img.imageURL  = fileUrl;
                    img.userId    = model.Id;
                    img.productId = int.Parse(pId);
                    bll.AddImg(img);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(json.WriteJson(0, ex.Message, new { }));
            }
            return(json.WriteJson(1, "上传成功", new { imgUrl = fileUrl }));
        }
コード例 #6
0
 /// <summary>
 /// 根据userId获取用户信息
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public string GetUserByUserId(HttpContext context)
 {
     try
     {
         string userId = context.Request["userId"];
         BLL    bll    = new BLL();
         //公司/会员信息
         cmUserInfo userInfo = bll.GetUser(string.Format("where Id='{0}'", userId));
         return(json.WriteJson(1, "成功", new { cmUser = userInfo }));
     }
     catch (Exception ex)
     {
         return(json.WriteJson(0, ex.ToString(), new { }));
     }
 }
コード例 #7
0
ファイル: BLL.cs プロジェクト: fbkc/fist_site
        /// <summary>
        /// 查找单个用户
        /// </summary>
        /// <param name="sqlstr"></param>
        /// <returns></returns>
        public cmUserInfo GetUser(string sqlstr)
        {
            DataTable dt = SqlHelper.ExecuteDataSet("select * from userInfo " + sqlstr).Tables[0];

            if (dt.Rows.Count < 1)
            {
                return(null);
            }
            DataRow    row      = dt.Rows[0];
            cmUserInfo userInfo = new cmUserInfo();

            userInfo.Id               = (int)row["Id"];
            userInfo.username         = (string)row["username"];
            userInfo.password         = (string)row["password"];
            userInfo.userType         = (int)row["userType"];
            userInfo.isStop           = (bool)row["isStop"];
            userInfo.gradeId          = (int)row["gradeId"];
            userInfo.canPubCount      = (int)row["canPubCount"];
            userInfo.realmNameInfo    = (string)row["realmNameInfo"];
            userInfo.expirationTime   = ((DateTime)row["expirationTime"]).ToString("yyyy-MM-dd HH:mm:ss");
            userInfo.endPubCount      = (int)row["endPubCount"];
            userInfo.endTodayPubCount = (int)row["endTodayPubCount"];
            userInfo.registerTime     = ((DateTime)row["registerTime"]).ToString("yyyy-MM-dd HH:mm:ss");
            userInfo.registerIP       = (string)row["registerIP"];
            userInfo.companyName      = (string)row["companyName"];
            userInfo.columnInfoId     = (int)row["columnInfoId"];
            userInfo.person           = (string)row["person"];
            userInfo.telephone        = (string)row["telephone"];
            userInfo.modile           = (string)row["modile"];
            userInfo.ten_qq           = (string)row["ten_qq"];
            userInfo.keyword          = (string)row["keyword"];
            userInfo.pinpai           = (string)row["pinpai"];
            userInfo.xinghao          = (string)row["xinghao"];
            userInfo.price            = (string)row["price"];
            userInfo.smallCount       = (string)row["smallCount"];
            userInfo.sumCount         = (string)row["sumCount"];
            userInfo.unit             = (string)row["unit"];
            userInfo.city             = (string)row["city"];
            userInfo.address          = (string)row["address"];
            userInfo.com_web          = (string)row["com_web"];
            userInfo.companyRemark    = (string)row["companyRemark"];
            userInfo.yewu             = (string)row["yewu"];
            userInfo.ziduan1          = (string)row["ziduan1"];
            return(userInfo);
        }
コード例 #8
0
ファイル: BLL.cs プロジェクト: fbkc/toolWebsevice
        /// <summary>
        /// 查找单个用户
        /// </summary>
        /// <param name="sqlstr"></param>
        /// <returns></returns>
        public cmUserInfo GetUser(string sqlstr)
        {
            DataTable dt = SqlHelper.ExecuteDataSet("select * from userInfo " + sqlstr).Tables[0];

            if (dt.Rows.Count < 1)
            {
                return(null);
            }
            DataRow    row      = dt.Rows[0];
            cmUserInfo userInfo = new cmUserInfo();

            userInfo.Id               = (int)SqlHelper.FromDBNull(row["Id"]);
            userInfo.username         = (string)SqlHelper.FromDBNull(row["username"]);
            userInfo.password         = (string)SqlHelper.FromDBNull(row["password"]);
            userInfo.userType         = (int)SqlHelper.FromDBNull(row["userType"]);
            userInfo.isStop           = (bool)SqlHelper.FromDBNull(row["isStop"]);
            userInfo.gradeId          = (int)SqlHelper.FromDBNull(row["gradeId"]);
            userInfo.canPubCount      = (int)SqlHelper.FromDBNull(row["canPubCount"]);
            userInfo.realmNameInfo    = (string)SqlHelper.FromDBNull(row["realmNameInfo"]);
            userInfo.expirationTime   = ((DateTime)SqlHelper.FromDBNull(row["expirationTime"])).ToString("yyyy-MM-dd HH:mm:ss");
            userInfo.endPubCount      = (int)SqlHelper.FromDBNull(row["endPubCount"]);
            userInfo.endTodayPubCount = (int)SqlHelper.FromDBNull(row["endTodayPubCount"]);
            userInfo.registerTime     = ((DateTime)SqlHelper.FromDBNull(row["registerTime"])).ToString("yyyy-MM-dd HH:mm:ss");
            userInfo.registerIP       = (string)SqlHelper.FromDBNull(row["registerIP"]);
            userInfo.companyName      = (string)SqlHelper.FromDBNull(row["companyName"]);
            userInfo.columnInfoId     = (int)SqlHelper.FromDBNull(row["columnInfoId"]);
            userInfo.person           = (string)SqlHelper.FromDBNull(row["person"]);
            userInfo.telephone        = (string)SqlHelper.FromDBNull(row["telephone"]);
            userInfo.modile           = (string)SqlHelper.FromDBNull(row["modile"]);
            userInfo.ten_qq           = (string)SqlHelper.FromDBNull(row["ten_qq"]);
            userInfo.address          = (string)SqlHelper.FromDBNull(row["address"]);
            userInfo.com_web          = (string)SqlHelper.FromDBNull(row["com_web"]);
            userInfo.companyRemark    = (string)SqlHelper.FromDBNull(row["companyRemark"]);
            userInfo.yewu             = (string)SqlHelper.FromDBNull(row["yewu"]);
            userInfo.beforePubTime    = ((DateTime)SqlHelper.FromDBNull(row["beforePubTime"])).ToString("yyyy-MM-dd HH:mm:ss");
            return(userInfo);
        }
コード例 #9
0
        /// <summary>
        /// 发布系统调用的post接口
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string ModuleHtml(HttpContext context)
        {
            string username = context.Request["username"];

            if (string.IsNullOrEmpty(username))
            {
                return(json.WriteJson(0, "用户名不能为空", new { }));
            }
            //key值判断
            string keyValue = NetHelper.GetMD5(username + "100dh888");
            string key      = context.Request["key"];

            if (key != keyValue)
            {
                return(json.WriteJson(0, "key值错误", new { }));
            }
            //根据username调用tool接口获取userInfo
            string     strjson  = NetHelper.HttpGet("http://tool.100dh.cn/UserHandler.ashx?action=GetUserByUsername&username="******"", Encoding.UTF8);//公共接口,调用user信息
            JObject    jo       = (JObject)JsonConvert.DeserializeObject(strjson);
            cmUserInfo userInfo = JsonConvert.DeserializeObject <cmUserInfo>(jo["detail"]["cmUser"].ToString());
            //时间间隔必须大于60秒
            DateTime dt  = DateTime.Now;
            DateTime sdt = Convert.ToDateTime(userInfo.beforePubTime);
            TimeSpan d3  = dt.Subtract(sdt);

            if (d3.TotalSeconds < 10)
            {
                return(json.WriteJson(0, "信息发布过快,请隔60秒再提交!", new { }));
            }
            //判断今日条数是否达到1000条
            if (userInfo.endTodayPubCount > 999)
            {
                return(json.WriteJson(0, "今日投稿已超过限制数!", new { }));
            }
            //判断所有条数是否发完
            if (!(userInfo.canPubCount > userInfo.endPubCount))
            {
                return(json.WriteJson(0, "会员套餐信息条数已发完!", new { }));
            }
            string url = "";

            try
            {
                htmlPara hInfo = new htmlPara();
                hInfo.userId = userInfo.Id.ToString();//用户名
                hInfo.title  = context.Request["title"];
                string cid = context.Request["catid"];
                if (string.IsNullOrEmpty(cid))
                {
                    return(json.WriteJson(0, "行业或栏目不能为空", new { }));
                }
                hInfo.columnId = cid;//行业id,行业新闻id=20
                string content = context.Request["content"];
                if (string.IsNullOrEmpty(content) || content.Length < 500)
                {
                    return(json.WriteJson(0, "文章不能少于500字,请丰富文章内容", new { }));
                }
                hInfo.articlecontent = content;
                //hInfo.articlecontent = HttpUtility.UrlDecode(jo["content"].ToString(), Encoding.UTF8);//内容,UrlDecode解码
                //命名规则:ip/目录/用户名/show_行业id+(五位数id)
                hInfo.titleURL    = hostUrl + "/" + username + "/ashow-" + cid + "-";
                hInfo.pinpai      = context.Request["pinpai"];
                hInfo.xinghao     = context.Request["xinghao"];
                hInfo.price       = context.Request["price"];
                hInfo.smallCount  = context.Request["qiding"];
                hInfo.sumCount    = context.Request["gonghuo"];
                hInfo.unit        = context.Request["unit"];
                hInfo.city        = context.Request["city"];
                hInfo.titleImg    = context.Request["thumb"];
                hInfo.addTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                hInfo.username    = username;
                hInfo.ten_qq      = userInfo.ten_qq;
                hInfo.companyName = userInfo.companyName;
                hInfo.com_web     = userInfo.com_web;
                //hInfo.realmNameId = "1";//发到哪个站
                bll.AddHtml(hInfo);//存入数据库
                url = bll.GetTitleUrl(userInfo.Id.ToString());
                //调用tool接口,更新userInfo已发条数等信息
                NetHelper.HttpGet("http://tool.100dh.cn/UserHandler.ashx?action=UpUserPubInformation&userId=" + userInfo.Id, "", Encoding.UTF8);//公共接口,调用user信息
            }
            catch (Exception ex)
            {
                return(json.WriteJson(0, ex.ToString(), new { }));
            }
            return(json.WriteJson(1, "发布成功", new { url, username }));
        }
コード例 #10
0
        public string ModuleHtml(HttpContext context)
        {
            //需要做一个时间,每隔多长时间才允许访问一次
            string keyValue = NetHelper.GetMD5("liu" + "100dh888");
            string url      = "";
            string key      = context.Request["key"];

            if (key != keyValue)
            {
                return(json.WriteJson(0, "key值错误", new { }));
            }
            string username = context.Request["username"];

            if (string.IsNullOrEmpty(username))
            {
                return(json.WriteJson(0, "用户名不能为空", new { }));
            }
            try
            {
                htmlPara hInfo = new htmlPara();
                hInfo.userId = bll.GetUserId(username);//用户名
                hInfo.title  = context.Request["title"];
                string cid = context.Request["catid"];
                if (string.IsNullOrEmpty(cid))
                {
                    return(json.WriteJson(0, "行业或栏目不能为空", new { }));
                }
                hInfo.columnId = cid;//行业id,行业新闻id=20
                string content = context.Request["content"];
                if (string.IsNullOrEmpty(content) || content.Length < 500)
                {
                    return(json.WriteJson(0, "文章不能少于500字,请丰富文章内容", new { }));
                }
                hInfo.articlecontent = content;
                //hInfo.articlecontent = HttpUtility.UrlDecode(jo["content"].ToString(), Encoding.UTF8);//内容,UrlDecode解码
                //命名规则:ip/目录/用户名/show_行业id+(五位数id)
                long htmlId = (bll.GetMaxId() + 1);
                hInfo.Id = htmlId;
                string showName = "show_" + cid + "_" + htmlId + ".html";
                url            = host + username + "/" + showName;
                hInfo.titleURL = url;
                //hInfo.titleURL = string.Format("handler/TestHandler.ashx?action=DetailPage&cId={0}&Id={1}", cid, htmlId);
                //url = host + hInfo.titleURL;
                hInfo.pinpai     = context.Request["pinpai"];
                hInfo.xinghao    = context.Request["xinghao"];
                hInfo.price      = context.Request["price"];
                hInfo.smallCount = context.Request["qiding"];
                hInfo.sumCount   = context.Request["gonghuo"];
                hInfo.unit       = context.Request["unit"];
                hInfo.city       = context.Request["city"];
                hInfo.titleImg   = context.Request["thumb"];
                hInfo.addTime    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                hInfo.username   = username;
                //公司 / 会员信息
                cmUserInfo uInfo = bll.GetUser(string.Format("where username='******'", username));
                hInfo.companyName = uInfo.companyName;
                hInfo.com_web     = uInfo.com_web;
                //hInfo.realmNameId = "1";//发到哪个站
                bll.AddHtml(hInfo);      //存入数据库

                string keyword     = ""; //关键词
                string description = ""; //描述
                if (hInfo.title.Length > 6)
                {
                    keyword = hInfo.title + "," + hInfo.title.Substring(0, 2) + "," + hInfo.title.Substring(2, 2) + "," + hInfo.title.Substring(4, 2);
                }
                else
                {
                    keyword = hInfo.title;
                }
                description = BLL.ReplaceHtmlTag(hInfo.articlecontent, 80);//产品简介
                var data = new
                {
                    title = hInfo.title + "_" + hInfo.companyName,
                    hInfo,
                    keyword,
                    description,
                    host,
                    columnName   = bll.GetColumns(" where Id=" + cid)[0].columnName,
                    ProductFloat = bll.GetProFloat(hInfo.userId),
                    NewsFloat    = bll.GetNewsFloat(hInfo.userId)
                };
                string html = SqlHelperCatalog.WriteTemplate(data, "DetailModel.html");
                WriteFile(html, showName, username);//写模板
            }
            catch (Exception ex)
            {
                return(json.WriteJson(0, ex.ToString(), new { }));
            }
            return(json.WriteJson(1, "发布成功", new { url, username }));
        }
コード例 #11
0
        public void ProcessRequest(HttpContext context)
        {
            BLL bll = new BLL();

            context.Response.ContentType = "image/png";
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            string pId      = context.Request["productId"];//产品Id
            string username = context.Request["username"];
            string key      = context.Request["key"];
            string keyValue = NetHelper.GetMD5(username + "100dh888");

            if (key != keyValue)
            {
                context.Response.Write(json.WriteJson(0, "key值错误", new { }));
            }
            cmUserInfo userInfo = bll.GetUser(string.Format("where username='******'", username.Trim()));

            if (userInfo == null)
            {
                context.Response.Write(json.WriteJson(0, "该用户不存在", new { }));
            }
            if (userInfo.isStop)
            {
                context.Response.Write(json.WriteJson(0, "该用户已被停用", new { }));
            }
            string fileUrl = "";

            try
            {
                HttpPostedFile _upfile = context.Request.Files["file"];
                if (_upfile == null)
                {
                    throw new Exception("请先选择文件!");
                }
                else
                {
                    string fileName = _upfile.FileName;                                            /*获取文件名: C:\Documents and Settings\Administrator\桌面\123.jpg*/
                    string suffix   = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower(); /*获取后缀名并转为小写: jpg*/
                    int    bytes    = _upfile.ContentLength;                                       //获取文件的字节大小
                    if (!(suffix == "jpg" || suffix == "gif" || suffix == "png" || suffix == "jpeg"))
                    {
                        throw new Exception("只能上传JPE,GIF,PNG文件");
                    }
                    if (bytes > 1024 * 1024 * 2)
                    {
                        throw new Exception("图片最大只能传2M");
                    }
                    string newfileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string fileDir     = HttpContext.Current.Server.MapPath("~/upfiles/" + username + "/");
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }
                    string saveDir = fileDir + newfileName + "." + suffix; //文件服务器存放路径
                    fileUrl = "/upfiles/" + username + "/" + newfileName + "." + suffix;
                    _upfile.SaveAs(saveDir);                               //保存图片
                    #region 存到sql图片库
                    imageInfo img = new imageInfo();
                    img.imageId   = newfileName;
                    img.imageURL  = fileUrl;
                    img.userId    = userInfo.Id;
                    img.productId = int.Parse(pId);
                    bll.AddImg(img);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.ToString());
            }
            context.Response.Write(json.WriteJson(1, "上传成功", new { imgUrl = "http://tool.100dh.cn" + fileUrl }));
        }