Exemplo n.º 1
0
        public Entity.BaseResult Post()
        {
            Entity.BaseResult result = new Entity.BaseResult();
            try
            {
                string   openid      = Request.Form["openid"];
                string   imageid     = Request.Form["imageid"];
                string   filecontent = Request.Form["file"];
                string[] filess      = filecontent.Split(",");
                // logger.LogError("wxk: "+filecontent);
                byte[] bit = Convert.FromBase64String(filess[1]);

                string filePath = hostingEnv.WebRootPath;
                // var files = Request.Form.Files;
                string filename = $@"\Files\Pictures\";
                //if (files.Count > 0)
                //{
                //var file = files[0];
                //创建文件夹
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                string oldfilext = ".png";
                //创建文件名称并写入文件
                filename += Guid.NewGuid().ToString() + oldfilext;
                using (FileStream fs = System.IO.File.Create(filePath + filename))
                {
                    //将byte数组写入文件中
                    fs.Write(bit, 0, bit.Length);
                    //所有流类型都要关闭流,否则会出现内存泄露问题
                    fs.Flush();
                    //file.CopyTo(fs);
                    //fs.Flush();
                }

                // }
                Entity.ImageEntity entity = new Entity.ImageEntity();
                entity.ImageId    = imageid;
                entity.UserOpenId = openid;
                entity.FilePath   = filename;

                bool insresult = _bll.InsertImageInfo(entity);
                if (insresult)
                {
                    result.status = 1;
                }
            }
            catch (Exception ex)
            {
                result.status = 0;
                result.desc   = ex.StackTrace;
            }
            return(result);
        }
Exemplo n.º 2
0
        public Entity.BaseResult Post()
        {
            Entity.BaseResult br = new Entity.BaseResult();
            try
            {
                Entity.ImageEntity enttiy = new Entity.ImageEntity();
                enttiy.UserOpenId = Request.Form["openid"];
                enttiy.Renom      = Request.Form["renum"];
                enttiy.ImageId    = Request.Form["imageid"];
                //插入之前需要先检查此人当日是否已经超过三次,若已满足,则不给点赞
                if (_bll.GetUserFabEnable(enttiy.UserOpenId))
                {
                    if (_bll.InsertFabInfo(enttiy))
                    {
                        br.status = 1;
                    }
                    else
                    {
                        br.status = 0;
                        br.desc   = "插入失败,请检查!";
                    }
                }
                else
                {
                    br.status = 0;
                    br.desc   = "今日点赞已满3次,请明日再来!";
                }
            }
            catch (Exception ex)
            {
                br.status = 0;
                br.desc   = "点赞异常!";
            }

            return(br);
        }