Exemple #1
0
int auto_smzdm::smzdm_run()
{
  QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

  network.GetManager().setCookieJar(cookie);

  QString str_url_1 = "http://digi.tech.qq.com/original/pyp/pro.html";

  QUrl url_1(str_url_1);
  HttpParamList header_list1;
  header_list1.push_back(HttpParamItem("Accept",	"application/json, text/javascript, */*; q=0.01"));
  header_list1.push_back(HttpParamItem("Connection","Keep-Alive"));
  header_list1.push_back(HttpParamItem("Accept-Encoding","deflate"));
  header_list1.push_back(HttpParamItem("Accept-Language","zh-cn"));
  header_list1.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"));

  header_list1.push_back(HttpParamItem("Cache-Control", "no-cache"));
  //header_list.push_back(HttpParamItem("X-CSRFToken", "20c9e1fc22618a31cbfcd42218e96dd0"));
  header_list1.push_back(HttpParamItem("Host", "digi.tech.qq.com"));
  header_list1.push_back(HttpParamItem("Referer", "http://digi.tech.qq.com/original/pyp/pro.html"));
  header_list1.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
 
  QNetworkReply* rp1 = network.GetRequest(url_1, header_list1);

   QTime _t;
   _t.start();
 
   bool _timeout = false;
 
   while (rp1 &&!rp1->isFinished())
   {
     QCoreApplication::processEvents();
     if (_t.elapsed() >= TIMEOUT) {
       _timeout = true;
       break;
     }
   }

   QString str = rp1->readAll();
   rp1->deleteLater();

  //投票
  QString str_url1 = "http://panshi.qq.com/v2/vote/10615080/submit";

  QUrl url1(str_url1);

  HttpParamList header_list2;
  header_list2.push_back(HttpParamItem("Accept", "text/html, application/xhtml+xml, */*"));
  header_list2.push_back(HttpParamItem("Referer", "http://digi.tech.qq.com/original/pyp/pro.html"));
  header_list2.push_back(HttpParamItem("Cache-Control","no-cache"));
  header_list2.push_back(HttpParamItem("Connection","keep-alive"));
  //header_list2.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list2.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list2.push_back(HttpParamItem("Host", "panshi.qq.com"));
  header_list2.push_back(HttpParamItem("X-Requested-With", "XMLHttpRequest"));
  header_list2.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded"));
  header_list2.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"));

  HttpParamList post_data;
  post_data.push_back(HttpParamItem("answer","{\"673646\":{\"selected\":[1560346]}}"));
  post_data.push_back(HttpParamItem("callback","parent.AppPlatform.Survey.Digg.ReceiveDiggResult"));
  post_data.push_back(HttpParamItem("format","script"));
  post_data.push_back(HttpParamItem("g_tk","2013"));
  post_data.push_back(HttpParamItem("login","1"));
  post_data.push_back(HttpParamItem("source","1"));
  QNetworkReply* rp2 = network.PostRequest(url1, header_list2, post_data);

  _t.restart();

  _timeout = false;

  while (rp2 &&!rp2->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  str = rp2->readAll();
  rp2->deleteLater();

  cookie->deleteLater();

  return 0;
}
void auto_dirvers_fatie::AutoFatie()
{
	//DailConnector connector("VPN", "ycc1", "111");

	QString adsl = ui.comboBox_adsl->currentText();
	QString account = ui.lineEdit_account->text();
	QString pwd = ui.lineEdit_password->text();

	DailConnector connector(adsl, account, pwd);

	while (!m_control_stop)
	{
		//1. 换VPN
		QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

		network.GetManager().setCookieJar(cookie);

#ifdef NDEBUG
 		emitMsgBar(QStringLiteral("拨号中..."));
 		QString dial_msg;
 		while (!connector.ReConnect(dial_msg))
 		{
 			emitMsgBar(QStringLiteral("拨号中失败:") + dial_msg);
 			WaitforSeconds(3);
 			emitMsgBar(QStringLiteral("拨号中..."));
 		}
 
 		emitMsgBar(QStringLiteral("拨号成功..."));

 		int ncount = 0;
 		while (!GetContent() && ncount < 15)
 		{
 			connector.ReConnect(dial_msg);
 			WaitforSeconds(3);
 			ncount++;
 		}
 
 		if (ncount >= 15)
 		{
 			emitMsgBar(QStringLiteral("网站连接失败...,请检查网络连接"));
 			break;
 		}
#else
//        GetContent();
#endif
		//2. 登录
		bool login_status = false;
		while (m_account_order < m_account_list.size())
		{
			AccountParam ac = m_account_list.at(m_account_order);
			int ndepth = 1;
			if (!Login(ac._id, ac._password, ndepth))
			{
				emitMsgBar(QStringLiteral("登陆失败..."));
				//m_account_row_list.at(m_account_order)->setCheckState(Qt::Checked);
				ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(255, 0, 0, 180));
				m_account_order++;
				continue;
			}
			else
			{
				emitMsgBar(QStringLiteral("登陆成功"));
				m_account_row_list.at(m_account_order)->setCheckState(Qt::Checked);
				ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(0, 255, 0, 180));
				m_account_order++;
				login_status = true;
				break;
			}
		}

		if (!login_status)
		{
			emitMsgBar(QStringLiteral("1、网络无连接 \n 2、号登陆不成功,无法继续"));
			return;
		}

		//3. 发贴
		for (int k = 0; k < m_work_list.size(); ++k)
		{
			if (!m_work_list[k].isFinished())
			{
				if (m_work_list[k].doWork())
				{
					int current_id = m_work_list.at(k).getCurrentIndex();
					QString msg = QStringLiteral("第%1篇,第%2条,已完成").arg(k+1).arg(current_id);
					emitMsgBar(msg);
				}
				else
				{
					int current_id = m_work_list.at(k).getCurrentIndex();
					QString msg = QStringLiteral("第%1篇,第%2条,失败").arg(k+1).arg(current_id);
					emitMsgBar(msg);
				}

				// 如果全部完成,则退出
				if (isAllFinished())
				{
					logout();
					cookie->deleteLater();
					connector.DisConnect();
					emitMsgBar(QStringLiteral("已完成"));
					return;
				}

				//等待
				QElapsedTimer t1;
				t1.start();
				while (t1.elapsed() < m_interval*1000)
					QCoreApplication::processEvents();
			}	
		}

		//4. 登出
		logout();

		//5. 删除cookies
		cookie->deleteLater();
	}

 	connector.DisConnect();
 	emitMsgBar(QStringLiteral("已完成"));
}
bool autobots_toutiao::DoWork()
{
  if (m_comment_order >= m_comment_list.size())
  {
    UpdateData();
  }

  QNetworkCookieJar* cookie = new QNetworkCookieJar();

  network.GetManager().setCookieJar(cookie);

  // 尝试登陆
  bool login_status = false;
  while (m_account_order < m_account_list.size())
  {
    // 获取CSRF TOKEN

    if (!GetContent())
    {
      ui.lineEdit_msg->setText(QStringLiteral("网站连接失败...,请检查网络连接"));
      break;;
    }

    //if (!RequestForLogin())
    //{
    //  ui.lineEdit_msg->setText(QStringLiteral("请求失败..."));
    //  continue;
    //}

    AccountParam ac = m_account_list.at(m_account_order);

    if (!LoginWY(ac._id, ac._password))
    {
      ui.lineEdit_msg->setText(QStringLiteral("登陆失败..."));
      ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(255,0,0, 180));
      m_account_order++;
      continue;
    }
    else
    {
      ui.lineEdit_msg->setText(QStringLiteral("登陆成功"));
      ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(0,255,0, 180));
      m_account_order++;
      login_status = true;
      break;
    }
  }

  if (!login_status)
  {
    ui.lineEdit_msg->setText(QStringLiteral("账号登陆不成功,无法继续"));
    return false;
  }

  QString msg;
  msg.setNum(m_comment_order);

  QElapsedTimer t2;
  t2.start();
  while(t2.elapsed()<1000 )  
    QCoreApplication::processEvents();

  if (DoPostFatie(m_comment_list[m_comment_order]))
  {
    m_comment_item_list[m_comment_order]->setCheckState(Qt::Checked);
    ui.lineEdit_msg->setText(QStringLiteral("第") + msg + QStringLiteral("条,已完成"));
    m_comment_order++;
  }
  else
  {
    ui.lineEdit_msg->setText(QStringLiteral("第") + msg + QStringLiteral("条,失败"));
    m_comment_order++;
  }

  t2.restart();
  while(t2.elapsed()<1000 )  
    QCoreApplication::processEvents();

  if (login_status)
  {
      Logout(m_account_list.at(m_account_order-1)._id);
  }

  cookie->deleteLater();

  return true;
}
void autobots_toutiao::onStart()
{
	// 检查输入
	if (!CheckInput())
	{
		return;
	}

	// 更新界面输入
	UpdateData();

	//   if (m_account_list.size() < m_comment_list.size())
	//   {
	//     QMessageBox::critical(this, QStringLiteral("提示"), QStringLiteral("用户账户太少")); 
	//     return;
	//   }

	control_status = true;

	// 循环发帖
	for (int i = 0; i < m_account_list.size(); ++i)
	{
		if (!control_status)
		{
			break;
		}

		// 尝试登陆

		network.GetManager().clearAccessCache();

		QNetworkCookieJar* cookie = new QNetworkCookieJar();

		network.GetManager().setCookieJar(cookie);

		if (!RequestForRenren())
		{
			ui.lineEdit_msg->setText(QStringLiteral("请求失败..."));
			cookie->deleteLater();
			continue;
		}

		AccountParam ac = m_account_list.at(i);

		if (!AuthorByRenren(ac._id, ac._password))
		{
			ui.lineEdit_msg->setText(QStringLiteral("登陆失败..."));
			ui.tableWidget_account_id->item(i, 0)->setBackgroundColor(QColor(255, 0, 0, 180));
			continue;
		}
		else
		{
			ui.lineEdit_msg->setText(QStringLiteral("登陆成功"));
			ui.tableWidget_account_id->item(i, 0)->setBackgroundColor(QColor(0, 255, 0, 180));
		}

		QElapsedTimer t2;
		t2.start();
		while (t2.elapsed()<1000)
			QCoreApplication::processEvents();

		DoSupport();

		t2.restart();
		while (t2.elapsed()<1000)
			QCoreApplication::processEvents();

		Logout();
		m_device_order++;

		if (m_device_order >= m_devices_list.size())
		{
			m_device_order = 0;
		}

		QString msg;
		msg.setNum(i + 1);

		ui.lineEdit_msg->setText(QStringLiteral("第") + msg + QStringLiteral("次完成"));

		t2.restart();
		while (t2.elapsed()< m_interval * 1000)  // 时间间隔
		{
			ui.lineEdit_msg->setText(QString::number(t2.elapsed()));
			QCoreApplication::processEvents();
		}
	}

	ui.lineEdit_msg->setText(QStringLiteral("已完成"));
}