This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
CardWatcher/main.cpp

187 lines
4.5 KiB
C++
Raw Normal View History

2017-03-22 11:24:38 +08:00
#include <iostream>
#include <fstream>
#include <sstream>
2017-03-22 13:08:30 +08:00
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
2017-03-22 13:08:30 +08:00
#include <thread>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
2017-03-22 11:24:38 +08:00
using namespace std;
double parseValue(string Filename)
{
printf("Filename : %s\n",Filename.c_str());
ifstream ifs(Filename);
string temp,s;
while(getline(ifs,temp)) s.append(temp);
printf("%s\n",s.c_str());
string target="amt";
string::size_type ans=s.find(target);
printf("Found in ... %u\n",ans);
if(ans==string::npos)
{
return -2;
}
istringstream istr(s.substr(ans+7));
double a=-1;
istr>>a;
return a;
}
double LocalParse(int id)
{
char buff[1024];
sprintf(buff,"data/%d.txt",id);
string Filename(buff);
return parseValue(Filename);
}
2017-03-22 13:08:30 +08:00
void prepareCookie()
{
system(R"(curl -s "life.ccb.com/tran/WCCMainPlatV5?CCB_IBSVersion=V5&SERVLET_NAME=WCCMainPlatV5&TXCODE=100119&USERID=&SKEY=" --user-agent "Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1" -c temp/cookie1.txt > temp/step1.txt)");
2017-03-22 13:08:30 +08:00
}
bool _fetched_cookie=false;
void BeginNetwork()
{
if(!_fetched_cookie)
{
prepareCookie();
_fetched_cookie=true;
}
}
2017-03-22 13:08:30 +08:00
void RunCommand(string stuNumber,string outputFilename)
{
string cmd=R"(curl -s "life.ccb.com/tran/WCCMainPlatV5?CCB_IBSVersion=V5&SERVLET_NAME=WCCMainPlatV5&isAjaxRequest=true&TXCODE=JF1103&OPUN_COD=370200&MERCHANT=#STUCODE#100010&COMM=#STUCODE#&BANK_COD=370000&BIll_CODE=100010&PAY_TYPE=11&BILL_FLAG=0&BIll_MERCHANT=600007&BANK_NAME=%E5%B1%B1%E4%B8%9C%E7%9C%81&OPUN_NAME=%E9%9D%92%E5%B2%9B%E5%B8%82&MERCHANT_NAME=%E9%9D%92%E5%B2%9B%E7%A7%91%E6%8A%80%E5%A4%A7%E5%AD%A6%E6%A0%A1%E5%9B%AD%E5%8D%A1%E5%85%85%E5%80%BC&BILL_TYPE=2&BRAN_NO=371000000&BILL_ITEM=01013&BILL_NAME=IC%E5%8D%A1%E3%80%81%E8%81%94%E5%90%8D%E5%8D%A1%E5%85%85%E5%80%BC&RE1CON=&RE2CON=" --user-agent "Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1" -b "temp/cookie1.txt" > )" ;
2017-03-22 13:08:30 +08:00
string target="#STUCODE#";
while( cmd.find(target)!= string::npos )
{
cmd=cmd.replace(cmd.find(target),target.size(),stuNumber);
}
cmd.append(outputFilename);
2017-03-22 13:08:30 +08:00
system(cmd.c_str());
}
void RemoteQuery(string PreCode,int ID)
{
char buff[1024];
sprintf(buff,"%s%02d",PreCode.c_str(),ID);
string stuCode(buff);
sprintf(buff,"data/%d.txt",ID);
string Filename(buff);
printf("ִ<EFBFBD>в<EFBFBD>ѯ.. StuID=%s\n",stuCode.c_str());
RunCommand(stuCode,Filename);
/// Delay 1~4 seconds
this_thread::sleep_for(chrono::seconds(rand()%3+1));
}
#define HEAD_STR "15080901"
#define NUM 40
2017-03-22 11:24:38 +08:00
int main()
{
2017-03-22 13:08:30 +08:00
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\n");
srand(time(NULL));
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>..\n");
system("mkdir temp");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>...\n");
system("mkdir data");
2017-03-22 13:08:30 +08:00
printf("׼<EFBFBD><EFBFBD>Cookies<EFBFBD>ļ<EFBFBD>...\n");
BeginNetwork();
2017-03-22 13:08:30 +08:00
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ѯ...\n");
for(int i=0;i<NUM;i++)
{
RemoteQuery(HEAD_STR,i+1);
}
printf("<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>...\n");
vector<double> vec;
queue<pair<int,int>> needrefetch;
for(int i=0;i<NUM;i++)
2017-03-22 13:08:30 +08:00
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d of %d\n",i+1,NUM);
double val=LocalParse(i+1);
if(val==-2)
{
needrefetch.push(make_pair(i+1,0));
}
vec.push_back(val);
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡ...\n");
if(!needrefetch.empty())
{
printf("<EFBFBD><EFBFBD>%u<><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>»<EFBFBD>ȡ...\n",needrefetch.size());
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡ...\n");
2017-03-22 13:08:30 +08:00
BeginNetwork();
while(!needrefetch.empty())
{
pair<int,int> pack=needrefetch.front();
needrefetch.pop();
int id=pack.first;
printf("<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡID: %d\n",id);
RemoteQuery(HEAD_STR,id);
double val=LocalParse(id);
if(val==-2)
{
printf("<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡID: %d ʧ<><CAA7>.\n",id);
if(pack.second<3)
{
printf("<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡʧ<EFBFBD>ܶ<EFBFBD><EFBFBD><EFBFBD>,ֹͣ<CDA3><D6B9>ȡID: %d.\n",id);
needrefetch.push(make_pair(id,pack.second+1));
}
}
else
{
printf("<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡID: %d <20>ɹ<EFBFBD>.\n",id);
vec.at(id-1)=val;
}
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n");
string fname;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\n");
getline(cin,fname);
printf("<EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><EFBFBD>浽 %s\n",fname.c_str());
2017-03-22 13:08:30 +08:00
ofstream ofs(fname);
for(size_t i=0;i<vec.size();i++)
{
ofs<<i+1<<" "<<vec.at(i)<<endl;
2017-03-22 13:08:30 +08:00
}
ofs.flush();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>.\n");
2017-03-22 13:08:30 +08:00
2017-03-22 11:24:38 +08:00
return 0;
}