兩類實現:① 嵌入 IE 控件(WebBrowser)操作 DOM;② 純 HTTP 封包(本文重點)。核心難點:
訪問 https://captcha.qq.com/getimage?aid=1007901&0.3621022082160978,其中:
aid:日期相關,一天遞增 1,可硬編碼或從主頁正則提取。關鍵 Header:
GET /getimage?aid=1007901&0.3621022082160978 HTTP/1.1
Accept: */*
Referer: https://reg.qq.com/
Accept-Language: zh-CN
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; ...)
Host: captcha.qq.com
Connection: Keep-Alive
HINTERNET hSession = InternetOpen("InetAll", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "captcha.qq.com",
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "GET",
"/getimage?aid=1007901&0.0022421072022002497",
NULL, "https://reg.qq.com/", (LPCSTR*)"Accept: */*",
INTERNET_FLAG_RELOAD, 1);
HttpSendRequest(hRequest, NULL, -1, NULL, 0);
// 讀取圖片數據
char buf[1024]; DWORD read;
HANDLE hFile = CreateFile("temp.dat", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
while (InternetReadFile(hRequest, buf, 1024, &read) && read)
WriteFile(hFile, buf, read, &read, NULL);
CloseHandle(hFile);
Win32 無原生 GIF 支持,利用 OleLoadPicture 從流載入:
bool LoadPic(CString path)
{
IStream* pStm = NULL;
CFile file; CFileStatus fs;
if (!file.Open(path, CFile::modeRead) || !file.GetStatus(path, fs)) return false;
LONG cb = fs.m_size;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
if (!hGlobal) return false;
LPVOID pv = GlobalLock(hGlobal);
file.Read(pv, cb); file.Close();
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); // TRUE: 流釋放時自動釋放 hGlobal
IPicture* pPic = NULL;
HRESULT hr = OleLoadPicture(pStm, cb, FALSE, IID_IPicture, (void**)&pPic);
pStm->Release();
if (SUCCEEDED(hr) && pPic) {
// 在畫布繪製
HDC hdc = GetDC(m_picCtrl.m_hWnd);
RECT rc; m_picCtrl.GetClientRect(&rc);
long hmWidth, hmHeight;
pPic->get_Width(&hmWidth); pPic->get_Height(&hmHeight);
pPic->Render(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
0, hmHeight, hmWidth, -hmHeight, &rc); // 注意 HIMETRIC 坐標系
ReleaseDC(m_picCtrl.m_hWnd, hdc);
pPic->Release();
}
return SUCCEEDED(hr);
}
關鍵點:Render 參數用 HIMETRIC (0.01mm),寬高從 IPicture::get_Width/Height 獲取,Y 軸方向相反故用負高度。
分析註冊頁面表單字段(隱藏域、Cookie、驗證碼輸入框等),構造 application/x-www-form-urlencoded 體,發送至註冊接口,解析返回頁面/JSON 獲取 QQ 號。
⚠️ 批量註冊 QQ 號違反騰訊《服務協議》,屬於濫用服務、惡意註冊,可能構成計算機信息系統破壞罪。本文僅作為 HTTP 協議分析、WinInet 編程、OLE 圖片加載的技術教學示例,請勿用於非法用途。
libcurl + OpenCV/stb_image 解碼 GIF,跨平台、無 COM 依賴。requests + PIL/Pillow,幾行代碼完成。