Пример #1
0
        public System.Drawing.Image DownloadImage(About about, string imageName)
        {
            System.Drawing.Image ad = null;
            string   loginUrl       = about.ServerUrl;
            Encoding encoding       = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string token    = CMD5.UserMd5(about.CabinetCode) + CMD5.UserMd5(datetime);

            parameters.Add("token", CMD5.UserMd5(token));
            parameters.Add("cabinetCode", about.CabinetCode);
            parameters.Add("filename", imageName);
            parameters.Add("datetime", datetime);
            parameters.Add("c", "Adimage");
            parameters.Add("a", "download");
            try
            {
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    Stream stream = response.GetResponseStream();

                    ad = System.Drawing.Bitmap.FromStream(stream);
                    stream.Close();
                }


                CLog4net.LogInfo("服务器连接:获得图片");
            }
            catch (Exception e)
            {
                CLog4net.LogError("GetAdImageNames" + e);
            }
            return(ad);
        }
Пример #2
0
        private void button7_Click(object sender, EventArgs e)
        {
            //double time = UnixTime.ConvertDateTimeInt(DateTime.Now);
            DateTime begin    = DateTime.Now;
            int      timeInt  = UnixTime.ConvertDateTimeToUnixTime(begin);
            DateTime dateTime = UnixTime.ConverUnixTimeToDateTime(timeInt);

            CLog4net.LogInfo(dateTime.ToShortTimeString());
        }
Пример #3
0
        public ServerCallback3 ServiceShakeHand(About about, IDictionary <string, string> dic)
        {
            ServerCallback3 sc       = new ServerCallback3();
            string          loginUrl = about.ServerUrl;
            Encoding        encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string token    = CMD5.UserMd5(about.CabinetCode) + CMD5.UserMd5(datetime);

            parameters.Add("cabinetCode", about.CabinetCode);
            parameters.Add("datetime", datetime);
            parameters.Add("c", "Security");
            parameters.Add("a", "hiCabinet");

            if (dic != null)
            {
                StringBuilder cabinetStatus = new StringBuilder();
                cabinetStatus.Append("{");
                cabinetStatus.Append(dic["camera"]);
                cabinetStatus.Append(",");
                cabinetStatus.Append(dic["comcard"]);
                cabinetStatus.Append("}");
                parameters.Add("cabinetStatus", cabinetStatus.ToString());
            }
            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();

                try
                {
                    sc = (ServerCallback3)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback3));
                }
                catch (Exception e)
                {
                    CLog4net.LogError(e.ToString());
                }
                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError("ServiceShakeHand" + e);
            }
            return(sc);
        }
Пример #4
0
        private void button5_Click(object sender, EventArgs e)
        {
            //string targetResult = string.Format("{\"v\":{0}}", 20);

            //string datetime = "1408202160";
            //string password = "******";
            //string temp = password + datetime;
            //string taken = CMD5.UserMd5(password + datetime);

            string       clearText     = UnixTime.ConvertDateTimeToUnixTime(new DateTime(2014, 9, 1)).ToString() + "30";
            string       key           = "ABCDEFGHIJKLMNOP";
            CryptoHelper helper        = new CryptoHelper(key);
            string       encryptedText = helper.Encrypt(clearText);

            Console.WriteLine(encryptedText);

            //string clearText1 = CryptoHelper.Decrypt(encryptedText, key);
            //string tempDate = clearText1.Substring(0, 10);
            //DateTime tempTime = UnixTime.ConverUnixTimeToDateTime(Convert.ToInt32(tempDate));
            //string tempDay = clearText1.Remove(0, 10);
            //Console.WriteLine(clearText1);

            //string source = temp;
            //using (MD5 md5Hash = MD5.Create())
            //{
            //    string hash = CMD5.GetMd5Hash(md5Hash, source);

            //    Console.WriteLine("The MD5 hash of " + source + " is: " + hash + ".");

            //    Console.WriteLine("Verifying the hash...");

            //    if (CMD5.VerifyMd5Hash(md5Hash, source, hash))
            //    {
            //        Console.WriteLine("The hashes are the same.");
            //    }
            //    else
            //    {
            //        Console.WriteLine("The hashes are not same.");
            //    }

            //    //taken = hash;

            //}


            //if (taken == "2b4109904540e7f1a858a70f99c76dad")
            //{
            //    Console.WriteLine("true");
            //}

            //HttpWebResponseUtility.TestJson();
            //HttpWebResponseUtility.TestPostHttps();
            //HttpWebResponseUtility.TestPostHttp();
            //WebServiceCall.TestGet();
        }
