//上传验证码 public void UploadVerifyCode() { if (moniterLoginThread != null && moniterLoginThread.IsAlive) { return; } try { JingKongHttp.DoGet(loginUrl); Random MyRandom = new Random(); int RandomNum = MyRandom.Next(100000000, 999999999); string url = "https://119.4.99.217:7300/mcrm/code/code?" + RandomNum; string filePath = Application.StartupPath + "\\" + posPlatForm + ".jpg"; JingKongHttp.Download(url, filePath, Application.StartupPath, "https://119.4.99.217:7300/mcrm/j_spring_security_check"); //上传 url = controllerUrl + "/UploadForReLogin?platform=" + posPlatForm; WebClient webClient = new WebClient(); byte[] resultByte = webClient.UploadFile(url, filePath); string errorMsg = Encoding.UTF8.GetString(resultByte); if (!string.IsNullOrEmpty(errorMsg)) { throw new Exception(errorMsg); } //切到web tabControl1.SelectedIndex = 1; myBrowser.Reload();//刷新,输入验证码 moniterLoginThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(MoniterVerifyCodeIsSet)); moniterLoginThread.Start(); } catch (Exception ex) { onError("重新登录", ex); } }
private static void testAutoLogin() { JingKongHttp.DoGet("https://119.4.99.217:7300/mcrm/login.jsp"); Random MyRandom = new Random(); int RandomNum = MyRandom.Next(100000000, 999999999); string url = "https://119.4.99.217:7300/mcrm/code/code?" + RandomNum; string filePath = "d:\\aaaaaaaa.jpg"; string basePath = @"D:\QuickDisk\MyWork\yiletong\output"; JingKongHttp.Download(url, filePath, basePath, "https://119.4.99.217:7300/mcrm/j_spring_security_check"); Console.WriteLine("download ok, please input the code"); string code = Console.ReadLine(); string data = "j_username=福州易乐通&j_password=Ylt123456&codeVal=" + code; string response = JingKongHttp.DoPostHttps("https://119.4.99.217:7300/mcrm/j_spring_security_check", data, basePath, "https://119.4.99.217:7300/mcrm/login.jsp"); if (response.IndexOf("<div class=\"alert alert-danger\" style=\"margin: 0px;\">验证码错误</div>") > -1) { Console.WriteLine("重登录失败,验证码" + code + "错误"); testAutoLogin(); } }