[C++] 纯文本查看 复制代码
void HttpRequest(const WCHAR* wDomain, const WCHAR* wRequest, const WCHAR* wReferer, WCHAR * wCookie, WCHAR* wOutBuffer, int iButterSize, BOOL bPost=FALSE, const WCHAR* szPost = NULL, BOOL bGBK = FALSE, INTERNET_PORT iPort=INTERNET_DEFAULT_HTTPS_PORT,const WCHAR *wContent=NULL)//http发送与接收
{
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
BOOL bResults = FALSE;
HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL;
// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen(szUserAgent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, NULL);
if (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion == 1)//WIN 7 开启TLS1.2
{
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
WinHttpSetOption(hSession, WINHTTP_OPTION_SECURE_PROTOCOLS, &flags, sizeof(flags));
}
// Specify an HTTP server.
if (hSession)
{
hConnect = WinHttpConnect(hSession, wDomain, iPort, 0);
}
// Create an HTTP request handle.
if (hConnect)
{
if (bPost)
hRequest = WinHttpOpenRequest(hConnect, L"POST", wRequest, NULL, L"", WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
else
hRequest = WinHttpOpenRequest(hConnect, L"GET", wRequest, NULL, L"", WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
}
if (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion == 1)//WIN 7 开启TLS1.2
{
DWORD dwSecFlag = SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
SECURITY_FLAG_IGNORE_UNKNOWN_CA |
SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE;
WinHttpSetOption(hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &dwSecFlag, sizeof(dwSecFlag));
}
WCHAR szCookie[4096] = L"Cookie: ";
if (wCookie)
{
lstrcat(szCookie, wCookie);
WinHttpAddRequestHeaders(hRequest, szCookie, lstrlen(szCookie), WINHTTP_ADDREQ_FLAG_ADD);
}
if (wReferer)
{
WCHAR szReferer[4096] = L"Referer: ";
lstrcat(szReferer, wReferer);
WinHttpAddRequestHeaders(hRequest, szReferer, lstrlen(szReferer), WINHTTP_ADDREQ_FLAG_ADD);
}
WCHAR szContentType[1024] = L"Content-Type: ";
if (wContent)
lstrcat(szContentType, wContent);
else
lstrcat(szContentType, L"application/x-www-form-urlencoded;charset=utf-8");
WinHttpAddRequestHeaders(hRequest, szContentType, lstrlen(szContentType), WINHTTP_ADDREQ_FLAG_ADD);
// Send a request.
if (hRequest)
{
if (bPost && szPost != NULL)//有POST
{
int lSize = lstrlen(szPost);
char* szUTF8 = new char[lSize * 2];
if (bGBK)
::WideCharToMultiByte(CP_ACP, NULL, szPost, -1, szUTF8, lSize*2, NULL, NULL);
else
::WideCharToMultiByte(CP_UTF8, NULL, szPost, -1, szUTF8, lSize*2, NULL, NULL);
bResults = WinHttpSendRequest(hRequest, 0, 0, szUTF8, (DWORD)strlen(szUTF8),(DWORD)strlen(szUTF8), 0);
delete[]szUTF8;
}
else
bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
}
// End the request.
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL);
DWORD dErr = GetLastError();
// Keep checking for data until there is nothing left.
size_t i = 0;
char* pszOutBuffer = new char[iButterSize];
ZeroMemory(pszOutBuffer, iButterSize);
if (bResults)
{
do
{
dwSize = 0;
WinHttpQueryDataAvailable(hRequest, &dwSize);
if (!dwSize)
break;
if (int(i + dwSize) > iButterSize)
dwSize = iButterSize - (DWORD)i;
if (WinHttpReadData(hRequest, (LPVOID)&pszOutBuffer[i], dwSize, &dwDownloaded))
{
i = strlen(pszOutBuffer);
}
if (!dwDownloaded)
break;
} while (dwSize != 0);
char* cCharset = xstrstr(pszOutBuffer, "gbk");
if (cCharset == NULL)
cCharset = xstrstr(pszOutBuffer, "gb2312");
char* cHead = xstrstr(pszOutBuffer, "/head");
if (cCharset)
{
if (cCharset < cHead)
MultiByteToWideChar(CP_ACP, 0, pszOutBuffer, -1, wOutBuffer, iButterSize);
else
MultiByteToWideChar(CP_UTF8, 0, pszOutBuffer, -1, wOutBuffer, iButterSize);
}
else
MultiByteToWideChar(CP_UTF8, 0, pszOutBuffer, -1, wOutBuffer, iButterSize);
}
delete[] pszOutBuffer;
if (wCookie)
{
DWORD dwIndex = 0;
WCHAR nCookie[CookieSize];
BOOL bQuerySizeResult;
dwSize = CookieSize * 2;
BOOL bSetCookie = FALSE;
do
{
bQuerySizeResult = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_SET_COOKIE, WINHTTP_HEADER_NAME_BY_INDEX, nCookie, &dwSize, &dwIndex);
if (bQuerySizeResult)
{
bSetCookie = TRUE;
WCHAR* wEnd = lstrstr(nCookie, L"; ");
if (wEnd)
wEnd[0] = L'\0';
lstrcpy(wCookie, nCookie);
lstrcat(wCookie, L"; ");
WCHAR* wEqu = lstrstr(nCookie, L"=");
if (wEqu)
{
wEqu[0] = L'\0';
LPWSTR cStart = szCookie + 8;
while (cStart)
{
LPWSTR cValue = lstrstr(cStart, L"=");
if (cValue > cStart && cValue != NULL)
{
cValue[0] = L'\0';
LPWSTR cName = cStart;
cValue += 1;
cStart = lstrstr(cValue, L"; ");
if (cStart != NULL)
{
cStart[0] = L'\0';
cStart += 2;
}
if (lstrcmp(nCookie, cName) != 0)
{
lstrcat(wCookie, cName);
lstrcat(wCookie, L"=");
lstrcat(wCookie, cValue);
if (cStart != NULL)
lstrcat(wCookie, L"; ");
}
}
else
cStart = NULL;
}
lstrcpy(szCookie + 8, wCookie);
}
}
} while (bQuerySizeResult);
}
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);}
int SignKaFan(WCHAR* wCookie)
{
WCHAR* wOutBuffer = new WCHAR[1024 * 1024];
HttpRequest(L"bbs.kafan.cn", L"/", L"https://bbs.kafan.cn/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
if (lstrstr(wOutBuffer, L"找回密码"))
{
WriteLog(L"Cookie失效 卡饭论坛", TRUE);
delete[]wOutBuffer;
return -99;
}
else
{
WCHAR* wStart = lstrstr(wOutBuffer, L"pper_a");
if (wStart)
{
WCHAR* wLink = lstrstr(wStart, L"formhash");
if (wLink)
{
WCHAR* wLinkEnd = lstrstr(wLink, L"\"");
if (wLinkEnd)
{
wLinkEnd[0] = L'\0';
WCHAR szLink[128] = L"/plugin.php?id=dsu_amupper&ppersubmit=true&";
lstrcat(szLink, wLink);
HttpRequest(L"bbs.kafan.cn", szLink, L"https://bbs.kafan.cn/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
}
}
}
WriteLog(L"签到 卡饭论坛", FALSE);
}
delete[]wOutBuffer;
return TRUE;
}
int SignSeHuaTang(WCHAR* wCookie)
{
WCHAR* wOutBuffer = new WCHAR[1024 * 1024];
HttpRequest(L"www.xxxxxxxxx.org", L"/plugin.php?id=dd_sign&mod=sign", L"https://www.xxxxxxxxx.org/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
if (lstrstr(wOutBuffer, L"尚未登录"))
{
WriteLog(L"Cookie失效 xxx", TRUE);
delete[]wOutBuffer;
return -99;
}
else
{
WCHAR* wStart = lstrstr(wOutBuffer, L"ajaxpost");
if (wStart)
{
WCHAR* wLink = lstrstr(wStart, L"signhash");
if (wLink)
{
WCHAR* wLinkRight = lstrstr(wLink, L"\"");
if (wLinkRight)
{
wLinkRight[0] = L'\0';
WCHAR* wFormhash = lstrstr(wLinkRight + 1, L"value");
if (wFormhash)
{
wFormhash += 7;
WCHAR* wFormhashRight = lstrstr(wFormhash, L"\"");
if (wFormhashRight)
{
wFormhashRight[0] = L'\0';
WCHAR* wSigntoken = lstrstr(wFormhashRight + 1, L"value");
if (wSigntoken)
{
wSigntoken += 7;
WCHAR* wSigntokenRight = lstrstr(wSigntoken, L"\"");
if (wSigntokenRight)
{
wSigntokenRight[0] = L'\0';
WCHAR* wSecqaahash = lstrstr(wSigntokenRight + 1, L"value");
if (wSecqaahash)
{
wSecqaahash += 7;
WCHAR* wSecqaahashRight = lstrstr(wSecqaahash, L"\"");
if (wSecqaahashRight)
{
wSecqaahashRight[0] = L'\0';
WCHAR szPost[1024];
WCHAR wNumBuffer[1024];
// WCHAR szHome[1024];
// wsprintf(szHome, L"/home.php?mod=spacecp&ac=pm&op=checknewpm&rand=%s");
// HttpRequest(L"www.sehuatang.org", L"", szHome, wCookie, wNumBuffer, 1024 * 1024, FALSE);
HttpRequest(L"www.xxxxxxxxx.org", L"/misc.php?mod=secqaa&action=update&idhash=qS0&0.8888888888888888", L"https://www.xxxxxxxxx.org/plugin.php?id=dd_sign&mod=sign", wCookie, wNumBuffer, 1024 * 1024-2, FALSE);
WCHAR* wNum = lstrstr(wNumBuffer, L" = ?");
if (wNum)
{
if (wNum)
{
wNum[0] = L'\0';
while (wNum[0] != L'\'')
{
wNum--;
}
WCHAR* wNum1 = wNum += 1;
while (wNum[0] != L' ')
{
wNum++;
}
wNum[0] = L'\0';
WCHAR wOperator = wNum[1];
WCHAR* wNum2 = wNum + 3;
int iSecanswer = 0;
if (wOperator == L'+')
iSecanswer = my_wtoi(wNum1) + my_wtoi(wNum2);
else
iSecanswer = my_wtoi(wNum1) - my_wtoi(wNum2);
WCHAR szLink[1024] = L"/plugin.php?id=dd_sign&mod=sign&signsubmit=yes&";
lstrcat(szLink, wLink);
lstrcat(szLink, L"&inajax=1");
wsprintf(szPost, L"formhash=%s&signtoken=%s&secqaahash=qS0&secanswer=%d", wFormhash, wSigntoken, iSecanswer);
HttpRequest(L"www.xxxxxxxxx.org", szLink, L"https://www.xxxxxxxxx.org/plugin.php?id=dd_sign&mod=sign", wCookie, wOutBuffer, 1024 * 1024-2, TRUE, szPost);
}
}
}
}
}
}
}
}
}
}
}
WriteLog(L"签到 xxx", FALSE);
}
delete[]wOutBuffer;
return TRUE;
}
int SignPCBeta(WCHAR* wCookie)
{
WCHAR* wOutBuffer = new WCHAR[1024 * 1024];
HttpRequest(L"i.pcbeta.com", L"/home.php?mod=task&do=apply&id=149", L"https://i.pcbeta.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
if (lstrstr(wOutBuffer, L"要先登录"))
{
WriteLog(L"Cookie失效 远景论坛", TRUE);
delete[]wOutBuffer;
return -99;
}
else
{
WriteLog(L"签到 远景论坛", FALSE);
}
HttpRequest(L"i.pcbeta.com", L"/home.php?mod=task&item=new", L"https://i.pcbeta.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
WCHAR* wApply = lstrstr(wOutBuffer, L"do=apply");
if (wApply)
{
WCHAR* wLink = lstrstr(wApply, L"id=");
if (wLink)
{
wLink += 3;
WCHAR* wLinkEnd = lstrstr(wLink, L"\"");
if (wLinkEnd)
{
wLinkEnd[0] = L'\0';
WCHAR wID[8];
lstrcpy(wID, wLink);
WCHAR wNew[256] = L"/home.php?mod=task&do=apply&id=";
lstrcat(wNew, wID);
HttpRequest(L"i.pcbeta.com", wNew, L"https://i.pcbeta.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
WCHAR wNow[256] = L"/home.php?mod=task&do=view&id=";
lstrcat(wNow, wID);
HttpRequest(L"i.pcbeta.com", wNow, L"https://i.pcbeta.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
WCHAR* wIS = lstrstr(wOutBuffer, L"在“");
if (wIS)
{
WCHAR* wOut = lstrstr(wIS, L"/view");
if (wOut)
{
WCHAR* wOutEnd = lstrstr(wOut, L"\"");
if (wOutEnd)
{
wOutEnd[0] = L'\0';
WCHAR wReferer[1024] = L"https://bbs.pcbeta.com";
lstrcat(wReferer, wOut);
HttpRequest(L"bbs.pcbeta.com", wOut, L"https://i.pcbeta.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
WCHAR* wPost = lstrstr(wOutBuffer, L"fastpostform");
if (wPost)
{
FILETIME ft;
SYSTEMTIME st;
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ft);
// LONGLONG nLL;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
// nLL = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
#if defined _M_IX86
UINT64 pt64;
UINT32 ys;
uint64_div_uint32(ui.QuadPart - 116444736000000000, 10000000, &pt64, &ys);
time_t pt = (long)pt64;
#else
time_t pt = (long)((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
#endif
WCHAR* wLink = lstrstr(wPost, L"=\"");
if (wLink)
{
wLink += 2;
WCHAR* wLinkEnd = lstrstr(wLink, L"\"");
if (wLinkEnd)
{
wLinkEnd[0] = L'\0';
WCHAR* wFormhashStart = lstrstr(wLinkEnd + 1, L"formhash");
if (wFormhashStart)
{
WCHAR* wFormhash = lstrstr(wFormhashStart, L"=\"");
if (wFormhash)
{
wFormhash += 2;
WCHAR* wFormhashEnd = lstrstr(wFormhash, L"\"");
if (wFormhashEnd)
{
wFormhashEnd[0] = L'\0';
WCHAR szLink[1024] = L"/";
do
{
wLinkEnd = lstrstr(wLink, L"amp;");
if (wLinkEnd)
wLinkEnd[0] = L'\0';
lstrcat(szLink, wLink);
wLink = wLinkEnd + 4;
} while (wLinkEnd);
lstrcat(szLink, L"&inajax=1");
WCHAR szPost[1024] = L"message=SmzdmRemind%C7%A9%B5%BD%A3%A1&posttime=";
WCHAR szPrint[1024];
wsprintf(szPrint, L"%d&formhash=%s&subject=&usesig=1", pt, wFormhash);
lstrcat(szPost, szPrint);
HttpRequest(L"bbs.pcbeta.com", szLink, wReferer, wCookie, wOutBuffer, 1024 * 1024-2, TRUE, szPost);
}
}
}
}
}
}
}
}
}
WCHAR wReceive[1024] = L"/home.php?mod=task&do=draw&id=";
lstrcat(wReceive, wID);
HttpRequest(L"i.pcbeta.com", wReceive, L"https://i.pcbeta.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
}
}
}
delete[]wOutBuffer;
return TRUE;
}
int SignMyDigit(WCHAR* wCookie)
{
WCHAR* wOutBuffer = new WCHAR[1024 * 1024];
HttpRequest(L"www.mydigit.cn", L"/plugin.php?id=k_misign:sign", L"https://www.mydigit.cn/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
if (lstrstr(wOutBuffer, L"找回密码"))
{
WriteLog(L"Cookie失效 数码之家", TRUE);
delete[]wOutBuffer;
return -99;
}
else
{
WCHAR* wLink = lstrstr(wOutBuffer, L"JD_sign");
if (wLink)
{
WCHAR* wLinkLeft = lstrstr(wLink, L"=\"");
if (wLinkLeft)
{
wLinkLeft += 1;
wLinkLeft[0] = L'/';
WCHAR* wLinkRight = lstrstr(wLinkLeft, L"\"");
if (wLinkRight)
{
wLinkRight[0] = L'\0';
HttpRequest(L"www.mydigit.cn", wLinkLeft, L"https://www.mydigit.cn/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
}
}
}
WriteLog(L"签到 数码之家", FALSE);
}
delete[]wOutBuffer;
return TRUE;
}
int SignTieba(WCHAR* wCookie)
{
WCHAR* wOutBuffer = new WCHAR[1024 * 1024];
HttpRequest(L"tieba.baidu.com", L"/f/like/mylike", L"https://tieba.baidu.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
WCHAR* wStart = lstrstr(wOutBuffer, L"/f?kw");
if (wStart)
{
WCHAR* wLinkStart;
while (wLinkStart = lstrstr(wStart, L"/f?kw"))
{
wLinkStart += 6;
WCHAR* wLinkEnd = lstrstr(wLinkStart, L"\"");
if (wLinkEnd)
{
wLinkEnd[0] = L'\0';
WCHAR wRequest[1024];
wsprintf(wRequest, L"/sign/add?ie=utf-8&kw=%s", wLinkStart);
HttpRequest(L"tieba.baidu.com", wRequest, L"https://tieba.baidu.com/", wCookie, wOutBuffer, 1024 * 1024-2, TRUE);
Sleep(188);
}
wStart = wLinkEnd + 1;
}
WriteLog(L"签到 百度贴吧", FALSE);
}
else
WriteLog(L"Cookie失效 百度贴吧", TRUE);
delete[]wOutBuffer;
return -1;
}
int SignV2EX(WCHAR* wCookie)
{
WCHAR* wOutBuffer = new WCHAR[1024 * 1024];
HttpRequest(L"v2ex.com", L"/mission/daily", L"https://v2ex.com/", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
if (lstrstr(wOutBuffer, L"要先登录"))
{
WriteLog(L"Cookie失效 V2EX", TRUE);
delete[]wOutBuffer;
return -99;
}
WCHAR* cLink = lstrstr(wOutBuffer, L"/mission/daily/redeem");
if (cLink)
{
WCHAR* cLinkRight = lstrstr(cLink, L"'");
if (cLinkRight)
{
cLinkRight[0] = L'\0';
HttpRequest(L"v2ex.com", cLink, L"https://v2ex.com/mission/daily", wCookie, wOutBuffer, 1024 * 1024-2, FALSE);
return TRUE;
}
}
WriteLog(L"签到 V2EX", FALSE);
delete[]wOutBuffer;
return -1;
}
int SignSMZDM(WCHAR* wCookie)
{
int nDay = -111;
WCHAR szGet[4096];
FILETIME ft;
SYSTEMTIME st;
GetLocalTime(&st);
SystemTimeToFileTime(&st, &ft);
// LONGLONG nLL;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
// nLL = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
#if defined _M_IX86
UINT64 pt64;
UINT32 ys;
uint64_div_uint32(ui.QuadPart - 116444736000000000, 10000000, &pt64, &ys);
time_t pt = (long)pt64;
#else
time_t pt = (long)((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
#endif
wsprintf(szGet, L"/user/checkin/jsonp_checkin?callback=jQuery13689&_=%d168", pt);
WCHAR wOutBuffer[4096];
HttpRequest(L"zhiyou.smzdm.com", szGet, L"https://www.smzdm.com/", wCookie, wOutBuffer, 4096-2, FALSE);
WCHAR* wErrorCode = lstrstr(wOutBuffer, L"error_code");
int iErrorCode = -111;
if (wErrorCode)
{
WCHAR* wECLeft = lstrstr(wErrorCode, L":");
if (wECLeft)
{
wECLeft += 1;
iErrorCode = my_wtoi(wECLeft);
if (iErrorCode < 0)
nDay = iErrorCode;
else
nDay = -iErrorCode;
WCHAR* wCheckinNum = lstrstr(wOutBuffer, L"checkin_num");
if (wCheckinNum)
{
WCHAR* wCheckinNumLeft = lstrstr(wCheckinNum, L":");
if (wCheckinNumLeft)
{
while (wCheckinNumLeft[0]<L'0'||wCheckinNumLeft[0]>L'9')
{
wCheckinNumLeft++;
}
nDay = my_wtoi(wCheckinNumLeft);
WriteLog(L"签到 什么值得买", FALSE);
}
}
}
}
if (nDay < 0)
WriteLog(L"Cookie失效 什么值得买", TRUE);
return nDay;
}