public static Image GetVcodeImg(string resulthtml, string qqhaoma, string cookie, ref string sig) { string pt_verifysession_v1 = QQSpaceHelper.GetStringMid(resulthtml, "'1','", "','"); HttpHelper http_A = new HttpHelper(); HttpItem item_A = new HttpItem() { URL = "http://captcha.qq.com/cap_union_show?clientype=2&uin=" + qqhaoma + "&aid=549000912&cap_cd=" + pt_verifysession_v1 + "&pt_style=40&0.4430906427668041", IsToLower = false, //得到的HTML代码是否转成小写 可选项默认转小写 Cookie = "", //字符串Cookie 可选项 Referer = "", //来源URL 可选项 Postdata = "", //Post数据 可选项GET时不需要写 Timeout = 100000, //连接超时时间 可选项默认为100000 ReadWriteTimeout = 30000, //写入Post数据超时时间 可选项默认为30000 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", //用户的浏览器类型,版本,操作系统 可选项有默认值 ContentType = "text/html", //返回类型 可选项有默认值 Allowautoredirect = false, //是否根据301跳转 可选项 //CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数 //Connectionlimit = 1024,//最大连接数 可选项 默认为1024 ProxyIp = "", //代理服务器ID 可选项 不需要代理 时可以不设置这三个参数 //ProxyPwd = "123456",//代理服务器密码 可选项 //ProxyUserName = "******",//代理服务器账户名 可选项 ResultType = ResultType.String }; HttpResult result_A = http_A.GetHtml(item_A); sig = result_A.Html; sig = QQSpaceHelper.GetStringMid(sig, "var g_vsig = \"", "\";"); //取出验证码地址 HttpHelper http_code = new HttpHelper(); HttpItem item_code = new HttpItem() { URL = "http://captcha.qq.com/getimgbysig?clientype=2&uin=" + qqhaoma + "&aid=549000912&cap_cd=" + pt_verifysession_v1 + "&pt_style=40&0.018421005630953724&rand=0.24943880787089034&sig=" + sig, IsToLower = false, //得到的HTML代码是否转成小写 可选项默认转小写 Cookie = cookie, //字符串Cookie 可选项 Referer = "", //来源URL 可选项 Postdata = "", //Post数据 可选项GET时不需要写 Timeout = 100000, //连接超时时间 可选项默认为100000 ReadWriteTimeout = 30000, //写入Post数据超时时间 可选项默认为30000 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", //用户的浏览器类型,版本,操作系统 可选项有默认值 ContentType = "text/html", //返回类型 可选项有默认值 Allowautoredirect = false, //是否根据301跳转 可选项 //CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数 //Connectionlimit = 1024,//最大连接数 可选项 默认为1024 ProxyIp = "", //代理服务器ID 可选项 不需要代理 时可以不设置这三个参数 //ProxyPwd = "123456",//代理服务器密码 可选项 //ProxyUserName = "******",//代理服务器账户名 可选项 ResultType = ResultType.Byte }; HttpResult result_code = http_code.GetHtml(item_code); Image img = byteArrayToImage(result_code.ResultByte); return(img); }
/// <summary> /// 取验证码 /// </summary> private static string GetVerification_Code(string qqhaoma, string cookie, ref string salt, ref bool isver, ref string pt_verifysession_v1, ref string sig) { // AllocConsole(); HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://check.ptlogin2.qq.com/check?regmaster=&pt_tea=2&pt_vcode=1&uin=" + qqhaoma + "&appid=549000912&js_ver=10165&js_type=1&login_sig=-TLaeVf9AOagLEQm323nKPYN*FyHmJmDAWjXxdV9ej7KL0uC3bbCSsvM9uPuRyyV&u1=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&r=0.3361908566720933&pt_uistyle=40", //URL 必需项 Method = "get", //URL 可选项 默认为Get IsToLower = false, //得到的HTML代码是否转成小写 可选项默认转小写 Cookie = cookie, //字符串Cookie 可选项 Referer = "", //来源URL 可选项 Postdata = "", //Post数据 可选项GET时不需要写 Timeout = 100000, //连接超时时间 可选项默认为100000 ReadWriteTimeout = 30000, //写入Post数据超时时间 可选项默认为30000 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", //用户的浏览器类型,版本,操作系统 可选项有默认值 ContentType = "text/html", //返回类型 可选项有默认值 Allowautoredirect = false, //是否根据301跳转 可选项 //CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数 //Connectionlimit = 1024,//最大连接数 可选项 默认为1024 ProxyIp = "",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数 //ProxyPwd = "123456",//代理服务器密码 可选项 //ProxyUserName = "******",//代理服务器账户名 可选项 ResultType = ResultType.String }; HttpResult result = http.GetHtml(item); string html = result.Html; string Cookie_A = result.Cookie; string code = QQSpaceHelper.GetStringMid(html, "'0','", "','"); salt = "\\" + QQSpaceHelper.GetStringMid(html, "','\\", "','"); pt_verifysession_v1 = QQSpaceHelper.GetStringRight(html, code); pt_verifysession_v1 = QQSpaceHelper.GetStringRight(pt_verifysession_v1, "\\"); pt_verifysession_v1 = QQSpaceHelper.GetStringMid(pt_verifysession_v1, "','", "','"); string Verification_Code_A = code; #region 判断文本或图片验证码 if (code != "_checkVC('1") { isver = false; //textBox2.Text = code; return(code); //textBox2.ReadOnly = true; } else { isver = true; Image img = QQSpaceHelper.GetVcodeImg(html, qqhaoma, cookie, ref sig); string vcode = Weibo.Common.Dama2.GetVcode(img); return(vcode); } #endregion //System.Console.WriteLine("pt_verifysession_v1:" + pt_verifysession_v1 + "sig" + sig); }
public static string GetJCookie(string cookie) { string skey = QQSpaceHelper.GetStringMid(cookie, "skey=", "';"); string p_skey = ""; string uin = ""; string p_uin = ""; string pt4_token = ""; string pt2gguin = ""; HttpHelper1.GetStringInTwoKeyword(cookie, ref skey, "skey=@", ";", 0); HttpHelper1.GetStringInTwoKeyword(cookie, ref p_skey, "p_skey=", ";", 0); HttpHelper1.GetStringInTwoKeyword(cookie, ref uin, "uin=", ";", 0); HttpHelper1.GetStringInTwoKeyword(cookie, ref p_uin, "p_uin=", ";", 0); HttpHelper1.GetStringInTwoKeyword(cookie, ref pt4_token, "pt4_token=", ";", 0); HttpHelper1.GetStringInTwoKeyword(cookie, ref pt2gguin, "pt2gguin=", ";", 0); string jcookie = "uin=" + uin + "; skey=" + skey + ";pt4_token=" + pt4_token + "; p_uin=" + p_uin + "; p_skey=" + p_skey + "; "; return(jcookie); }
public static CookieContainer Login(string qqhaoma, string password) { string cookie = ""; string salt = ""; bool isVer = false; string pt_verifysession_v1 = ""; string sig = ""; CookieContainer spacecc = new CookieContainer(); string URL = "http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&pt_qr_app=手机QQ空间&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html";//URL 必需项 string resulthtml = HttpHelper1.SendDataByGET(URL, ref spacecc); string Login_sig = QQSpaceHelper.GetStringMid(resulthtml, "pt_login_sig=", ";"); string code = GetVerification_Code(qqhaoma, cookie, ref salt, ref isVer, ref pt_verifysession_v1, ref sig); spacecc = LoginQQspace(qqhaoma, password, code, salt, isVer, pt_verifysession_v1, Login_sig, sig); return(spacecc); }
public void StartSend(object parms) { while (true) { SetSpaceeButtonStatus(true); AppenSpaceCmd("开始发布说说"); #region 登录账号并初始化 string[] qqlist = File.ReadAllLines("qq.txt"); foreach (string qqstr in qqlist) { string[] qq = qqstr.Split(','); string qqhaoma = qq[0]; string password = qq[1]; string nickname = qq[2]; AppenSpaceCmd(qqhaoma + "发布"); string cookiepath = "cookie/" + qqhaoma + ".txt"; string token = ""; if (File.Exists(cookiepath)) { spacecc = CookieHelper.ReadCookieFromFile(cookiepath); token = QQSpaceHelper.GetToken(spacecc, qqhaoma); } int logintime = 0; while (token == "") { logintime++; if (logintime == 10) { AppenSpaceCmd("登录失败,放弃!"); break; } AppenSpaceCmd(nickname + "[" + qqhaoma + "]未登录,正在第" + logintime.ToString() + "次尝试登录!"); spacecc = QQSpaceHelper.Login(qqhaoma, password); CookieHelper.SaveCookie(cookiepath, spacecc); token = QQSpaceHelper.GetToken(spacecc, qqhaoma); } if (token == "") { continue; } AppenSpaceCmd(nickname + "[" + qqhaoma + "]已登录"); string g_tk = QQSpaceHelper.Getgtk(spacecc.GetCookieHeader(new Uri("http://qzone.qq.com")).ToString()); QQHao qqhao = new QQHao(); qqhao.Qqhaoma = qqhaoma; qqhao.Password = password; qqhao.G_tk = g_tk; qqhao.Token = token; string result = QQSpaceHelper.GetUserInfo(qqhao, spacecc); #endregion DirectoryInfo TheFolder = new DirectoryInfo("待发布"); DirectoryInfo nextFolder = TheFolder.GetDirectories()[0];//发布选品库第一条 AppenSpaceCmd(nickname + "[" + qqhaoma + "]发布正文:" + nextFolder.Name); ArrayList imgs = new ArrayList(); foreach (FileInfo NextFile in nextFolder.GetFiles()) { if (NextFile.Extension == ".jpg" || NextFile.Extension == ".gif") { AppenSpaceCmd("上传图片"); UploadImageData imagedata = QQSpaceHelper.UploadPic(NextFile.FullName, spacecc, qqhao); imgs.Add(imagedata); } } string content = " "; if (!IsGuidByReg(nextFolder.Name)) { content = nextFolder.Name; } QQSpaceHelper.SendShuoshuoWithPic(content, imgs, spacecc, qqhao); Directory.Move(nextFolder.FullName, "已发布/" + nextFolder.Name); AppenSpaceCmd(nickname + "[" + qqhaoma + "]发布完成"); } int jiange = Convert.ToInt32(this.nud_spacejiange.Value); AppenSpaceCmd("此次发布完毕,等待" + jiange.ToString() + "分钟"); Thread.Sleep(jiange * 60 * 1000); } }
/// <summary> /// QQ空间登陆 /// </summary> /// <param name="u">账号</param> /// <param name="p">密码</param> /// <param name="code">验证码</param> /// <returns></returns> private static CookieContainer LoginQQspace(string u, string p, string code, string salt, bool isver, string pt_verifysession_v1, string Login_sig, string sig) { string html; string password; string v; string newcode; string Loginstatus;//登陆状态 if (!isver) { password = QQSpaceHelper.QQspace_password(p, salt, code); CookieContainer spacecc = new CookieContainer(); string url = "http://ptlogin2.qq.com/login?u=" + u + "&verifycode=" + code + "&pt_vcode_v1=0&pt_verifysession_v1=" + pt_verifysession_v1 + "&p=" + password + "&pt_randsalt=0&u1=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=2-6-1466753336279&js_ver=10165&js_type=1&login_sig=" + Login_sig + "&pt_uistyle=40&aid=549000912&daid=5&";//URL 必需项 string resulthtml = HttpHelper1.SendDataByGET(url, ref spacecc); string cookieAddres = QQSpaceHelper.GetStringMid(resulthtml, "ptuiCB('0','0','", "','"); HttpHelper1.SendDataByGET(cookieAddres, ref spacecc); return(spacecc); //HttpHelper http_A = new HttpHelper(); //HttpItem item_A = new HttpItem() //{ // URL = cookieAddres,//URL 必需项 // Method = "get",//URL 可选项 默认为Get // IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写 // Cookie = Cookie_A,//字符串Cookie 可选项 // Referer = "",//来源URL 可选项 // Postdata = "",//Post数据 可选项GET时不需要写 // Timeout = 100000,//连接超时时间 可选项默认为100000 // ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000 // UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值 // ContentType = "text/html",//返回类型 可选项有默认值 // Allowautoredirect = false,//是否根据301跳转 可选项 // //CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数 // //Connectionlimit = 1024,//最大连接数 可选项 默认为1024 // ProxyIp = "",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数 // //ProxyPwd = "123456",//代理服务器密码 可选项 // //ProxyUserName = "******",//代理服务器账户名 可选项 // ResultType = ResultType.String //}; //HttpResult result_A = http_A.GetHtml(item_A); //string spaceCookie = result_A.Cookie; //return spaceCookie; //HttpHelper http_B = new HttpHelper(); //HttpItem item_B = new HttpItem() //{ // URL = "http://user.qzone.qq.com/3213257524",//URL 必需项 // Method = "get",//URL 可选项 默认为Get // IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写 // Cookie = Cookie_A,//字符串Cookie 可选项 // Referer = "",//来源URL 可选项 // Postdata = "",//Post数据 可选项GET时不需要写 // Timeout = 100000,//连接超时时间 可选项默认为100000 // ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000 // UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值 // ContentType = "text/html",//返回类型 可选项有默认值 // Allowautoredirect = true,//是否根据301跳转 可选项 // //CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数 // //Connectionlimit = 1024,//最大连接数 可选项 默认为1024 // ProxyIp = "",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数 // //ProxyPwd = "123456",//代理服务器密码 可选项 // //ProxyUserName = "******",//代理服务器账户名 可选项 // ResultType = ResultType.String //}; //HttpResult result_B = http_B.GetHtml(item_B); //Cookie = Cookie.Replace(",", ""); //return Cookie; //File.WriteAllText("qqcookie.txt", spaceCookie); } else { CookieContainer spacecc = new CookieContainer(); string URL = "http://captcha.qq.com/cap_union_verify_new?clientype=2&uin=" + u + "&aid=549000912&cap_cd=" + pt_verifysession_v1 + "&pt_style=40&0.018421005630953724&rand=0.3566402584289032&capclass=0&sig=" + sig + "&collect=QJ8EZyxDDp69G3zb59eR-Mnz-5F08BdC-P9fzPDRe-BaZ5GqAriI5D2LH0DHscZ4JCS-yYz5_HPyVoopkm2gwe9Mgziaxhrp9doZoY9CFl7k2rbzaiegdx-eTyE3IVQkNwRTACxDHBRg3mHxM0-gf_MAAs4H7ieIfH1vgxORw0P-XrwPsqwKLhQiJFVa6KM4Gt8jF1BKJe6_WbSdP495lIa1FddYoi8yBYIdigtYuCC8zBFB98WfItynhsdFoMN9U9utX9eXltsFSBAqfiDPwChTe0zVG7cIKo38wAvQjE6ejZlqekFBa2Cl_mTDzg6QrGv_At2frSgH1ZdQIHO5ADsCa1u_Y552KotzqcDX8kLdzQxDXG4E-wteroUKZ5WG-zkQ89xCT9aWegigU4gvHrFHG9xpxTAnVA_mxaewMsUxqFOhRafPCHzyIw2eaTQl7D7AopK4WdMU3EJ8gLoRdDEAS7EXYIsqy0GWUl3m33QuJw1ocsnp42WG_V2pAbN-8PIqEoS-Z86Hj2kKQ-fdVMMVGj0BOo5FfNQaUHh6CvnPqwwiVGlUGKy9Ih_WC7G8312sN55MKWbJOONgZhrJxZbf42xks4YrlXDyvfMNe_TKzkW_jyHKJQ43PLmtvCqkQ_vslP2BCZwAEVAc9Xwd2K-y694nxK6EhVtclCC_m7fkbQWv19_uZoxIEczOqlvv-0icf_xQlzX9nzgYmgbLGsTLzW7H5YBYe7Sd-Udi2i_zW3p05ZL5Sr_IQpJpSRkckTLDi-4L5DX0aGVq_xblhotlZ4J7EpoyekA1uyMTkz7OIyVa8bAlFO7WOUwOJ5m8Kb65yv9Vsrb5bx8w-3CWvfBV9Nz4RX0QL_v-ISGHcwfN3cgJ6nUXZ6xXHpMYVZZBA15U-t4nVHGg0dagA7HAPcWi9Am-ScFah4o7xUMpJ5pTFfbizCHKVQZ42BMT56mC&ans=" + code;//URL 必需项 string resulthtml = HttpHelper1.SendDataByGET(URL, ref spacecc); v = QQSpaceHelper.GetStringMid(resulthtml, "\"ticket\" : \"", "\" , \""); newcode = QQSpaceHelper.GetStringMid(resulthtml, "\"randstr\" : \"", "\" , \""); password = QQSpaceHelper.QQspace_password(p, salt, newcode); URL = "http://ptlogin2.qq.com/login?u=" + u + "&verifycode=" + newcode + "&pt_vcode_v1=1&pt_verifysession_v1=" + v + "&p=" + password + "&pt_randsalt=0&u1=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=2-16-1466756588355&js_ver=10165&js_type=1&login_sig=ydH8cF-2O0R-QwimXsoVitiSBDo3WLir-zDAh5zEhsu7xGH4pDuGXleaieU8ySM0&pt_uistyle=40&aid=549000912&daid=5&";//URL 必需项 resulthtml = HttpHelper1.SendDataByGET(URL, ref spacecc); string cookieAddres = QQSpaceHelper.GetStringMid(resulthtml, "ptuiCB('0','0','", "','"); HttpHelper1.SendDataByGET(cookieAddres, ref spacecc); return(spacecc); } //判断登录是否成功 //Loginstatus = QQSpaceHelper.GetStringMiddle(html, "ptuiCB('", "','0','"); //if (Loginstatus == "0") //{ // Console.Write(QQSpaceHelper.GetStringMiddle(html, "aid=0','0','", "', '") + "\r\n" + QQSpaceHelper.GetStringMid(html, QQSpaceHelper.GetStringMiddle(html, "aid=0','0','", "', '") + "', '", "')")); //} //if (Loginstatus == "7") //{ // Console.Write("验证码错误!"); //} //if (Loginstatus == "3") //{ // Console.Write("账号或密码错误!", "登陆失败"); //} }