CMPP CONNECT CODE SAMPLE
发布时间:2006-10-14 3:03:13   收集提供:gaoqian

void CSmsCmpp::EncodeConnect(const long& nSecID,const string& sSrcAddr, const string& sPwd, const string& sUser, BYTE nVer)
{    
    m_smHeader.lCommandLength = 39;
    m_smHeader.lCommandId = CMPP_CONNECT;
    m_smHeader.lSequenceNumber = nSecID;
    EncodeHeader();
    
    string sAuthName;
    if(int(sUser.size())>0) {
        sAuthName = sUser.c_str();
    }
    else {
        sAuthName = sSrcAddr.c_str();
    }
    AppendOct(m_Body,(PBYTE)sAuthName.c_str(),6);

    vector<BYTE> vAuth;
    std::copy(sAuthName.begin(),sAuthName.end(),back_inserter(vAuth));
    for(int i=0;i<9;i++) vAuth.push_back(0x00);
    std::copy(sPwd.begin(),sPwd.end(),back_inserter(vAuth));    
    string sStamp = GetCurTime();
    std::copy(sStamp.begin(),sStamp.end(),back_inserter(vAuth));

    char src[400];    
    memset(src,0,400);
    std::copy(vAuth.begin(),vAuth.end(),src);

    PBYTE temp = new BYTE[17];
    memset(temp,0,17);
    DWORD dwSize;
    CryptMD5Hash((PBYTE)src,int(vAuth.size()),temp,dwSize);    

    ostringstream oss;
    oss<<"发送连接包!";
    

    AppendOct(m_Body,(PBYTE)temp,16);  //ICP认证码        
    delete[] temp;

    AppendInt(m_Body,nVer);        
    DWORD lTimeStamp = atoi(sStamp.c_str());
    lTimeStamp = htonl(lTimeStamp);
    AppendOct(m_Body,(PBYTE)&lTimeStamp,4);
}

 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50