ڼС
梦回起点
做你害怕做的事,你会发现:不过如此
本站基于WordPress—主题by 设计窝
冀ICP备15003737号
梦回起点
Copyright © 2015-2024 All rights reserved.

淘宝开放平台Sign算法

因为要的急,所以就匆匆的把它赶完了,没有过脑子,甚至都没用if,看到精易论坛上有人要过这个,于是贴出来吧。变量命名也是看心情。有注释的看一下,没注释的官方文档都有。算法用到的QT的,可以用其他的库代替。不说了,我要去接着赶这个东西了。

bool RequestData::SendRequest(QString url, QTableWidget* table)//
{

    this->table = table;
    m_UrlNeedCon = url;
    QString strMakeSign = "89aaaacaaa4d7b180aaaaa9caf55a1a";//这个填你后台的那个
    QNetworkRequest request;
    //这里设置了一个http头
    request.setHeader(QNetworkRequest::ContentTypeHeader, m_StrContentType);
    request.setUrl(m_Url);
    QString strPostDate;
    strPostDate += "app_key=";//这个也在后台
    strPostDate += m_AppKey.toUtf8().toPercentEncoding();
    strMakeSign += "app_key";
    strMakeSign += m_AppKey.toUtf8();

#ifdef EXT
    strPostDate += "&ext=";
    strPostDate += m_Ext.toUtf8().toPercentEncoding();
    strMakeSign += "ext";
    strMakeSign += m_Ext.toUtf8();
#endif

    strPostDate += "&format=";
    strPostDate += m_Format.toUtf8().toPercentEncoding();
    strMakeSign += "format";
    strMakeSign += m_Format.toUtf8();

#ifdef LOGO
    strPostDate += "&logo=";
    strPostDate += m_Logo.toUtf8().toPercentEncoding();
    strMakeSign += "logo";
    strMakeSign += m_Logo.toUtf8();
#endif

    strPostDate += "&method=";
    strPostDate += m_Method.toUtf8().toPercentEncoding();
    strMakeSign += "method";
    strMakeSign += m_Method.toUtf8();

    strPostDate += "&partner_id=";
    strPostDate += m_PartnetId.toUtf8().toPercentEncoding();
    strMakeSign += "partner_id";
    strMakeSign += m_PartnetId.toUtf8();

    strPostDate += "&sign_method=";
    strPostDate += m_SignMethod.toUtf8().toPercentEncoding();
    strMakeSign += "sign_method";
    strMakeSign += m_SignMethod.toUtf8();

    strPostDate += "&text=";
    strPostDate += m_Text.toUtf8().toPercentEncoding();
    strMakeSign += "text";
    strMakeSign += m_Text.toUtf8();

    strPostDate += "×tamp=";
    strPostDate += m_TimeStamp.toUtf8().toPercentEncoding();
    strMakeSign += "timestamp";
    strMakeSign += m_TimeStamp.toUtf8();

    strPostDate += "&url=";
    strPostDate += m_UrlNeedCon.toUtf8().toPercentEncoding();
    strMakeSign += "url";
    strMakeSign += m_UrlNeedCon.toUtf8();

#ifdef USERID
    strPostDate += "&user_id=";
    strPostDate += m_UserID.toUtf8().toPercentEncoding();
    strMakeSign += "user_id";
    strMakeSign += m_UserID.toUtf8();
#endif

    strPostDate += "&v=";
    strPostDate += m_V.toUtf8().toPercentEncoding();
    strMakeSign += "v";
    strMakeSign += m_V.toUtf8();
    strMakeSign += "89aaaacaaa4d7b180aaaaa9caf55a1a";
    QByteArray bb;
    //这里计算了一下MD5
    bb = QCryptographicHash::hash(strMakeSign.toUtf8(), QCryptographicHash::Md5 );
    m_Sign="";
    m_Sign.append(bb.toHex());
    m_Sign = m_Sign.toUpper();

    strPostDate += "&sign=";
    strPostDate += m_Sign.toUtf8().toPercentEncoding();

    m_uploadManager->post(request, strPostDate.toUtf8());

    //QtConcurrent::run(this, &RequestData::post);
    return true;
}

2017-11-09
                         
暂无评论

发表回复