Exemplo n.º 1
0
 public static string loginIn()
 {
     try
     {
         XmlDocument xmldoc = new XmlDocument();
         xmldoc.Load(Application.StartupPath + "/LoginConfig.xml");
         XmlNode address = xmldoc.SelectSingleNode("//address");
         XmlNode account = xmldoc.SelectSingleNode("//account");
         XmlNode password = xmldoc.SelectSingleNode("//password");
         HttpHelper httphelper = new HttpHelper();
         NameValueCollection namevaluec = new NameValueCollection();
         namevaluec.Add("token", "login");
         namevaluec.Add("username", account.InnerText);
         namevaluec.Add("password", password.InnerText);
         namevaluec.Add("version", Application.ProductVersion);
         string loginrequest = httphelper.postHttpRequest("http://" + address + "/api/User/post", namevaluec);
         return loginrequest;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return "";
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 提交试卷内容
        /// </summary>
        private void PostPaper(string paper)
        {
            XmlDocument xmldocc = new XmlDocument();
            xmldocc.Load(Application.StartupPath + "/LoginConfig.xml");
            XmlNode access_token = xmldocc.SelectSingleNode("//access_token");
            XmlNode refresh_token = xmldocc.SelectSingleNode("//refresh_token");

            if (string.IsNullOrEmpty(access_token.InnerText) || string.IsNullOrEmpty(refresh_token.InnerText))
            {
                AccountManage pm = new AccountManage();
                DialogResult dr= pm.ShowDialog();
                if (dr.Equals(DialogResult.Cancel))
                {
                    return;
                }
                xmldocc.Load(Application.StartupPath + "/LoginConfig.xml");
                access_token = xmldocc.SelectSingleNode("//access_token");
                refresh_token = xmldocc.SelectSingleNode("//refresh_token");
            }
            XmlNode address = xmldocc.SelectSingleNode("//address");
            XmlNode account = xmldocc.SelectSingleNode("//account");
            XmlNode password = xmldocc.SelectSingleNode("//password");
            XmlNode token_type = xmldocc.SelectSingleNode("//token_type");
            XmlNode openid = xmldocc.SelectSingleNode("//openid");
            XmlNode postpaper = xmldocc.SelectSingleNode("//postpaper");

            HttpHelper httphelper = new HttpHelper();
            NameValueCollection namevaluec = new NameValueCollection();
            namevaluec.Add("access_token", access_token.InnerText);
            namevaluec.Add("refresh_token", refresh_token.InnerText);
            namevaluec.Add("token_type", token_type.InnerText);
            namevaluec.Add("openid", openid.InnerText);
            namevaluec.Add("userid", account.InnerText);
            namevaluec.Add("client_id", "100006");
            namevaluec.Add("clientip", "127.0.0.1");
            //namevaluec.Add("oauth_version", "2.a");
            namevaluec.Add("paper", System.Web.HttpUtility.UrlEncode(paper, System.Text.Encoding.UTF8));
            string postpaperrequest = httphelper.postHttpRequest(postpaper.InnerText, namevaluec);

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(postpaperrequest)))
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(UploadImgResp));
                UploadImgResp uploadimgresp = (UploadImgResp)serializer.ReadObject(ms);
                if (uploadimgresp.ret.Equals("1"))
                {
                    MessageBox.Show(uploadimgresp.msg, "提示");
                }
                else
                {
                    this.progressBarSpot.Value = 100;
                    this.progressBarSpot.Visible = false;
                    UploadSuccess uploadSuccess = new UploadSuccess();
                    uploadSuccess.ExamId = uploadimgresp.data.examId;
                    uploadSuccess.ShowDialog();
                }
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            // NameValueCollection nc = (NameValueCollection)ConfigurationSettings.GetConfig("name");
            //String name = ConfigurationSettings.AppSettings["nameaaa"];
            //string name = (string)Properties.Settings.Default["name"];
            //StringCollection subjectPre = (StringCollection)Properties.Settings.Default["subjectPre"];
            //this.textBoxAccount.Text = subjectPre[0];
            //this.textBoxPassword.Text = subjectPre[1];
            string passwordmd5 = "";
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Application.StartupPath + "/LoginConfig.xml");
                XmlNode address = xmldoc.SelectSingleNode("//address");
                XmlNode account = xmldoc.SelectSingleNode("//account");
                XmlNode password = xmldoc.SelectSingleNode("//password");
                XmlNode token = xmldoc.SelectSingleNode("//token");
                XmlNode isLoginDefault = xmldoc.SelectSingleNode("//isLoginDefault");
                if (this.checkBox1.Checked)
                {

                    address.InnerText = this.textBoxAddress.Text;
                    account.InnerText = this.textBoxAccount.Text.Trim();
                    MD5 md5 = new MD5CryptoServiceProvider();
                    byte[] bt = md5.ComputeHash(UnicodeEncoding.UTF8.GetBytes(this.textBoxPassword.Text));
                    if (password.InnerText.Equals(this.textBoxPassword.Text))
                    {
                        passwordmd5 = this.textBoxPassword.Text;
                    }
                    else
                    {
                        password.InnerText = BitConverter.ToString(bt).Replace("-", "");
                        passwordmd5 = password.InnerText;
                    }
                    isLoginDefault.InnerText = "true";

                }
                else
                {
                    address.InnerText = this.textBoxAddress.Text;
                    account.InnerText = this.textBoxAccount.Text.Trim();
                    password.InnerText = "";
                    isLoginDefault.InnerText = "false";

                }
                xmldoc.Save(Application.StartupPath + "/LoginConfig.xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show("配置文件出错.请重新安装程序修复", "提示");
            }

            try
            {
                HttpHelper httphelper = new HttpHelper();
                NameValueCollection namevaluec = new NameValueCollection();
                namevaluec.Add("client_id", "100006");
                namevaluec.Add("username", this.textBoxAccount.Text.Trim());
                namevaluec.Add("password", this.textBoxPassword.Text);
                namevaluec.Add("grant_type", "password");
                string loginrequest = httphelper.postHttpRequest("http://" + this.textBoxAddress.Text + "/oauth/token", namevaluec);

                LoginjJsonResult(loginrequest);
                //LoginXmlResult(loginrequest);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
        }