Almost Finished.
Now this system can fetch card data, parsing them. We will add comparing to it later.
This commit is contained in:
parent
5a26adf229
commit
b1170f6d36
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@ bin/
|
|||||||
obj/
|
obj/
|
||||||
temp/
|
temp/
|
||||||
data/
|
data/
|
||||||
|
result/
|
||||||
*.cbp
|
*.cbp
|
||||||
*.layout
|
*.layout
|
||||||
*.depend
|
*.depend
|
||||||
|
144
main.cpp
144
main.cpp
@ -1,7 +1,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -12,11 +15,55 @@
|
|||||||
|
|
||||||
using namespace std;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void prepareCookie()
|
void prepareCookie()
|
||||||
{
|
{
|
||||||
system(R"(curl -v "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)");
|
system(R"(curl -v "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)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _fetched_cookie=false;
|
||||||
|
|
||||||
|
void BeginNetwork()
|
||||||
|
{
|
||||||
|
if(!_fetched_cookie)
|
||||||
|
{
|
||||||
|
prepareCookie();
|
||||||
|
_fetched_cookie=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RunCommand(string stuNumber,string outputFilename)
|
void RunCommand(string stuNumber,string outputFilename)
|
||||||
{
|
{
|
||||||
string cmd=R"(curl -v "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" > )" ;
|
string cmd=R"(curl -v "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" > )" ;
|
||||||
@ -28,11 +75,29 @@ void RunCommand(string stuNumber,string outputFilename)
|
|||||||
cmd=cmd.replace(cmd.find(target),target.size(),stuNumber);
|
cmd=cmd.replace(cmd.find(target),target.size(),stuNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd=cmd+outputFilename;
|
cmd.append(outputFilename);
|
||||||
|
|
||||||
system(cmd.c_str());
|
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("执行查询.. StuID=%s\n",stuCode.c_str());
|
||||||
|
RunCommand(stuCode,Filename);
|
||||||
|
|
||||||
|
/// Delay 3~6 seconds
|
||||||
|
this_thread::sleep_for(chrono::seconds(rand()%3+3));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HEAD_STR "15080901"
|
||||||
|
#define NUM 40
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("初始化随机数...\n");
|
printf("初始化随机数...\n");
|
||||||
@ -41,24 +106,75 @@ int main()
|
|||||||
system("mkdir temp");
|
system("mkdir temp");
|
||||||
printf("创建数据文件夹...\n");
|
printf("创建数据文件夹...\n");
|
||||||
system("mkdir data");
|
system("mkdir data");
|
||||||
|
|
||||||
printf("准备Cookies文件...\n");
|
printf("准备Cookies文件...\n");
|
||||||
prepareCookie();
|
BeginNetwork();
|
||||||
|
|
||||||
printf("开始查询...\n");
|
printf("开始查询...\n");
|
||||||
for(int i=0;i<40;i++)
|
for(int i=0;i<NUM;i++)
|
||||||
{
|
{
|
||||||
char buff[1024];
|
RemoteQuery(HEAD_STR,i+1);
|
||||||
sprintf(buff,"15080801%02d",i+1);
|
|
||||||
string stuCode(buff);
|
|
||||||
sprintf(buff,"data/%d.txt",i+1);
|
|
||||||
string Filename(buff);
|
|
||||||
|
|
||||||
printf("查询第 %d of %d\n",i+1,40);
|
|
||||||
RunCommand(stuCode,Filename);
|
|
||||||
|
|
||||||
this_thread::sleep_for(chrono::seconds(rand()%3+1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("查询完成.\n");
|
printf("查询完成,开始解析...\n");
|
||||||
|
vector<double> vec;
|
||||||
|
queue<int> needrefetch;
|
||||||
|
|
||||||
|
for(int i=0;i<NUM;i++)
|
||||||
|
{
|
||||||
|
printf("解析第 %d of %d\n",i+1,NUM);
|
||||||
|
double val=LocalParse(i+1);
|
||||||
|
if(val==-2)
|
||||||
|
{
|
||||||
|
needrefetch.push(i+1);
|
||||||
|
}
|
||||||
|
vec.push_back(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("检测重新获取...\n");
|
||||||
|
if(!needrefetch.empty())
|
||||||
|
{
|
||||||
|
printf("有%u条数据需要重新获取...\n",needrefetch.size());
|
||||||
|
|
||||||
|
printf("正在重新获取...\n");
|
||||||
|
|
||||||
|
BeginNetwork();
|
||||||
|
while(!needrefetch.empty())
|
||||||
|
{
|
||||||
|
int id=needrefetch.front();
|
||||||
|
needrefetch.pop();
|
||||||
|
printf("重新获取ID: %d\n",id);
|
||||||
|
RemoteQuery(HEAD_STR,id);
|
||||||
|
double val=LocalParse(id);
|
||||||
|
if(val==-2)
|
||||||
|
{
|
||||||
|
printf("重新获取ID: %d 失败.\n",id);
|
||||||
|
needrefetch.push(id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("重新获取ID: %d 成功.\n",id);
|
||||||
|
vec.at(id-1)=val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("解析完成.\n");
|
||||||
|
|
||||||
|
string fname;
|
||||||
|
printf("请输入保存文件名称...\n");
|
||||||
|
getline(cin,fname);
|
||||||
|
printf("正在保存到 %s\n",fname.c_str());
|
||||||
|
|
||||||
|
ofstream ofs(fname);
|
||||||
|
for(size_t i=0;i<vec.size();i++)
|
||||||
|
{
|
||||||
|
ofs<<i+1<<" "<<vec.at(i)<<endl;
|
||||||
|
}
|
||||||
|
ofs.flush();
|
||||||
|
|
||||||
|
printf("保存成功.\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user