Example #1
0
void QQLoginCore::login(QString id, QString pwd, ContactStatus status)
{
	id_ = id;
	pwd_ = pwd;
    status_ = status;

    QString login_url = "/login?u=" + id + "&p=" + getPwMd5(pwd) + "&verifycode="+vc_+
            "&webqq_type=10&remember_uin=0&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=2-6-22950&mibao_css=m_webqq&t=1&g=1";

    Request req;
    req.create(kGet, login_url);
    req.addHeaderItem("Host", "ptlogin2.qq.com");
    req.addHeaderItem("Cookie", CaptchaInfo::instance()->cookie());
    req.addHeaderItem("Referer", "http://ui.ptlogin2.qq.com/cgi-bin/login?target=self&style=5&mibao_css=m_webqq&appid=1003903&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fweb.qq.com%2Floginproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20120504001");

    fd_->connectToHost("ptlogin2.qq.com", 80);
    fd_->write(req.toByteArray());
    
    QByteArray result;
    while (result.indexOf(");") == -1 && fd_->waitForReadyRead(5000))
    {
        result.append(fd_->readAll());
    }

    fd_->close();

    qDebug() << "Login Result:\n" << result << '\n' << endl;

    QString ptwebqq;

    char result_state = getResultState(result);

    switch (result_state)
    {
    case '0':
        break;
    case '3':
    {
        emit sig_loginDone(kIdOrPwdWrong);
        return;
    }
    case '4':
    {
        emit sig_loginDone(kAuthcodeWrong);
        return;
    }
    default:
        return;
    }

    int idx = 0;  
    
    while ((idx = result.indexOf("Set-Cookie:", idx)) != -1) 
    {
        idx += strlen("Set-Cookie: ");

        int value_idx = result.indexOf("=", idx); 
        int fin_value_idx = result.indexOf(";", idx);

        if (fin_value_idx == (value_idx + 1)) continue;

        QString key = result.mid(idx, value_idx - idx); 
        QString value = result.mid(value_idx+1, fin_value_idx - value_idx - 1);

        if (key == "ptwebqq")
        {
            ptwebqq = value;
            CaptchaInfo::instance()->setPtwebqq(ptwebqq);
        }

        if (key == "skey")
            CaptchaInfo::instance()->setSkey(value);

        CaptchaInfo::instance()->setCookie(CaptchaInfo::instance()->cookie() + key + "=" + value + ";");
    }

    getLoginInfo(ptwebqq);
}
Example #2
0
void QQLogin::loginRead()
{
    fd_->disconnectFromHost();

    QString ptwebqq;
    QByteArray result = fd_->readAll();

    char result_state = getResultState(result);

    switch (result_state)
    {
    case '0':
        break;
    case '3':
    {
        QMessageBox box(this);
        box.setIcon(QMessageBox::Critical);
        box.setText(tr("Password validation error!!"));
        box.setInformativeText(tr("The password is not correct, the reason may be:\nForgot password; Not case sensitive; Not open small keyboard."));

        box.exec();

        return;
    }
    case '4':
    {
        QMessageBox box(this);
        box.setIcon(QMessageBox::Critical);
        box.setText(tr("Authcode error!!"));
        box.setInformativeText(tr("The Authcode is not correct! Please relogin!"));

        box.exec();
        return;
    }
    default:
        return;
    }

    int idx = 0;  
    
    while ((idx = result.indexOf("Set-Cookie:", idx)) != -1) 
    {
        idx += strlen("Set-Cookie: ");

        int value_idx = result.indexOf("=", idx); 
        int fin_value_idx = result.indexOf(";", idx);

        if (fin_value_idx == (value_idx + 1)) continue;

        QString key = result.mid(idx, value_idx - idx); 
        QString value = result.mid(value_idx+1, fin_value_idx - value_idx - 1);

        if (key == "ptwebqq")
            ptwebqq = value;

        if (key == "skey")
            captcha_info_.skey_ = value;

        captcha_info_.cookie_ = captcha_info_.cookie_ + key + "=" + value + ";";
    }

    disconnect(fd_, SIGNAL(readyRead()), this, SLOT(loginRead()));
    getLoginInfo(ptwebqq);
}