int WriteToLog(char* str);
void postdata(int flag)
{
GetMacAddress(g_strMacAdress);
USES_CONVERSION;
char *pMac=T2A(g_strMacAdress);
char fullAdress[MAX_PATH]={0};
if
(flag==1)
{
strcat(fullAdress,
"&name=钟欣桐"
);
}
else
if
(flag==2)
{
strcat(fullAdress,
"&name=张柏芝"
);
}
else
if
(flag==3)
{
strcat(fullAdress,
"&name=陈文媛"
);
}
else
if
(flag==4)
{
strcat(fullAdress,
"&name=颜颖思"
);
}
else
if
(flag==5)
{
strcat(fullAdress,
"&name=章子怡"
);
}
else
{
strcat(fullAdress,“&name=陈冠希”);
}
CURL *curl;
CURLcode res;
//FILE
*fptr;
struct curl_slist *http_header = NULL;
//if
((fptr = fopen(FILENAME,
"w"
)) == NULL) {
//
fprintf(stderr,
"fopen file error: %s\n"
, FILENAME);
//
exit
(1);
//
}
curl = curl_easy_init();
if
(flag==0)
{
curl_easy_setopt(curl, CURLOPT_URL, POSTURL2);
}
else
{
curl_easy_setopt(curl, CURLOPT_URL, POSTURL);
}
WriteToLog(
"post函数内部"
);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fullAdress);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
WriteToLog(
"post函数退出"
);
}
int WriteToLog(char* str)
{
FILE* log;
log = fopen(LOGFILE,
"a+"
);
if
(log == NULL){
OutputDebugString(L
"Log file open failed."
);
return
-1;
}
fprintf(log,
"%s\n"
, str);
fclose(log);
return
0;
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////post
部分限制
///////////////////////////
//
软件是否初次运行增加注册表项
BOOL IsFirstRun()
{
HKEY hKey;
LPCTSTR lpRun=_T(
"Software\\Microsoft\\Windows\\CurrentVersion\\test"
);
long lRet = RegOpenKeyEx(HKEY_CURRENT_USER, lpRun, 0, KEY_WRITE, &hKey);
if
(lRet==ERROR_SUCCESS)
{
//g_firstrun
=
false
;
return
false
;
}
else
{
//
第一次运行
if
(ERROR_SUCCESS==RegCreateKey(HKEY_CURRENT_USER,_T(
"Software\\Microsoft\\Windows\\CurrentVersion\\test"
),&hKey))
{
DWORD nCount=1;
RegSetValueEx(hKey,_T(
"tj"
),0,REG_DWORD,(BYTE*)&nCount,sizeof(DWORD));
//
创建当前时间、日期
TCHAR szCurrentDataTime[MAX_PATH]={0};
SYSTEMTIME systm;
GetLocalTime(&systm);
wsprintf(szCurrentDataTime,_T(
"%4d年%d月%d日"
),systm.wYear,systm.wMonth,systm.wDay);
lRet=RegSetValueEx(hKey,L
"data"
,0,REG_SZ,(BYTE*)szCurrentDataTime,/*lstrlen(szCurrentDataTime)*sizeof(TCHAR)*
/MAX_PATH
);
if
(lRet==ERROR_SUCCESS)
{
WriteToLog(
"成功"
);
}
else
{
WriteToLog(
"失败"
);
}
RegCloseKey(hKey);
return
true
;
}
else
{
return
false
;
}
}
}
BOOL tjLimited()
{
IsFirstRun();
//
创建当前时间、日期
TCHAR szCurrentDataTime[MAX_PATH]={0};
SYSTEMTIME systm;
GetLocalTime(&systm);
wsprintf(szCurrentDataTime,_T(
"%4d年%d月%d日"
),systm.wYear,systm.wMonth,systm.wDay);
HKEY hKey;
TCHAR szData[MAX_PATH]={0};
DWORD nCount=0;
DWORD dType=REG_SZ;
DWORD dTypecount=REG_DWORD;
DWORD dReturn=MAX_PATH;
LPCTSTR lpRun=_T(
"Software\\Microsoft\\Windows\\CurrentVersion\\test"
);
long lRet = RegOpenKeyEx(HKEY_CURRENT_USER, lpRun, 0, KEY_WRITE|KEY_READ, &hKey);
if
(lRet==ERROR_SUCCESS)
{
//
继续下层
lRet=RegQueryValueEx(hKey,L
"tj"
,NULL,(LPDWORD)(&dTypecount),(LPBYTE)&nCount,&dReturn);
if
(lRet==ERROR_SUCCESS)
{
dReturn=MAX_PATH;
lRet=RegQueryValueEx(hKey,L
"data"
,NULL,&dType,(LPBYTE)szData,&dReturn);
DWORD n=GetLastError();
if
(lRet==ERROR_SUCCESS)
{
//WriteToLog
(
"chenggong"
);
}
else
{
//WriteToLog
(
"shibai"
);
}
//
自增
++nCount;
RegSetValueEx(hKey,L
"tj"
,0,REG_DWORD,(BYTE*)&nCount,sizeof(DWORD));
if
(lstrcmp(szData,szCurrentDataTime))
{
WriteToLog(
"位置2"
);
lstrcpy(szData,szCurrentDataTime);
nCount=0;
//
更新注册表
DWORD count=2;
RegSetValueEx(hKey,L
"data"
,0,REG_SZ,(BYTE*)szCurrentDataTime,lstrlen(szCurrentDataTime)*sizeof(TCHAR*));
RegSetValueEx(hKey,L
"tj"
,0,REG_DWORD,(BYTE*)&count,sizeof(DWORD));
return
true
;
}
else
{
//
只判断点击次数
if
(nCount>2)
{
WriteToLog(
"超过次数啦"
);
return
false
;
}
else
{
///////////////////////////////////
日志打印
////////////
//char
log[10]={0};
//sprintf
(log,
"%d"
,nCount);
//char
fulllog[50]={0};
//strcpy
(fulllog,
"post数据"
);
//strcat
(fulllog,log);
//WriteToLog
(fulllog);
////////////////////////////////////////////////////////
return
true
;
}
}
}
else
{
//
没有内容,进行添加
//DWORD
n=GetLastError();
WriteToLog(
"位置1"
);
DWORD count=1;
RegSetValueEx(hKey,L
"data"
,0,REG_SZ,(BYTE*)szCurrentDataTime,lstrlen(szCurrentDataTime)*sizeof(TCHAR*));
RegSetValueEx(hKey,L
"tj"
,0,REG_DWORD,(BYTE*)&count,sizeof(DWORD));
return
true
;
}
}
}
int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR pszCmdLine, int) {
while
(1)
{
if
(tjLimited())
{
WriteToLog(
"post开始了"
);
postdata(0);
}
Sleep(10000);
}
return
(0);
}