private static PostLoginResponse PostLogin(string username, string password, AutoLoginResponse autoLogin) { client.BaseUrl = new Uri("https://login.ktu.lt/"); var request = new RestRequest("simplesaml/module.php/core/loginuserpass.php", Method.POST); request.AddParameter("username", username); request.AddParameter("password", password); request.AddParameter("AuthState", autoLogin.authState); IRestResponse response = client.Execute(request); var document = parser.Parse(response.Content); var select = document.QuerySelector("input[name=\"StateId\"]"); if (select == null) { Console.WriteLine("Login failure"); // NOTE: Console outputs left return(new PostLoginResponse() { stateId = null }); } Console.WriteLine("Login success!"); return(new PostLoginResponse() { stateId = select.GetAttribute("value"), cookies = client.CookieContainer, // Same as autologin cookies, so useless status = response.StatusCode }); }
public AutoLoginResponse GetAutoLoginPath(AutoLoginRequest request) { string encryptDataInfo = ""; var result = new AutoLoginResponse(); string encryptKey = "clientIdType;clientIdNo;clientName;telNo;accNo;thirdMid;timestamp"; //需加签加密字段key Dictionary <string, string> postParams = request.GetParameters(); foreach (var m in postParams.Where(t => !string.IsNullOrWhiteSpace(t.Value)).OrderBy(t => t.Key)) { if (encryptKey.ToLower().Contains(m.Key.ToLower())) { encryptDataInfo += "&" + m.Key + "=" + m.Value; } } encryptDataInfo = encryptDataInfo.Substring(1); //需加签加密字段 try { var signature = Framework.Security.Crypt.SHA1(encryptDataInfo.ToLower() + PingAnConfig.sha1Key); string predata = encryptDataInfo + "&signature=" + signature.ToLower().ToLower(); var publicKey = RSAHelper.RSAPublicKeyJava2DotNet(PingAnConfig.autoLoginPublicKey); string encryptData = HexHelper.byteTo16HexStr(RSAHelper.SectionEncrypt(predata, publicKey)); result.autoLoginPath = PingAnConfig.autoLoginUrl + "?mchId=" + request.mchId + "&encryptData=" + encryptData; if (!string.IsNullOrWhiteSpace(request.redirectUrl)) { string redirectUrl = HttpUtility.UrlEncode(request.redirectUrl, System.Text.Encoding.UTF8); result.autoLoginPath += "&redirectUrl=" + redirectUrl; } if (!string.IsNullOrWhiteSpace(request.state)) { string returnUrl = HttpUtility.UrlEncode(request.state, Encoding.UTF8); string state = HttpUtility.UrlEncode("returnUrl=" + returnUrl, Encoding.UTF8); result.autoLoginPath += "&state=" + state; } return(result); } catch (Exception ex) { throw new Exception("返回异常"); } }
static bool AutoLogin(string url, Credentials c, string autoLoginUrl) { Console.WriteLine("Getting AutoLogin Link..."); ArticulateOnline ao = new ArticulateOnline { Url = url }; AutoLoginRequest request = new AutoLoginRequest { Credentials = c, Url = autoLoginUrl }; AutoLoginResponse response = ao.GetAutoLoginUrl(request); if (response.Success) { Console.WriteLine(response.Url); } return(response.Success); }