Пример #5
0
        /// <summary>
        /// 创建包裹
        /// </summary>
        /// <param name="pac"></param>
        /// <param name="about"></param>
        /// <returns></returns>
        public ServerCallback PackageCreate(Resource.Package pac, Resource.About about)
        {
            ServerCallback sc       = new ServerCallback();
            string         loginUrl = about.ServerUrl + packageCreate;
            Encoding       encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string token    = CMD5.UserMd5(pac.Courier.Code) + CMD5.UserMd5(datetime);
            //柜子地址
            string boxName = pac.Place.CoordinateInfo.X.ToString() + pac.Place.CoordinateInfo.Y.ToString();

            parameters.Add("token", CMD5.UserMd5(token));
            parameters.Add("courierCode", pac.Courier.Code.ToString());
            parameters.Add("boxName", boxName);
            parameters.Add("packageCode", pac.SN);
            parameters.Add("boxCode", pac.Place.Code.ToString());
            parameters.Add("receiverTelNum", pac.ReceiverTelNum);
            parameters.Add("cabinetCode", about.CabinetCode.ToString());
            parameters.Add("datetime", UnixTime.ConvertDateTimeToUnixTime(pac.CreatedTime).ToString());
            parameters.Add("c", "Pack");
            parameters.Add("a", "putpack");

            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();
                try
                {
                    sc = (ServerCallback)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback));
                }
                catch (Exception e)
                {
                    CLog4net.LogError(e.ToString());
                }
                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError("PackageCreate" + e);
            }
            return(sc);
        }
Пример #6
0
        /// <summary>
        /// 抓图并保存
        /// </summary>
        private void GrabImageAndSave()
        {
            int    beginTime     = Environment.TickCount;
            string imageIndex    = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string grabImagePath = string.Format(@"{0}\DataResources\ImageData\{1}.jpg", GetPath.GetStartupPath(), imageIndex);

            this.myPick.GrabImage(grabImagePath);
            //System.Threading.Thread.Sleep(2000);

            this.ControlPhotoCount();

            Console.WriteLine("GrabImageAndSave Time Spaned: " + (Environment.TickCount - beginTime) + "ms");
        }
Пример #7
0
        public ServerCallback3 ManagerDeletePackage(string boxCode, About about)
        {
            ServerCallback3 sc       = new ServerCallback3();
            string          loginUrl = about.ServerUrl;
            Encoding        encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string token    = CMD5.UserMd5(boxCode) + CMD5.UserMd5(datetime) + CMD5.UserMd5(CMD5.UserMd5(about.CabinetCode));

            parameters.Add("token", CMD5.UserMd5(token));
            parameters.Add("box", boxCode);
            parameters.Add("cabinetCode", about.CabinetCode);
            parameters.Add("datetime", datetime);
            parameters.Add("c", "Admin");
            parameters.Add("a", "openbox");
            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();

                try
                {
                    sc = (ServerCallback3)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback3));
                }
                catch (Exception e)
                {
                    sc = null;
                    CLog4net.LogError(e.ToString());
                }
                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError("ManagerDeletePackage " + e);
            }
            return(sc);
        }
Пример #8
0
        public bool ResponseOpenBoxCmd(string code, bool isOpen, About about)
        {
            ServerCallback2 sc       = new ServerCallback2();
            string          loginUrl = about.ServerUrl;
            Encoding        encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime    = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string orderstatus = isOpen == true ? "boxopened" : "error";
            string token       = CMD5.UserMd5(code) + CMD5.UserMd5(datetime);

            parameters.Add("token", CMD5.UserMd5(token));
            parameters.Add("code", code);
            parameters.Add("orderstatus", orderstatus);
            parameters.Add("datetime", datetime);
            parameters.Add("c", "Pack");
            parameters.Add("a", "remoteOpenBoxFeedback");
            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();

                try
                {
                    sc = (ServerCallback2)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback2));
                }
                catch (Exception e)
                {
                    CLog4net.LogError(e);
                }
                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError("ResponseOpenBoxCmd" + e);
            }
            return(sc.Received);
        }
Пример #9
0
        /// <summary>
        /// 快递员取回
        /// </summary>
        /// <param name="pac"></param>
        /// <param name="about"></param>
        /// <returns></returns>
        public ServerCallback CourierTackBack(string sn, Courier cour, Resource.About about)
        {
            ServerCallback sc       = new ServerCallback();
            string         loginUrl = about.ServerUrl + courierTackBack;
            Encoding       encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string token    = CMD5.UserMd5(cour.Code) + CMD5.UserMd5(datetime);

            parameters.Add("token", CMD5.UserMd5(token));
            parameters.Add("courierCode", cour.Code);
            parameters.Add("packageCode", sn);
            parameters.Add("cabinetCode", about.CabinetCode);
            parameters.Add("datetime", datetime);
            parameters.Add("c", "Courier");
            parameters.Add("a", "getback");

            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();
                try
                {
                    sc = (ServerCallback)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback));
                }
                catch (Exception e)
                {
                    CLog4net.LogError(e.ToString());
                }
                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError("CourierTackBack" + e);
            }
            return(sc);
        }
