public void @__rsaTest() { /* * string str = "LYifFXmP889Rdczc112PA"; // TODO: 初始化为适当的值 * string expected = string.Empty; // TODO: 初始化为适当的值 * string actual; * actual = _37wanLogin.@__rsa(str); * Assert.AreEqual(expected, actual); */ string errMsg = ""; HISTORYGAMESERVER server = null; _37wanLogin obj = new _37wanLogin("burnblood2", "8891129zh"); bool bret = obj.Login(ref server, ref errMsg); Assert.Inconclusive("验证此测试方法的正确性。"); }
public bool Login(ref HISTORYGAMESERVER serverInfo, ref string errMsg) { try { string passwdencrypt = PasswdEncrypt(passwd); /* * GET /api/p_register_v2.php?callback=jQuery183024481548836811018_1512003074702&login_account=burnblood&password=VGdSbjBVd1Q4ODlBTGZ4YTExMjl6aEcz&game_id=237&game_server_id=&email=&referer=baidu_ppzq&referer_param=&ab_param=&name=&id_card_number=&ab_type=&wd=&verify_code=&s=1&return_userinfo=1&form_type=1&tj_from=202&tj_way=1&_=1512003180508 HTTP/1.1 */ long timestamp = ConvertDateTimeToInt(DateTime.Now); string destURL = string.Format("{0}/api/p_register_v2.php?callback=jQuery&login_account={1}&password={2}&_={3}&" + "game_id=237&game_server_id=&email=&referer=baidu_ppzq&referer_param=&ab_param=&name=&id_card_number=&ab_type=&" + "wd=&verify_code=&s=1&return_userinfo=1&form_type=1&tj_from=202&tj_way=1", mainURL, accName, passwdencrypt, timestamp); HttpClientHandler handler = new HttpClientHandler(); handler.AllowAutoRedirect = false; handler.MaxAutomaticRedirections = 5; HttpClient client = new HttpClient(handler); client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); var task = client.GetAsync(new Uri(destURL)); task.Result.EnsureSuccessStatusCode(); HttpResponseMessage response = task.Result; string statuscode = response.StatusCode + " " + response.ReasonPhrase + Environment.NewLine; var result = response.Content.ReadAsStringAsync(); string responseBodyAsText = result.Result; // 转为json对象 string jsonstr = responseBodyAsText.Replace("jQuery({", "{").Replace(");", ""); webLoginRetInfo retobj = (webLoginRetInfo)JsonManager.JsonToObject(jsonstr, typeof(webLoginRetInfo)); if (retobj.success == "0") { List <HISTORYGAMESERVER> serverlst = retobj.userinfo.HISTORY_GAME_SERVER.ToList(); if (serverlst.Count > 0) { serverInfo = serverlst[0]; } //// 获取服务器URL // // 获取服务器信息 string jumpURL = string.Format("http://game.37.com/play.php?game_id={0}&sid={1}", serverInfo.GAME_ID, serverInfo.SID); // 请求并获取server_id task = client.GetAsync(new Uri(jumpURL)); task.Result.EnsureSuccessStatusCode(); response = task.Result; result = response.Content.ReadAsStringAsync(); responseBodyAsText = result.Result; // 正则提取server_id jsonstr = Regex.Match(responseBodyAsText, "(?s)SQ.GameTopNav.init(?<value>.*?)\\)") .Groups["value"].Value.Replace("(", ""); if (string.IsNullOrEmpty(jsonstr)) { return(false); } string serverID = Regex.Match(jsonstr, "(?s)serverId: \"(?<value>.*?)\"").Groups["value"].Value; if (string.IsNullOrEmpty(serverID)) { return(false); } string jumpURL2 = gameMainURL + string.Format("/controller/enter_game.php?game_id={0}&sid={1}&server_id={2}&showlogintype=1&yksw_from=0", serverInfo.GAME_ID, serverInfo.SID, serverID); // status=302 获取服务器真实URL task = client.GetAsync(new Uri(jumpURL2)); // task.Result.E(); response = task.Result; Uri realURL = task.Result.Headers.Location; result = response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.Found) { return(false); } task = client.GetAsync(realURL); task.Result.EnsureSuccessStatusCode(); response = task.Result; result = response.Content.ReadAsStringAsync(); // 获取IP地址 端口号 jsonstr = Regex.Match(result.Result, "(?s)window.YOLK7_CLIENT_ENV = (?<value>.*?);").Groups["value"].Value; if (string.IsNullOrEmpty(jsonstr)) { return(false); } string port = Regex.Match(jsonstr, "(?s)port:(?<value>.*?)\"").Groups["value"].Value.Replace("\"", "").Trim(); //Port = port; //webServerInfo serverInfo1 = (webServerInfo)JsonManager.JsonToObject(jsonstr, typeof(webServerInfo)); //if (serverInfo1 == null) //{ // return false; //} Port = Convert.ToInt32(port); // retobj2.serverId; return(true); } else { errMsg = HttpUtility.UrlDecode(retobj.message);//UnicodeToString(retobj.message); } } catch (Exception ex) { ConsoleLog.Instance.writeInformationLog("ErrMsg=" + ex.Message); } return(false); }