コード例 #1
0
ファイル: PrntImageRepo.cs プロジェクト: Acgnu/Meidoru-win
        public InvokeResult <ImageRepoUploadResult> Upload(ImageRepoUploadArg arg)
        {
            InvokeResult <ImageRepoUploadResult> invokeResult = new InvokeResult <ImageRepoUploadResult>()
            {
                success = false,
                message = "请求无返回"
            };
            ImageRepoUploadResult apiResult = new ImageRepoUploadResult()
            {
                Api        = GetApiCode(),
                ApiChannel = GetApiCode()
            };
            //var response = string.Empty;
            //using (HttpClient client = new HttpClient())
            //{
            //    var content = new MultipartFormDataContent();
            //    content.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(arg.FullFilePath)), "image", arg.ExtraArgs["uploadFileFormName"].ToString());
            //    content.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:65.0) Gecko/20100101 Firefox/65.0");
            //    response = client.PostAsync("https://prntscr.com/upload.php", content).Result.Content.ReadAsStringAsync().Result;
            //}

            //执行上传
            var response = RequestUtil.UploadFile("https://prntscr.com/upload.php", arg.FullFilePath, "image", arg.ExtraArgs["uploadFileFormName"].ToString(), null);

            if (string.IsNullOrEmpty(response))
            {
                return(invokeResult);
            }
            //转换为json对象
            var resultModel = (JObject)JsonConvert.DeserializeObject(response);
            var status      = Convert.ToString(resultModel["status"]);

            if (!status.Equals("success"))
            {
                invokeResult.message = Convert.ToString(resultModel["msg"]);
                return(invokeResult);
            }
            var ImgAddress  = resultModel["data"].ToString();
            var crawlResult = RequestUtil.CrawlContentFromWebsit(ImgAddress, null);

            //设置匹配规则
            Match mstr = Regex.Match(crawlResult.data, "(?m)<meta property=\"og: image\" content=\"(.*?)\"/>");

            if (!mstr.Success)
            {
                invokeResult.message = "数据抓取失败";
                return(invokeResult);
            }
            //开始逐行爬取IP
            while (mstr.Success)
            {
                apiResult.ImgUrl = mstr.Groups[0].Value + mstr.Groups[1].Value;
                break;
            }

            invokeResult.success = true;
            invokeResult.data    = apiResult;
            return(invokeResult);
        }
コード例 #2
0
        public InvokeResult <ImageRepoUploadResult> Upload(ImageRepoUploadArg arg)
        {
            //image File    是 表单名称
            //apiType String 是   公有云CDN,上传的图床类型(this、ali、huluxia等等),支持字符串传入(英文逗号分隔,例如:ali,huluxia)
            //token String  是 用户的秘钥,不填则上传至游客组(前提:支持游客上传)
            Dictionary <string, object> args = new Dictionary <string, object>();
            var apiType = CHANNELS[RandomUtil.GetRangeRandomNum(0, CHANNELS.Length)];

            args.Add("apiType", apiType);
            args.Add("token", "8cf8e506934880417492bde929777da3");
            ImageRepoUploadResult apiResult = new ImageRepoUploadResult()
            {
                Api        = GetApiCode(),
                ApiChannel = apiType
            };
            //执行上传
            var response = RequestUtil.UploadFile("https://www.hualigs.cn/api/upload", arg.FullFilePath, "image", arg.ExtraArgs["uploadFileFormName"].ToString(), args);

            if (string.IsNullOrEmpty(response))
            {
                return(new InvokeResult <ImageRepoUploadResult>()
                {
                    success = false,
                    message = "请求无返回"
                });
            }
            //转换为json对象
            JObject resultModel = (JObject)JsonConvert.DeserializeObject(response);
            int     code        = Convert.ToInt32(resultModel["code"]);

            if (code != 200)
            {
                return(new InvokeResult <ImageRepoUploadResult>()
                {
                    success = false,
                    message = "[" + apiType + "]" + Convert.ToString(resultModel["msg"])
                });
            }
            apiResult.ImgUrl = resultModel["data"]["url"][apiType].ToString();
            return(new InvokeResult <ImageRepoUploadResult>()
            {
                success = true,
                data = apiResult
            });
        }
コード例 #3
0
        public InvokeResult <ImageRepoUploadResult> Upload(ImageRepoUploadArg arg)
        {
            var apiType = CHANNELS[RandomUtil.GetRangeRandomNum(0, CHANNELS.Length)];
            ImageRepoUploadResult apiResult = new ImageRepoUploadResult()
            {
                Api        = GetApiCode(),
                ApiChannel = apiType
            };
            //执行上传
            //var uploadFileFormName = "sheet_" + RandomUtil.makeSring(false, 8) + ".png";
            var response = RequestUtil.UploadFile("https://image.kieng.cn/upload.html?type=" + apiType, arg.FullFilePath, "image", arg.ExtraArgs["uploadFileFormName"].ToString(), null);

            if (string.IsNullOrEmpty(response))
            {
                return(new InvokeResult <ImageRepoUploadResult>()
                {
                    success = false,
                    message = "请求无返回"
                });
            }
            //转换为json对象
            JObject resultModel = (JObject)JsonConvert.DeserializeObject(response);
            int     code        = Convert.ToInt32(resultModel["code"]);

            if (code != 200)
            {
                return(new InvokeResult <ImageRepoUploadResult>()
                {
                    success = false,
                    message = "[" + apiType + "]" + Convert.ToString(resultModel["msg"])
                });
            }
            apiResult.ImgUrl = resultModel["data"]["url"].ToString();
            return(new InvokeResult <ImageRepoUploadResult>()
            {
                success = true,
                data = apiResult
            });
        }