示例#1
0
        public Result CheckFw()
        {
            Result Result = new Result();

            try
            {
                User user = this.GetLoginUser();
                if (user.IsHasSpecialPower() == false &&
                    ishaveroot(user) == false)
                {
                    throw new Exception("权限不足!");
                }
                else
                {
                    List <byte[]> datas = new List <byte[]>();
                    foreach (var item in HttpContext.Request.Form.Files)
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            item.CopyTo(stream);
                            datas.Add(stream.ToArray());
                            stream.Dispose();
                        }
                    }

                    List <string> msgdatas = new List <string>();
                    datas.ForEach(c => msgdatas.AddRange(TextDetectionService.TextDetections(c)));
                    Result.Data = msgdatas;
                }
            }
            catch (Exception e)
            {
                Result.SetFail();
                Result.Msg = e.Message;
                Log.Error(e.ToString());
            }
            return(Result);
        }
示例#2
0
        public Result CheckImage([FromForm] IFormCollection formFiles)
        {
            Result Result = new Result();

            try
            {
                User user = this.GetLoginUser();
                if (Convert.ToBoolean(user.IsHasSpecialPower()) == false &&
                    ishaveroot(user) == false)
                {
                    throw new Exception("权限不足!");
                }
                else
                {
                    string rootdir = AppContext.BaseDirectory + "//FileCheck//" + DateTime.Now.ToString("yyyy-MM-dd") + "//";
                    if (Directory.Exists(rootdir) == false)
                    {
                        Directory.CreateDirectory(rootdir);
                    }
                    List <ImageItem> imagedatas = new List <ImageItem>();
                    int    idx   = 0;
                    byte[] datas = null;
                    ///获取图片信息
                    foreach (var item in ((FormCollection)formFiles).Files)
                    {
                        if (idx++ == 0)
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                item.CopyTo(stream);
                                datas = stream.ToArray();
                            }
                        }
                        else
                        {
                            string id = idx + "----------------" + Guid.NewGuid().ToString().Replace("-", "_") + ".jpg";
                            id = Path.Combine(rootdir, id);
                            using (FileStream stream = System.IO.File.Open(id, FileMode.Create))
                            {
                                item.CopyTo(stream);
                            }
                            imagedatas.Add(new ImageItem(id, ""));
                        }
                    }
                    if (imagedatas.Count != 8 || datas == null)
                    {
                        throw new Exception("请求的图片参数错误!");
                    }
                    else
                    {
                        string text = TextDetectionService.TextDetection(datas);
                        foreach (var item in imagedatas)
                        {
                            //item.FileValue = textDetectionService.ImageDetection(item.File).ToString();
                            item.FileValue = HttpClient.GetStringAsync(url + item.FileName).Result;
                        }
                        List <int> resultValues = checkimagecode(text);

                        for (int i = 0; i < imagedatas.Count; i++)
                        {
                            if (resultValues.Contains(Convert.ToInt32(imagedatas[i].FileValue)))
                            {
                                imagedatas[i].FileValue = "true";
                            }
                            else
                            {
                                imagedatas[i].FileValue = "false";
                            }
                            imagedatas[i].FileName = i.ToString();
                        }
                        Result.Data = imagedatas;
                    }
                }
            }
            catch (Exception ex)
            {
                Result.SetFail();
                Result.Msg = ex.Message;
                Log.Log(ex.ToString());
            }
            return(Result);
        }