예제 #1
0
        private void picVerifyCode_Click(object sender, EventArgs e)
        {
            _Thread_GetVerifyCode = new Thread(() =>
            {
                #region Parameters/Headers
                IDictionary <string, string> SendParams = new Dictionary <string, string>()
                {
                };
                IDictionary <string, string> SendHeaders = ProcessSendHeaders();
                #endregion

                string GetURL = GetHTTPSendURL((int)APIActionType.GetVerifyCode);

                #region Process & Results
                bool IsSucceed = ProcessHTTPSend(GetURL, SendParams, SendHeaders, out string OutMessages, out string OutHtmlSource);
                if (IsSucceed && OutHtmlSource.Length > 0)
                {
                    var VerifyCode = JsonConvert.DeserializeObject <VerifyCodeInfo>(OutHtmlSource);
                    if (VerifyCode.StateCode.Equals(1) && VerifyCode.Info.VerifyImage.Length > 0)
                    {
                        txtVerifyKey.Text   = VerifyCode.Info.VerifyKey;
                        picVerifyCode.Image = WinFun.Base64ToImage(VerifyCode.Info.VerifyImage);
                    }
                    else
                    {
                        WinFun.ShowMessageBox("获取验证码失败:" + VerifyCode.StateMessage);
                    }
                }
                #endregion
            });
            _Thread_GetVerifyCode.Start();
        }
예제 #2
0
        private void btnUserRegister_Click(object sender, EventArgs e)
        {
            _Thread_UserRegister = new Thread(() =>
            {
                btnUserRegister.Enabled = false;

                #region Parameters/Headers
                IDictionary <string, string> SendParams = new Dictionary <string, string>()
                {
                };
                IDictionary <string, string> SendHeaders = ProcessSendHeaders();

                SendParams.Add("UserName", txtLoginUser.Text.Trim());
                SendParams.Add("Password", WinFun.StringToBase64(txtLoginPassword.Text.Trim()));
                SendParams.Add("MobileCode", txtLoginMobileCode.Text.Trim());
                SendParams.Add("VerifyKey", txtVerifyKey.Text.Trim());
                SendParams.Add("VerifyCode", txtLoginVerifyCode.Text.Trim());
                #endregion

                #region Process & Results
                bool IsSucceed = ProcessHTTPSend(GetHTTPSendURL((int)APIActionType.UserRegister), SendParams, SendHeaders, out string OutMessages, out string OutHtmlSource);
                if (IsSucceed && OutHtmlSource.Length > 0)
                {
                    UserTokenResult ResultInfo           = null;
                    UserTokenResultError ResultInfoError = null;

                    try { ResultInfo = JsonConvert.DeserializeObject <UserTokenResult>(OutHtmlSource); }
                    catch { }

                    try { ResultInfoError = JsonConvert.DeserializeObject <UserTokenResultError>(OutHtmlSource); }
                    catch { }

                    if (ResultInfo != null)
                    {
                        if (ResultInfo.StateCode.Equals(1))
                        {
                            //txtParamV1.Text = ResultInfo.Info.Token;
                            //txtHeaderV1.Text = ResultInfo.Info.Token;
                            WinFun.ShowMessageBox("注册成功");
                        }
                        else
                        {
                            WinFun.ShowMessageBox("注册失败," + ResultInfo.StateMessage);
                        }
                    }
                    else
                    {
                        if (ResultInfoError != null)
                        {
                            StringBuilder SbResults = new StringBuilder();
                            foreach (var item in ResultInfoError.Info)
                            {
                                SbResults.Append(item.Code.ToString() + ":" + item.Message + "\r");
                            }

                            WinFun.ShowMessageBox("注册失败,\r" + SbResults.ToString());
                        }
                        else
                        {
                            WinFun.ShowMessageBox("注册失败,远程返回状态不正确");
                        }
                    }
                }
                else
                {
                    WinFun.ShowMessageBox(OutMessages);
                }
                #endregion

                btnUserRegister.Enabled = true;
            });
            _Thread_UserRegister.Start();
        }
예제 #3
0
        private bool ProcessHTTPSend(string GetURL,
                                     IDictionary <string, string> SendParams,
                                     IDictionary <string, string> SendHeaders,
                                     out string OutMessages,
                                     out string OutHtmlSource)
        {
            txtOptionTips.Text    = "";
            txtHtmlSource.Text    = "";
            txtResultHeaders.Text = "";

            bool IsSucceed = false;
            bool IsPost    = cmbHttpType.SelectedIndex == 1 ? true : false;

            OutMessages   = "";
            OutHtmlSource = "";

            IDictionary <string, string> OutSendHeaders = new Dictionary <string, string>()
            {
            };
            IDictionary <string, string> OutResultHeaders = new Dictionary <string, string>()
            {
            };

            if (WinFun.CheckIsUrl(GetURL))
            {
                txtOptionTips.AppendText(FormatResultData("请求:" + GetURL + "\r\n"));
                if (IsPost)
                {
                    IsSucceed = HttpFun.DoWebPost(
                        GetURL,
                        "",
                        FormatGetTimeout(),
                        _Array_EncodingList[cmbEncoding.SelectedIndex],
                        SendParams,
                        SendHeaders,
                        out OutSendHeaders,
                        out OutResultHeaders,
                        out OutHtmlSource,
                        out OutMessages
                        );
                }
                else
                {
                    IsSucceed = HttpFun.DoWebGet(
                        GetURL,
                        FormatGetTimeout(),
                        _Array_EncodingList[cmbEncoding.SelectedIndex],
                        SendParams,
                        SendHeaders,
                        out OutSendHeaders,
                        out OutResultHeaders,
                        out OutHtmlSource,
                        out OutMessages
                        );
                }

                txtOptionTips.AppendText(FormatResultData("URL:" + OutMessages + "\r\n"));
                if (IsSucceed)
                {
                    txtOptionTips.AppendText(FormatResultData("结果:成功。\r\n"));
                    txtOptionTips.AppendText(FormatResultData("字数:" + OutHtmlSource.Length.ToString() + "\r\n"));
                    txtHtmlSource.Text = OutHtmlSource;
                }
                else
                {
                    txtOptionTips.AppendText("结果:失败。" + OutMessages + "\r\n");
                }

                #region Headers Show
                txtResultHeaders.AppendText("请求Headers:\r\n");
                foreach (var item in OutSendHeaders)
                {
                    txtResultHeaders.AppendText(item.Key + ": " + item.Value + "\r\n");
                }

                txtResultHeaders.AppendText("\r\n返回Headers:\r\n");

                foreach (var item in OutResultHeaders)
                {
                    txtResultHeaders.AppendText(item.Key + ": " + item.Value + "\r\n");
                }
                #endregion
            }
            else
            {
                WinFun.ShowMessageBox("请求URL无效。");
            }

            return(IsSucceed);
        }