18,356
社区成员
发帖
与我相关
我的任务
分享
void CHttpManager::LoginJD(/*char *szBuff,int & szSize*/)
{
CString strHttpName = "http://passport.jd.com/new/login.aspx";
//CString strHeaders = "Content-Type: application/x-www-form-urlencoded; charset=utf-8"; // 请求头
//CString strFormData = "LoginUserName=wjyoem&LoginPassword=qq123123";
//pConnection = m_Session.GetHttpConnection(strHttpName);
//m_HttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,"");
m_http = (CHttpFile *)m_senssion.OpenURL(strHttpName);
CString strSentence, strGetSentence="";
if(m_http)
{
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
//BOOL result = m_HttpFile->SendRequest(strHeaders,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
BOOL bSuccess = m_http->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 &&dwStatus<300 )
{
while(m_http->ReadString(strSentence)) // 读取提交数据后的返回结果
{
strGetSentence = strGetSentence + strSentence + char(13) + char(10);
}
}
// 取返回的COOKIE
CString strInfo ;
DWORD dw = 0 ;
while(m_http->QueryInfo(HTTP_QUERY_SET_COOKIE ,strInfo ,&dw))
{
m_strCookie += strInfo ;
}
string returnVal = strGetSentence;
int nStart = returnVal.find("acid=");
if (nStart != returnVal.npos)
{
int nEnd = returnVal.find("&",nStart);
m_strPic = returnVal.substr(nStart+5,nEnd-nStart-5);
}
nStart = returnVal.find("name=\"uuid\"");
if (nStart != returnVal.npos)
{
nStart = returnVal.find("value=\"");
int nEnd = returnVal.find("\"",nStart+7);
m_strUuid = returnVal.substr(nStart+7,nEnd-nStart-7);
}
nStart = returnVal.find("使用合作");
if (nStart != returnVal.npos)
{
nStart = returnVal.find("name=\"",nStart);
int nEnd = returnVal.find("\"",nStart+6);
m_strName = returnVal.substr(nStart+6,nEnd-nStart-6);
}
nStart = returnVal.find("value=\"",nStart);
if (nStart != returnVal.npos)
{
int nEnd = returnVal.find("\"",nStart+7);
m_strValue = returnVal.substr(nStart+7,nEnd-nStart-7);
}
time_t timep;
time (&timep);
long ltime = timep;
string strUrl = "https://authcode.jd.com/verify/image?a=1&acid=";
strUrl += m_strPic;
strUrl += "&uid=";
strUrl += m_strPic;
strUrl += "&yys=";
CString strTime;
strTime.Format("%d",ltime);
strUrl += strTime;
strGetSentence = "";
m_http = (CHttpFile *)m_senssion.OpenURL(strUrl.c_str());
bSuccess = m_http->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
char szBuff[1024*100];
memset(szBuff, 0, sizeof(szBuff));
DWORD dwFileLen = m_http->GetLength();
DWORD ret;
DWORD dwRead=10;
HANDLE hFile;
hFile=CreateFile("d://1.png",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
while(dwRead>0)
{
dwRead=m_http->Read(szBuff,sizeof(szBuff)-1);
WriteFile(hFile,szBuff,dwRead,&ret,NULL);
}
CloseHandle(hFile);
}
}
void CHttpManager::LoginJD2(CString strPic)
{
CString strHttpName = "passport.jd.com";
CString strHeaders = "Content-Type: application/x-www-form-urlencoded; charset=utf-8"; // 请求头
CString strFormData = "LoginUserName=wjyoem&LoginPassword=qq123123";
CString strCookie = "Cookie: ";
strCookie += m_strCookie.c_str();
strCookie.Replace("Path:/;","");
strCookie.Replace("HttpOnly","");
m_http->AddRequestHeaders(strCookie);
m_connection = m_senssion.GetHttpConnection(strHttpName);
string strUrl = "/uc/loginService?uuid=";
strUrl += m_strUuid;
SYSTEMTIME st;
GetLocalTime(&st);
double time;
SystemTimeToVariantTime(&st,&time);
time = time/100000;
CStringA str;
str.Format("%.17lf",time);
strUrl += "&&r=";
strUrl += str;
m_http = m_connection->OpenRequest(CHttpConnection::HTTP_VERB_POST,strUrl.c_str(),NULL,1,0,0,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);
string strPost = "uuid=";
strPost += m_strUuid;
strPost += "&loginname=a409012486&nloginpwd=25853322&loginpwd=25853322&machineNet=&machineCpu=&machineDisk=&authcode=";
strPost += strPic;
strPost += "&";
strPost += m_strName;
strPost += "=";
strPost += m_strValue;
CString strSentence, strGetSentence="";
if(m_http)
{
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL result = m_http->SendRequest(strHeaders,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
BOOL bSuccess = m_http->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 &&dwStatus<300 )
{
while(m_http->ReadString(strSentence)) // 读取提交数据后的返回结果
{
strGetSentence = strGetSentence + strSentence + char(13) + char(10);
}
USES_CONVERSION;
string strRet;
Utf8ToMb(strGetSentence.GetBuffer(),strGetSentence.GetLength(),strRet);
}
}
m_http->Close();
delete m_http;
}