Exemple #1
0
        private void btn_lane_connect_Click(object sender, EventArgs e)
        {
            Dictionary <string, string> dic = new Dictionary <string, string> {
                { "Type", "Client" }, { "Name", text_message_lane_code.Text }
            };

            connection = new HubConnection(text_lane_hub_address.Text, dic);

            proxy = connection.CreateHubProxy(text_lane_hub_name.Text);

            connection.Start().Wait();

            lane = new Lane();
            GetLane_Value();
            Pf_Message_Lane_Object lane_obj = new Pf_Message_Lane_Object {
                lane = this.lane, lane_code = lane.lane_code, send_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            Pf_Message_Obj <Pf_Message_Lane_Object> obj = new Pf_Message_Obj <Pf_Message_Lane_Object>("lane", lane_obj);

            proxy.Invoke("Change", lane.lane_code, JSONHelper.SerializeObject(obj));//send to messageHub
            richTextBox1.AppendText(DateTime.Now.ToString() + ":" + "与服务器连接成功" + "\r\n");
            connection.StateChanged += Connection_StateChanged;


            proxy.On("reciveLane", (data) =>
            {
                Pf_Message_Lane_Object lane_obj_temp = JSONHelper.DeserializeJsonToObject <Pf_Message_Lane_Object>(data);
                lane = JSONHelper.DeserializeJsonToObject <Lane>(JSONHelper.SerializeObject(lane_obj_temp.lane));
                SetLane_Value();
            });
        }
Exemple #2
0
        //提交方案:
        private string submitDesign(string unit, string UserCode, string password, SplitData sdata)
        {
            object cookieLogin = null;
            //LoginResult loginResult = login3DWeb("meiwu"/*单位名称*/, "15915831930"/*手机号*/, "pwd123456"/*密码*/);
            LoginResult loginResult = login3DWeb(unit /*单位名称*/, UserCode /*手机号*/, password /*密码*/);

            if (loginResult.success)
            {
                cookieLogin = loginResult.msg as CookieContainer;
            }
            else
            {
                return(loginResult.msg.ToString());
            }

            //SplitData sdata = new SplitData();
            //填充sdata信息
            //...

            string      result      = split3DWeb(cookieLogin as CookieContainer, JSONHelper.SerializeObject(sdata));
            LoginResult splitResult = JSONHelper.DeserializeJsonToObject <LoginResult>(result);

            // MessageBox.Show(splitResult.msg);
            return(splitResult.msg.ToString());
        }
        private UploadToken GetTokenInfo(string token)
        {
            string tokenPath = _tokenPath + token + ".token";

            if (File.Exists(_server.MapPath(tokenPath)))
            {
                _fileHelper.FileName = token + ".token";
                _fileHelper.FilePath = _server.MapPath(_tokenPath);
                UploadToken uploadToken = JSONHelper.DeserializeJsonToObject <UploadToken>(_fileHelper.ReadFile());

                return(uploadToken);
            }

            return(null);
        }
 /// <summary>
 ///回调页面
 /// </summary>
 /// <returns></returns>
 public ActionResult CallBackUrl(string code)
 {
     try
     {
         var           url  = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx5da57aa47edf8eb8&secret=253cf3aa5bd73d13146c610e055a007d&code=" + code + "&grant_type=authorization_code";//获取access_token和openid请求链接
         string        resp = WebToRequest.PushToWeb(url);
         CallBackModel cb   = JSONHelper.DeserializeJsonToObject <CallBackModel>(resp);
         #region 数据操作
         //此处可进行数据相互相关代码
         #endregion
         return(View());
     }
     catch (Exception)
     {
         throw;
     }
 }
        public async Task <string> GetTokenAsync()
        {
            var user = new LoginDTO()
            {
                UserId   = "admin_drone",
                Password = "******"
            };

            var request = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json");

            using var client   = new HttpClient();
            client.BaseAddress = new Uri(_urlPedidos);
            var tokenJson = await client.PostAsync("api/login", request);

            var token = JSONHelper.DeserializeJsonToObject <Token>(await tokenJson.Content.ReadAsStringAsync()) as Token;

            return(token.AccessToken);
        }
Exemple #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!IsPostBack)
         {
             var           code = Request["code"];
             var           url  = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx5da57aa47edf8eb8&secret=253cf3aa5bd73d13146c610e055a007d&code=" + code + "&grant_type=authorization_code";//获取access_token和openid请求链接
             string        resp = WebToRequest.PushToWeb(url);
             CallBackModel cb   = JSONHelper.DeserializeJsonToObject <CallBackModel>(resp);
             #region 数据操作
             //此处可进行数据相互相关代码
             #endregion
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #7
0
        private LoginResult check3DWeb(CookieContainer cookieLogin, int process)
        {
            byte[] byteArray = Encoding.UTF8.GetBytes(String.Format("action=check&process={0}", process));

            HttpWebRequest request = WebRequest.Create("http://120.77.62.58:51404/ashx/users.ashx") as HttpWebRequest;

            request.Method          = "POST";
            request.KeepAlive       = false;
            request.ContentType     = "application/x-www-form-urlencoded";
            request.ContentLength   = byteArray.Length;
            request.CookieContainer = cookieLogin;
            Stream requestStream = request.GetRequestStream();

            requestStream.Write(byteArray, 0, byteArray.Length);
            requestStream.Flush();
            requestStream.Close();

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            CookieContainer cookieResponse = new CookieContainer();

            cookieResponse.Add(response.Cookies);
            Stream       instream = response.GetResponseStream();
            StreamReader sr       = new StreamReader(instream, Encoding.UTF8);
            string       result   = sr.ReadToEnd();

            sr.Close();
            response.Close();

            LoginResult loginResult = JSONHelper.DeserializeJsonToObject <LoginResult>(result);// JsonConvert.DeserializeObject<LoginResult>(result);

            if (loginResult.success)
            {
                loginResult.msg = cookieResponse;
            }
            else if (loginResult.msg.ToString().Equals("expire"))
            {
                loginResult.msg = "你的帐号已经到期,请联系管理员续费,谢谢!";
            }
            return(loginResult);
        }
Exemple #8
0
        // 一键拆单:
        private string separateBill(string uid, string UserCode, string password, string path, string KJLDesignID, string type)
        {
            object      cookieLogin = null;
            LoginResult loginResult = login3DWeb(uid /*单位名称*/, UserCode /*手机号*/, password /*密码*/);

            if (loginResult.success)
            {
                cookieLogin = loginResult.msg as CookieContainer;
            }
            else
            {
                return("false");
            }

            //string woodType = "橱柜" ? 1 : 2;
            //1  "Cabinet" :2 "Wardrobe"
            int    woodTypeNum = 0;
            string woodTypeStr = "";

            if (type == "橱柜")
            {
                woodTypeNum = 1;
                woodTypeStr = "Cabinet";
            }
            else if (type == "衣柜")
            {
                woodTypeNum = 2;
                woodTypeStr = "Wardrobe";
            }
            loginResult = check3DWeb(cookieLogin as CookieContainer, woodTypeNum);
            if (loginResult.success)
            {
                cookieLogin = loginResult.msg as CookieContainer;
            }
            else
            {
                return("false");
            }

            object sdata = new { appName = woodTypeStr, obsDesignId = KJLDesignID };

            string      result      = split3DWeb(cookieLogin as CookieContainer, JSONHelper.SerializeObject(sdata));
            LoginResult splitResult = new LoginResult();

            try
            {
                splitResult = JSONHelper.DeserializeJsonToObject <LoginResult>(result);
            }
            catch (Exception)
            {
                return(result + "/false");
            }

            if (splitResult.success)
            {
                Uri    uri       = new Uri(splitResult.msg.ToString());
                string queryStr  = uri.Query.TrimStart('?');
                byte[] byteArray = Encoding.UTF8.GetBytes(queryStr);

                HttpWebRequest request = WebRequest.Create(splitResult.msg.ToString()) as HttpWebRequest;
                request.Method          = "POST";
                request.KeepAlive       = false;
                request.ContentType     = "application/x-www-form-urlencoded";
                request.ContentLength   = byteArray.Length;
                request.CookieContainer = cookieLogin as CookieContainer;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(byteArray, 0, byteArray.Length);
                requestStream.Flush();
                requestStream.Close();

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                Stream          instream = response.GetResponseStream();
                StreamReader    sr       = new StreamReader(instream, Encoding.ASCII);

                byte[]     bArr = new byte[1024];
                FileStream fs   = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                int        size = instream.Read(bArr, 0, (int)bArr.Length);
                while (size > 0)
                {
                    fs.Write(bArr, 0, size);
                    size = instream.Read(bArr, 0, (int)bArr.Length);
                }
                fs.Close();

                sr.Close();
                response.Close();
                return("success");
            }
            else
            {
                return(splitResult.msg.ToString() + "/false");
            }
            //    MessageBox.Show(splitResult.msg);
        }