// 登录weibo.com, 提交POST表单之前需要先获取一些数据 public static PreloginData GetPreloginData() { PreloginData d = new PreloginData(); try { System.Net.WebRequest wReq = System.Net.WebRequest.Create("http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=anNlbnRlciU0MDE2My5jb20%3D&rsakt=mod&checkpin=1&client=ssologin.js(v1.4.11)&_=1381372726787"); System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding("utf-8"))) { String content = reader.ReadLine(); Match matchST = Regex.Match(content, "\"servertime\":[0-9]+"); // 匹配servertime if (matchST.Length > 0) { d.servertime = matchST.Value.Split(':')[1]; } Match matchNonce = Regex.Match(content, "\"nonce\":\"[^\"]+\""); // 匹配nonce if (matchNonce.Length > 0) { var s = matchNonce.Value.Split(':')[1]; d.nonce = s.Substring(1, s.Length - 2); } Match matchRsakv = Regex.Match(content, "\"rsakv\":\"[^\"]+\""); // 匹配rsakv if (matchRsakv.Length > 0) { var rsakv = matchRsakv.Value.Split(':')[1]; d.rsakv = rsakv.Substring(1, rsakv.Length - 2); } Match matchPubKey = Regex.Match(content, "\"pubkey\":\"[^\"]+\""); if (matchPubKey.Length > 0) { var pubkey = matchPubKey.Value.Split(':')[1]; d.pubkey = pubkey.Substring(1, pubkey.Length - 2); } } } catch { return null; } return d; }
// 生成sp private static string createSP(PreloginData preData, string passwd) { ScriptEngine se = new ScriptEngine(ScriptLanguage.JavaScript); object obj = se.Run("getpass", new object[] { passwd, preData.servertime, preData.nonce, preData.pubkey }, ssojs); return obj.ToString(); }