Пример #10
0
        /// <summary>
        /// 快递柜配置
        /// </summary>
        /// <param name="about"></param>
        /// <returns></returns>
        public ServerCallback CabinetConfig(Resource.About about)
        {
            ServerCallback sc       = new ServerCallback();
            string         loginUrl = about.ServerUrl + courierLogin;
            Encoding       encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("cabinetName", about.Name);
            parameters.Add("companyName", about.CompanyName);
            parameters.Add("address", about.Address);
            parameters.Add("telNum", about.TelNum);
            parameters.Add("configTime", UnixTime.ConvertDateTimeToUnixTime(about.ConfigTime).ToString());
            parameters.Add("createdTime", UnixTime.ConvertDateTimeToUnixTime(about.CreatedTime).ToString());
            parameters.Add("remark", about.Remark);

            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();
                try
                {
                    sc = (ServerCallback)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback));
                }
                catch (Exception e)
                {
                    CLog4net.LogError("CabinetConfig" + e);
                }

                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError(e);
            }
            return(sc);
        }
Пример #11
0
        public bool PackagePickUpLog(Resource.PickUpLog log, About about)
        {
            ServerCallback sc       = new ServerCallback();
            string         loginUrl = about.ServerUrl + packageDeliverLog;
            Encoding       encoding = Encoding.GetEncoding("gb2312");

            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("courierCode", log.CourierCode.ToString());
            parameters.Add("sn", log.Sn);
            parameters.Add("boxCode", log.BoxCode.ToString());
            parameters.Add("receiverTelNum", log.ReceiverTelNum);
            parameters.Add("cabinetCode", about.CabinetCode.ToString());
            parameters.Add("deletedTime", UnixTime.ConvertDateTimeToUnixTime(log.DeletedTime).ToString());
            parameters.Add("receiverIdentity", log.ReceiverIdentity.ToString());
            parameters.Add("remark", log.Remark);
            try
            {
                string result = "";
                using (HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, timeoutMSecond, null, encoding, null))
                {
                    string cookieString = response.Headers["Set-Cookie"];
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                StringReader   sr         = new StringReader(result);
                JsonSerializer serializer = new JsonSerializer();
                try
                {
                    sc = (ServerCallback)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback));
                }
                catch (Exception e)
                {
                    CLog4net.LogError(e.ToString());
                }
                CLog4net.LogInfo("服务器连接:" + result);
            }
            catch (Exception e)
            {
                CLog4net.LogError("PackagePickUpLog" + e);
            }
            return(sc.Success);
        }
Пример #12
0
        /// <summary>
        /// 抓图并保存
        /// </summary>
        private bool GrabImageAndSave()
        {
            if (videoDevices == null)
            {
                return(false);
            }

            if (this.bitmapBuffer == null)
            {
                return(false);
            }
            int    beginTime     = Environment.TickCount;
            string imageIndex    = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string grabImagePath = string.Format(@"{0}\DataResources\ImageData\{1}.jpg", GetPath.GetStartupPath(), imageIndex);

            this.bitmapBuffer.Save(grabImagePath);

            this.ControlPhotoCount();

            Console.WriteLine("GrabImageAndSave Time Spaned: " + (Environment.TickCount - beginTime) + "ms");

            return(true);
        }
Пример #13
0
        public string GetRceiverSearchPGUrl(About about, string packageCode, int pageNum)
        {
            string result   = "";
            string loginUrl = about.ServerUrl;
            IDictionary <string, string> parameters = new Dictionary <string, string>();
            string datetime = UnixTime.ConvertDateTimeToUnixTime(DateTime.Now).ToString();
            string token    = CMD5.UserMd5(about.CabinetCode) + CMD5.UserMd5(datetime);

            parameters.Add("token", CMD5.UserMd5(token));
            parameters.Add("cabinetCode", about.CabinetCode);
            parameters.Add("packageCode", packageCode);
            parameters.Add("datetime", datetime);
            parameters.Add("reqPageNum", pageNum.ToString());
            parameters.Add("c", "Receiver");
            parameters.Add("a", "packstatus");

            StringBuilder buffer = new StringBuilder();
            int           i      = 0;

            foreach (string key in parameters.Keys)
            {
                if (i > 0)
                {
                    buffer.AppendFormat("&{0}={1}", key, parameters[key]);
                }
                else
                {
                    buffer.AppendFormat("{0}={1}", key, parameters[key]);
                }
                i++;
            }

            result = about.ServerUrl + "?" + buffer.ToString();

            return(result);
        }