예제 #1
0
        //写诗
        static string ComposePoem(string imageBase64)
        {
            string url = "https://poem.msxiaobing.com/api/upload";//小冰上传图片地址

            HttpRequestClient httpRequestClient = new HttpRequestClient();

            httpRequestClient.SetFieldValue("userid", new Guid().ToString("x")); //发送数据
            httpRequestClient.SetFieldValue("text", "");                         //发送数据
            httpRequestClient.SetFieldValue("guid", new Guid().ToString("x"));   //发送数据
            httpRequestClient.SetFieldValue("image", imageBase64.Split(',')[1]); //发送数据
            string responseText = string.Empty;
            bool   uploaded     = httpRequestClient.Upload(url, out responseText);

            return(responseText);
        }
예제 #2
0
        public async static void Login(string device, string PicPath)
        {
            try
            {
                string     responseText = "";
                FileStream fs           = new FileStream(PicPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[]     fileBytes    = new byte[fs.Length];
                fs.Read(fileBytes, 0, fileBytes.Length);
                fs.Close(); fs.Dispose();

                HttpRequestClient httpRequestClient = new HttpRequestClient();
                httpRequestClient.SetFieldValue("device", device);
                httpRequestClient.SetFieldValue("pic", Path.GetFileName(PicPath), "application/octet-stream", fileBytes);
                string UploadApiUrl = ServerUrl + "/wgcs/custom/upload";
                httpRequestClient.Upload(UploadApiUrl, out responseText);
            }
            catch (Exception ex)
            {
                MessageBox.Show("服务器连接异常!");
            }
        }
예제 #3
0
        public override async Task <bool> Run()
        {
            this.Info($"Host:{Arguments.Host} Start rollBack from version:" + Arguments.DeployFolderName);
            HttpRequestClient httpRequestClient = new HttpRequestClient();

            httpRequestClient.SetFieldValue("publishType", "windowservice_rollback");
            httpRequestClient.SetFieldValue("id", Arguments.LoggerId);
            httpRequestClient.SetFieldValue("serviceName", Arguments.ServiceName);
            httpRequestClient.SetFieldValue("deployFolderName", Arguments.DeployFolderName);
            httpRequestClient.SetFieldValue("Token", Arguments.Token);
            HttpLogger HttpLogger = new HttpLogger
            {
                Key = Arguments.LoggerId,
                Url = $"http://{Arguments.Host}/logger?key=" + Arguments.LoggerId
            };
            var             isSuccess = true;
            WebSocketClient webSocket = new WebSocketClient(this.Log, HttpLogger);

            try
            {
                var hostKey = await webSocket.Connect($"ws://{Arguments.Host}/socket");

                httpRequestClient.SetFieldValue("wsKey", hostKey);

                var uploadResult = await httpRequestClient.Upload($"http://{Arguments.Host}/rollback", null, GetProxy());

                webSocket.ReceiveHttpAction(true);
                if (webSocket.HasError)
                {
                    isSuccess = false;
                    this.Error($"Host:{Arguments.Host},Rollback Fail,Skip to Next");
                }
                else
                {
                    if (uploadResult.Item1)
                    {
                        this.Info($"【rollback success】Host:{Arguments.Host},Response:{uploadResult.Item2}");
                    }
                    else
                    {
                        isSuccess = false;
                        this.Error($"Host:{Arguments.Host},Response:{uploadResult.Item2},Skip to Next");
                    }
                }
            }
            catch (Exception ex)
            {
                isSuccess = false;
                this.Error($"Fail Rollback,Host:{Arguments.Host},Response:{ex.Message},Skip to Next");
            }
            finally
            {
                await webSocket?.Dispose();
            }
            return(await Task.FromResult(isSuccess));
        }
예제 #4
0
        public override async Task <bool> Run()
        {
            byte[] zipBytes = File.ReadAllBytes(Arguments.PackageZipPath);
            if (zipBytes.Length < 1)
            {
                Error("package file is empty");
                return(await Task.FromResult(false));
            }

            this.Info($"Start Uppload,Host:{Arguments.Host}");

            HttpRequestClient httpRequestClient = new HttpRequestClient();

            httpRequestClient.SetFieldValue("publishType", "iis");
            httpRequestClient.SetFieldValue("isIncrement", (Arguments.IsSelectedDeploy || Arguments.IsIncrementDeploy)?"true":"false");
            httpRequestClient.SetFieldValue("useOfflineHtm", (Arguments.UseAppOffineHtm)?"true":"false");
            httpRequestClient.SetFieldValue("sdkType", "netcore");
            httpRequestClient.SetFieldValue("port", Arguments.Port);
            httpRequestClient.SetFieldValue("id", Arguments.LoggerId);
            httpRequestClient.SetFieldValue("remark", Arguments.Remark);
            httpRequestClient.SetFieldValue("mac", CodingHelper.GetMacAddress());
            httpRequestClient.SetFieldValue("pc", string.IsNullOrEmpty(Arguments.Email) ? System.Environment.MachineName : Arguments.Email);
            httpRequestClient.SetFieldValue("localIp", CodingHelper.GetLocalIPAddress());
            httpRequestClient.SetFieldValue("poolName", Arguments.PoolName);
            httpRequestClient.SetFieldValue("physicalPath", Arguments.PhysicalPath);
            httpRequestClient.SetFieldValue("webSiteName", Arguments.WebSiteName);
            httpRequestClient.SetFieldValue("deployFolderName", Arguments.DeployFolderName);
            httpRequestClient.SetFieldValue("Token", Arguments.Token);
            httpRequestClient.SetFieldValue("backUpIgnore", (Arguments.BackUpIgnore != null && Arguments.BackUpIgnore.Any()) ? string.Join("@_@", Arguments.BackUpIgnore) : "");
            httpRequestClient.SetFieldValue("publish", "publish.zip", "application/octet-stream", zipBytes);


            HttpLogger HttpLogger = new HttpLogger
            {
                Key = Arguments.LoggerId,
                Url = $"http://{Arguments.Host}/logger?key=" + Arguments.LoggerId
            };

            //IDisposable _subcribe = null;
            WebSocketClient webSocket = new WebSocketClient(this.Log, HttpLogger);
            var             isSuccess = true;

            try
            {
                var hostKey = await webSocket.Connect($"ws://{Arguments.Host}/socket");

                httpRequestClient.SetFieldValue("wsKey", hostKey);

                var uploadResult = await httpRequestClient.Upload($"http://{Arguments.Host}/publish", ClientOnUploadProgressChanged, GetProxy());

                if (ProgressPercentage == 0)
                {
                    isSuccess = false;
                }
                else
                {
                    webSocket.ReceiveHttpAction(true);
                    if (webSocket.HasError)
                    {
                        this.Error($"Host:{Arguments.Host},Deploy Fail,Skip to Next");
                        isSuccess = false;
                    }
                    else
                    {
                        if (uploadResult.Item1)
                        {
                            this.Info($"【deploy success】Host:{Arguments.Host},Response:{uploadResult.Item2}");
                        }
                        else
                        {
                            isSuccess = false;
                            this.Error($"Host:{Arguments.Host},Response:{uploadResult.Item2},Skip to Next");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isSuccess = false;
                this.Error($"Fail Deploy,Host:{Arguments.Host},Response:{ex.Message},Skip to Next");
            }
            finally
            {
                await webSocket?.Dispose();

                //_subcribe?.Dispose();
            }

            return(await Task.FromResult(isSuccess));
        }
예제 #5
0
        /// <summary>
        /// 上传图片服务
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public AppImgUploadRes Any(AppImgUploadReq req)
        {
            var res = new AppImgUploadRes();

            try
            {
                if (Request.Files != null && Request.Files.Count() > 0)
                {
                    for (int i = 0; i < Request.Files.Count(); i++)
                    {
                        var fileName = "";
                        var reqFile  = Request.Files[i];
                        if (reqFile.ContentLength > (1024 * 1024))
                        {
                            res.DoResult = "图片过大,不能超过1M";
                            return(res);
                        }

                        var fileBytes = new byte[reqFile.ContentLength];
                        reqFile.InputStream.Read(fileBytes, 0, (int)reqFile.ContentLength);

                        var upUrl             = Configurator.ImageFileService;
                        var imgUrl            = Configurator.ImageFileUrl;
                        var httpRequestClient = new HttpRequestClient();
                        var responseText      = string.Empty;

                        int userid = req.UserId;
                        if (userid <= 0)
                        {
                            Random rd = new Random();
                            userid = rd.Next();
                        }

                        fileName = reqFile.FileName;
                        httpRequestClient.SetFieldValue("userId", userid.ToString());
                        httpRequestClient.SetFieldValue("upFile", fileName, "application/octet-stream", fileBytes);

                        string dir = "/default/";
                        if (req.UploadType == (int)Enums.UploadType.Head)
                        {
                            dir = "/head/";
                        }
                        else if (req.UploadType == (int)Enums.UploadType.goods)
                        {
                            dir = "/goods/";
                        }
                        httpRequestClient.SetFieldValue("dir", dir);

                        httpRequestClient.Upload(upUrl, out responseText);
                        if (!string.IsNullOrEmpty(responseText))
                        {
                            responseText = responseText.Replace("\\", "");
                            var uploadResult = Newtonsoft.Json.JsonConvert.DeserializeObject <UploadImg>(responseText);
                            if (uploadResult.State.ToUpper() == "SUCCESS")
                            {
                                res.ImgUrl   = imgUrl + uploadResult.Url;
                                res.DoFlag   = (int)PtcpState.Success;
                                res.DoResult = "上传图片成功";
                                return(res);
                            }
                            else
                            {
                                res.DoResult = uploadResult.State.ToUpper();
                            }
                        }
                    }
                }
                else
                {
                    res.DoResult = "请上传图片";
                }
            }
            catch (Exception ex)
            {
                res.DoResult = "图片上传接口错误";
            }

            return(res);
        }
예제 #6
0
        public void ProcessRequest(HttpContext context)
        {
            string PUBLICIF = "";
            string postData = "";

            if (context.Request["PUBLICIF"] != null)
            {
                PUBLICIF = context.Request["PUBLICIF"].ToString();
            }
            if (context.Request["postData"] != null)
            {
                postData = context.Request["postData"].ToString();
            }
            PUBLICIF = context.Request["PUBLICIF"].ToString();
            context.Response.ContentType = "text/plain";
            context.Response.ContentType = "text/html; charset=utf-8";
            //返回提示
            ErrMsg NoteObject = new ErrMsg();
            //取出file上传文件
            HttpPostedFile file     = context.Request.Files[0];
            string         fileType = context.Request.QueryString["type"];
            //取本地路径,先将文件上传到服务器(程序服务器)
            string mapPath = context.Server.MapPath("~");
            string path    = mapPath + "\\WeiXin\\";

            if (file != null && file.ContentLength > 0)
            {
                int    imagesKindInx = file.FileName.LastIndexOf(".");
                string fileNewName   = ConvertDateTimeInt(DateTime.Now) + file.FileName.Substring(imagesKindInx, file.FileName.Length - imagesKindInx);
                string savePath      = path + fileNewName;
                //本地目录不存在创建
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //本地命名重复存在删除
                if (File.Exists(savePath))
                {
                    File.Delete(savePath);
                }
                //保存文件在本地
                file.SaveAs(savePath);

                //将文件转化为字节
                FileStream fs        = new FileStream(savePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[]     fileBytes = new byte[fs.Length];
                fs.Read(fileBytes, 0, fileBytes.Length);
                fs.Close();
                fs.Dispose();

                //获取token
                WX.WX_Token wxproc = new WX.WX_Token();
                string      token  = wxproc.getToken(PUBLICIF);
                Token1      oToken = new Token1();
                oToken = JsonConvert.DeserializeObject <Token1>(token);

                WebClient wc = new WebClient();
                wc.Encoding = ASCIIEncoding.UTF8;
                var    MediaUrl = "";
                string tp_media = "";
                if (fileType == "newsimg")  //图文图片接口 只返回图片地址
                {
                    MediaUrl = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=";
                    byte[] result = wc.UploadFile(new Uri(String.Format(MediaUrl + "{0}", oToken.result)), savePath);
                    tp_media = Encoding.Default.GetString(result);
                }
                else //image voice video thumb
                {
                    MediaUrl = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=";
                    string newUri = Convert.ToString(new Uri(String.Format(MediaUrl + "{0}&type={1}", oToken.result, fileType)));

                    //设置表单数据格式
                    HttpRequestClient httpRequestClient = new HttpRequestClient();
                    if (fileType == "video")  //上传视频需要传title、description
                    {
                        VideoInfo ObjVideo = JsonConvert.DeserializeObject <VideoInfo>(postData);
                        httpRequestClient.SetFieldValue("title", ObjVideo.title);                              //发送数据
                        httpRequestClient.SetFieldValue("introduction", ObjVideo.introduction);                //发送数据
                    }
                    httpRequestClient.SetFieldValue("media", savePath, "application/octet-stream", fileBytes); //发送文件数据
                    string responseText = string.Empty;
                    httpRequestClient.Upload(newUri, out responseText);                                        //请求  responseText是返回结果
                    tp_media = responseText;
                }


                WX_Mediaid tp_mediaid = new WX_Mediaid();
                tp_mediaid = JsonConvert.DeserializeObject <WX_Mediaid>(tp_media);
                if (tp_mediaid.errcode != 0)
                {
                    NoteObject.errCode    = 2;
                    NoteObject.errMessage = "上传微信服务器:" + tp_mediaid.errmsg;
                    context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                }
                else
                {
                    if (fileType == "newsimg")
                    {
                        ImgMsg imgObject = new ImgMsg();
                        imgObject.error = 0;
                        imgObject.url   = tp_mediaid.url;
                        context.Response.Write(JsonConvert.SerializeObject(imgObject));
                        // NoteObject.result = tp_mediaid.url;
                        //context.Response.Write(NoteObject.result);
                    }
                    else
                    {
                        NoteObject.result = tp_mediaid.media_id;
                        context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                    }
                }
                //context.Response.Write(JsonConvert.SerializeObject(NoteObject));
            }
        }