Ejemplo n.º 1
0
        /// <summary>
        /// 保持数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public string Save(hangfire_task dto)
        {
            if (dto.id.EmptyId())
            {
                var exiteJob = Sqldb.Select <hangfire_task>()
                               .Where(s => s.assembly_namespace == dto.assembly_namespace && s.class_name == dto.class_name).Count();
                if (exiteJob > 0)
                {
                    throw new Exception($"任务{dto.assembly_namespace}.{dto.class_name}已存在");
                }
                dto.id            = IdWorkerHelper.GenObjectId();
                dto.excute_time   = DateTime.Now;
                dto.excute_status = 1;
                int affect = Sqldb.Insert(dto).ExecuteAffrows();
                if (affect < 1)
                {
                    throw new Exception("任务添加失败");
                }

                return(dto.id);
            }
            else
            {
                int affect = Sqldb.Update <hangfire_task>().SetSource(dto).IgnoreColumns(s => new { s.excute_time, s.excute_status }).ExecuteAffrows();
                if (affect < 1)
                {
                    throw new Exception("任务添加失败");
                }

                return(dto.id);
            }
        }
Ejemplo n.º 2
0
        public ActionResult GenTaskId()
        {
            var id     = IdWorkerHelper.GenObjectId();
            var result = new ResultAdaptDto();

            result.data.Add("taskId", id);
            return(Data(result));
        }
Ejemplo n.º 3
0
        public ActionResult Uploadimg()
        {
            var result = new ResultAdaptDto();
            //long size = 0;
            var files = Request.Form.Files;

            if (files.Count == 0)
            {
                result.status = false;
                result.msg    = "没有文件信息";
                return(Content(result.ToJson()));
            }
            string url    = $"/upfiles/images/{DateTime.Now.ToString("yyyyMMdd")}";
            var    folder = GlobalParamsDto.WebRoot + url;

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var file     = files[0];
            var filename = ContentDispositionHeaderValue
                           .Parse(file.ContentDisposition)
                           .FileName
                           .Trim('"');
            int    index        = filename.LastIndexOf('.');
            string extName      = filename.Substring(index);
            string guidstr      = Guid.NewGuid().ToString("N");
            string guidFileName = guidstr + extName;

            //这个hostingEnv.WebRootPath就是要存的地址可以改下
            filename = $"{folder}/{guidFileName}";
            using (FileStream fs = System.IO.File.Create(filename))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var firstFileInfo = new FileInfo(filename);

            if (firstFileInfo.Length > 200 * 1024)
            {
                string compressFileName = IdWorkerHelper.GenObjectId() + extName;
                string compressFile     = $"{folder}/{compressFileName}";
                ImageUtilities.CompressImage(filename, compressFile, 90, 200);
                guidFileName = compressFileName;
            }
            string imgurl = $"{ url}/{guidFileName}";

            result.data.Add("url", imgurl);
            return(Content(result.ToJson()));
        }
Ejemplo n.º 4
0
        public IActionResult Merge()
        {
            var result = new ResultAdaptDto();

            try
            {
                string guid      = RequestHelper.GetQueryString("guid");
                string fileName  = RequestHelper.GetQueryString("fileName");
                var    tempDir   = GlobalParamsDto.WebRoot + "/UploadTemp/" + guid;                                  // 缓存文件夹
                var    targetDir = GlobalParamsDto.WebRoot + "/upfiles/videos/" + DateTime.Now.ToString("yyyyMMdd"); // 目标文件夹
                //uploadfile,uploadvideo
                string action = RequestHelper.GetPostString("action");
                if (action == "uploadfile")
                {
                    targetDir = GlobalParamsDto.WebRoot + "/upfiles/attachments/" + DateTime.Now.ToString("yyyyMMdd"); // 目标文件夹
                }
                if (!System.IO.Directory.Exists(targetDir))
                {
                    System.IO.Directory.CreateDirectory(targetDir);
                }

                int    index        = fileName.LastIndexOf('.');
                string extName      = fileName.Substring(index);
                string guidFileName = IdWorkerHelper.GenObjectId() + extName;
                var    finalPath    = Path.Combine(targetDir, guidFileName);

                var files = System.IO.Directory.GetFiles(tempDir);//获得下面的所有文件
                using (FileStream fs = System.IO.File.Create(finalPath))
                {
                    foreach (var part in files.OrderBy(x => x.Length).ThenBy(x => x))//排一下序,保证从0-N Write
                    {
                        var bytes = System.IO.File.ReadAllBytes(part);
                        fs.Write(bytes, 0, bytes.Length);
                        bytes = null;
                        System.IO.File.Delete(part);//删除分块
                    }
                    fs.Flush();
                }
                string returnPath = "/upfiles/videos/" + DateTime.Now.ToString("yyyyMMdd") + "/" + guidFileName;
                result.data.Add("url", returnPath);
                result.data.Add("fileName", fileName);
            }
            catch (Exception ex)
            {
                result.status = false;
                result.msg    = ex.Message;
            }
            return(Content(result.ToJson()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 返回openid
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public ActionResult Id(string code, string state)
        {
            string signUrl = RequestHelper.Request().AbsoluteUri();

            if (!string.IsNullOrEmpty(code))
            {
                var result = OAuthApi.GetAccessToken(_wxSetting.WeixinAppId, _wxSetting.WeixinAppSecret, code);
                if (result.errcode != ReturnCode.请求成功)
                {
                    return(Content("错误:" + result.errmsg));
                }
                string id = $"你的openid为:{result.openid}";
                return(Content(id));
            }
            else
            {
                string state1 = IdWorkerHelper.GenObjectId();//随机数,用于识别请求可靠性
                // signUrl = signUrl + "/WxExpert/Index";
                var url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect", _wxSetting.WeixinAppId, signUrl.UrlEncode(), state1);
                return(Redirect(url));
            }
        }
Ejemplo n.º 6
0
        public IActionResult Auth(string code, string state)
        {
            AccessTokenContainer.RegisterAsync(_wxSetting.WeixinAppId, _wxSetting.WeixinAppSecret, "doctor_platform");
            string state1 = IdWorkerHelper.GenObjectId();   //随机数,用于识别请求可靠性

            HttpContext.Session.SetString("State", state1); //储存随机数到Session
            string signUrl = Request.AbsoluteUri();

            // LogNHelper.Info(signUrl);
            // MemoryCacheHelper.Set("test", "nihao", TimeSpan.FromMinutes(1));
            // var keys= MemoryCacheHelper.GetCacheKeys();
            if (!string.IsNullOrEmpty(code))
            {
                var result = OAuthApi.GetAccessToken(_wxSetting.WeixinAppId, _wxSetting.WeixinAppSecret, code);
                if (result.errcode != ReturnCode.请求成功)
                {
                    return(Content("错误:" + result.errmsg));
                }
                //LogNHelper.Info(result.openid);
                //尝试获取用户信息
                //OAuthUserInfo userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                //string json = userInfo.ToJson();
                //LogNHelper.Info(json);
                //Task.Factory.StartNew(() => GetUserInfo(result.access_token, result.openid));
                string key = "{access_token}:wxtoken";
                RedisHelper.Set(key, result, result.expires_in);

                RequestHelper.SetOpenId(result.openid, result.expires_in);
                string homeUrl = $"/wechat/index.html?openId={result.openid}";
                return(Redirect(homeUrl));
            }
            else
            {
                // signUrl = signUrl + "/WxExpert/Index";snsapi_userinfo snsapi_base
                var url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect",
                                        _wxSetting.WeixinAppId, signUrl.UrlEncode(), state1);
                return(Redirect(url));
            }
        }
Ejemplo n.º 7
0
        public ActionResult Index(string action)
        {
            var result = new UeditorUploadDto();

            try
            {
                if (action == "config")
                {
                    string configPath = $@"plugins\ueditor\config.json";
                    string serverPath = Path.Combine(GlobalParamsDto.WebRoot, configPath);
                    if (System.IO.File.Exists(serverPath))
                    {
                        string json = System.IO.File.ReadAllText(serverPath);
                        return(Content(json));
                    }
                    return(Content(""));
                }

                var files = Request.Form.Files;
                if (files.Count == 0)
                {
                    result.state = "FAIL";
                    result.error = "请选择文件";
                    return(Content(result.ToJson()));
                }
                var    file     = files[0];
                var    filename = file.FileName;
                int    index    = filename.LastIndexOf('.');
                string extName  = filename.Substring(index + 1);
                //uploadimage
                string url       = $"/upfiles/images/{DateTime.Now.ToString("yyyyMMdd")}";
                var    uploadSet = SiteManagerCache.GetUploadInfo();
                if (action == "uploadimage")
                {
                    var imageExt = uploadSet.image_extname.Split(',');
                    if (!imageExt.Contains(extName))
                    {
                        result.state = "FAIL";
                        result.error = $"禁止上传图片类型:{extName}";
                        return(Content(result.ToJson()));
                    }
                }
                else if (action == "uploadfile")
                {
                    var fileExt = uploadSet.attache_extname.Split(',');
                    if (!fileExt.Contains(extName))
                    {
                        result.state = "FAIL";
                        result.error = $"禁止上传附件类型:{extName}";
                        return(Content(result.ToJson()));
                    }

                    if (file.Length > (uploadSet.max_file_size * 1024 * 1024))
                    {
                        result.state = "FAIL";
                        result.error = $"上传附件超过{uploadSet.max_file_size}MB限制,禁止上传";
                        return(Content(result.ToJson()));
                    }
                    url = $"/upfiles/attachments/{DateTime.Now.ToString("yyyyMMdd")}";
                }
                else if (action == "uploadvideo")
                {
                    var mediaExt = uploadSet.media_extname.Split(',');
                    if (!mediaExt.Contains(extName))
                    {
                        result.state = "FAIL";
                        result.error = $"禁止上传视频类型:{extName}";
                        return(Content(result.ToJson()));
                    }
                    if (file.Length > (uploadSet.max_file_size * 1024 * 1024))
                    {
                        result.state = "FAIL";
                        result.error = $"上传视频超过{uploadSet.max_file_size}MB限制,禁止上传";
                        return(Content(result.ToJson()));
                    }
                    url = $"/upfiles/videos/{DateTime.Now.ToString("yyyyMMdd")}";
                }
                var folder = GlobalParamsDto.WebRoot + url;

                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }


                string guidstr      = IdWorkerHelper.GenObjectId();
                string guidFileName = guidstr + extName;
                //这个hostingEnv.WebRootPath就是要存的地址可以改下
                string newfilename = $"{folder}/{guidFileName}";

                using (FileStream fs = System.IO.File.Create(newfilename))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                if (action == "uploadimage")
                {
                    var firstFileInfo = new FileInfo(newfilename);
                    if (firstFileInfo.Length > 200 * 1024)
                    {
                        string compressFileName = IdWorkerHelper.GenObjectId() + extName;
                        string compressFile     = $"{folder}/{compressFileName}";
                        ImageUtilities.CompressImage(newfilename, compressFile, 90, 200);
                        guidFileName = compressFileName;
                    }
                }
                result.original = filename;
                result.title    = filename;
                result.url      = $"{url}/{guidFileName}";
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
                result.state = "FAIL";
                result.error = "内部异常,请联系管理员";
            }


            return(Content(result.ToJson()));
        }
Ejemplo n.º 8
0
        public ActionResult Uploadimg()
        {
            var result = new ResultAdaptDto();
            //long size = 0;
            //当设置了开始水印的时候,可以使用nomark来过滤图片不加水印
            int nomark = RequestHelper.GetPostInt("nomark");
            var files  = Request.Form.Files;

            if (files.Count == 0)
            {
                result.status = false;
                result.msg    = "没有文件信息";
                return(Content(result.ToJson()));
            }
            string url    = $"/upfiles/images/{DateTime.Now.ToString("yyyyMMdd")}";
            var    folder = GlobalParamsDto.WebRoot + url;

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var file     = files[0];
            var filename = ContentDispositionHeaderValue
                           .Parse(file.ContentDisposition)
                           .FileName
                           .Trim('"');
            int    index        = filename.LastIndexOf('.');
            string extName      = filename.Substring(index);
            string guidstr      = Guid.NewGuid().ToString("N");
            string guidFileName = guidstr + extName;

            //这个hostingEnv.WebRootPath就是要存的地址可以改下
            filename = $"{folder}/{guidFileName}";
            using (FileStream fs = System.IO.File.Create(filename))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var firstFileInfo = new FileInfo(filename);

            if (firstFileInfo.Length > 200 * 1024)
            {
                string compressFileName = IdWorkerHelper.GenObjectId() + extName;
                string compressFile     = $"{folder}/{compressFileName}";
                ImageUtilities.CompressImage(filename, compressFile, 90, 200);
                guidFileName = compressFileName;
            }
            if (nomark == 0)
            {
                var imageSet = SiteManagerCache.GetUploadInfo();
                if (imageSet.open_watermark == 1)
                {
                    try
                    {
                        string sourcePath = $"{folder}/{guidFileName}";
                        if (System.IO.File.Exists(sourcePath))
                        {
                            FileStream fs = new FileStream(sourcePath, FileMode.Open);
                            //把文件读取到字节数组
                            byte[] data = new byte[fs.Length];
                            fs.Read(data, 0, data.Length);
                            fs.Close();
                            //实例化一个内存流--->把从文件流中读取的内容[字节数组]放到内存流中去
                            MemoryStream ms    = new MemoryStream(data);
                            Image        image = Image.FromStream(ms);
                            if (image.Width > imageSet.image_width && image.Height > imageSet.image_height)
                            {
                                ImageWatermarker marker = new ImageWatermarker();
                                //图片水印
                                if (imageSet.watermark_type == 1)
                                {
                                    string waterMarkIamge = GlobalParamsDto.WebRoot + imageSet.watermark_image;
                                    if (System.IO.File.Exists(waterMarkIamge))
                                    {
                                        marker.AddImageSignPic(image, sourcePath, waterMarkIamge, imageSet.water_postion, imageSet.image_quality, imageSet.image_opacity);
                                    }
                                }
                                else
                                {
                                    marker.AddWatermarkText(image, sourcePath, imageSet.watermark_word, imageSet.water_postion, imageSet.font_size, imageSet.font_color);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogNHelper.Exception(ex);
                    }
                }
            }
            string imgurl = $"{ url}/{guidFileName}";

            result.data.Add("url", imgurl);
            return(Content(result.ToJson()));
        }
Ejemplo n.º 9
0
        public ActionResult Index(string action)
        {
            var result = new UeditorUploadDto();

            try
            {
                if (action == "config")
                {
                    string configPath = $@"plugins\ueditor\config.json";
                    string serverPath = Path.Combine(GlobalParamsDto.WebRoot, configPath);
                    if (System.IO.File.Exists(serverPath))
                    {
                        string json = System.IO.File.ReadAllText(serverPath);
                        return(Content(json));
                    }
                    return(Content(""));
                }

                var files = Request.Form.Files;
                if (files.Count == 0)
                {
                    result.state = "FAIL";
                    result.error = "请选择文件";
                    return(Content(result.ToJson()));
                }
                //uploadimage
                string url = $"/upfiles/images/{DateTime.Now.ToString("yyyyMMdd")}";
                if (action == "uploadfile")
                {
                    url = $"/upfiles/attachments/{DateTime.Now.ToString("yyyyMMdd")}";
                }
                var folder = GlobalParamsDto.WebRoot + url;

                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                var    file         = files[0];
                var    filename     = file.FileName;
                int    index        = filename.LastIndexOf('.');
                string extName      = filename.Substring(index);
                string guidstr      = IdWorkerHelper.GenObjectId();
                string guidFileName = guidstr + extName;
                //这个hostingEnv.WebRootPath就是要存的地址可以改下
                string newfilename = $"{folder}/{guidFileName}";

                using (FileStream fs = System.IO.File.Create(newfilename))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                result.original = filename;
                result.title    = filename;
                result.url      = $"{url}/{guidFileName}";
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
                result.state = "FAIL";
                result.error = "内部异常,请联系管理员";
            }


            return(Content(result.ToJson()));
        }