#include "stdafx.h" #include "AceReportInterface.h" #include "GameServer.h" #include "GameProto.pb.h" #include "CurlHelper.h" #include "AceInterface.h" #include "rapidjson/document.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" #include "rapidjson/prettywriter.h" #include "libEncrypt_MD5.h" const char* kReportProto = "http"; const char* kReportHost = "service-exp.light.oa.com"; const char* kReportUrl = "report/report_log_data"; const char* kReportUser = "719_report"; const char* kReportToken = "HaPjIyPBgVJSLsnZJGQjpAHKGLycsQSS"; std::string buildReportRequestJson(GameClient* client, Game::GameReportReq* request, uint32_t timeStamp) { rapidjson::Document root; root.SetObject(); rapidjson::Document::AllocatorType& allocator = root.GetAllocator(); rapidjson::Value emptyString(""); //informant_account_type rapidjson::Value accountType(1);//ACE_SDK_ACCOUNT_TYPE_QQ=1 root.AddMember("informant_account_type", accountType, allocator); //informant_account_id rapidjson::Value openIDValue(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); root.AddMember("informant_account_id", openIDValue, allocator); //informant_app_id rapidjson::Value appID(AceInterface::kGameID); root.AddMember("informant_app_id", appID, allocator); //informant_plat_id rapidjson::Value platID(2); root.AddMember("informant_plat_id", platID, allocator); //informant_world_id rapidjson::Value worldID(client->gameWorldID); root.AddMember("informant_world_id", worldID, allocator); //informant_name rapidjson::Value informantAccountID(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); root.AddMember("informant_account_id", informantAccountID, allocator); //informant_name rapidjson::Value informantName(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); root.AddMember("informant_name", informantName, allocator); //informant_roleid rapidjson::Value informantRoleID(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); root.AddMember("informant_roleid", informantRoleID, allocator); //informant_area rapidjson::Value areaID(3); root.AddMember("informant_area", areaID, allocator); //reported_account_type rapidjson::Value reportedAccountType(1);//ACE_SDK_ACCOUNT_TYPE_QQ=1 root.AddMember("reported_account_type", reportedAccountType, allocator); //reported_account_id rapidjson::Value reportedIDValue(request->reported_account_id().c_str(), static_cast(request->reported_account_id().length()), allocator); root.AddMember("reported_account_id", reportedIDValue, allocator); //reported_app_id rapidjson::Value reportedAppID(AceInterface::kGameID); root.AddMember("reported_app_id", reportedAppID, allocator); //reported_plat_id rapidjson::Value reportedPlatID(2); root.AddMember("reported_plat_id", reportedPlatID, allocator); //reported_world_id rapidjson::Value reportedWorldIDValue(request->reported_world_id()); root.AddMember("reported_world_id", reportedWorldIDValue, allocator); //reported_name rapidjson::Value reportedName(request->reported_name().c_str(), static_cast(request->reported_name().length()), allocator); root.AddMember("reported_name", reportedName, allocator); //reported_roleid rapidjson::Value reportedRoldID(request->reported_roleid().c_str(), static_cast(request->reported_roleid().length()), allocator); root.AddMember("reported_roleid", reportedRoldID, allocator); //reported_area rapidjson::Value reportedAreaID(3); root.AddMember("reported_area", reportedAreaID, allocator); //report_time rapidjson::Value reportTime(timeStamp); root.AddMember("report_time", reportTime, allocator); //business_data rapidjson::Value business_data(rapidjson::kObjectType); //business_data:report_category rapidjson::Value reportCategory(request->report_category()); business_data.AddMember("report_category", reportCategory, allocator); //business_data:report_reason rapidjson::Value reportReasonArray(rapidjson::kArrayType); for (const auto& reason : request->report_reason()) { reportReasonArray.PushBack(reason, allocator); } business_data.AddMember("report_reason", reportReasonArray, allocator); //business_data::report_scene rapidjson::Value reportScene(request->report_scene()); business_data.AddMember("report_scene", reportScene, allocator); //business_data::reported_profile_url rapidjson::Value reportedProfileUrl(request->reported_profile_url().c_str(), static_cast(request->reported_profile_url().length()), allocator); business_data.AddMember("reported_profile_url", reportedProfileUrl, allocator); //business_data::report_battle_id rapidjson::Value reportBattleID(request->report_battle_id().c_str(), static_cast(request->report_battle_id().length()), allocator); business_data.AddMember("report_battle_id", reportBattleID, allocator); //business_data::report_battle_time rapidjson::Value reportBattleTime(request->report_battle_time()); business_data.AddMember("report_battle_time", reportBattleTime, allocator); //business_data::report_desc rapidjson::Value reportDesc(request->report_desc().c_str(), static_cast(request->report_desc().length()), allocator); business_data.AddMember("report_desc", reportDesc, allocator); //business_data::report_content rapidjson::Value reportContent(request->report_content().c_str(), static_cast(request->report_content().length()), allocator); business_data.AddMember("report_content", reportContent, allocator); root.AddMember("business_data", business_data, allocator); rapidjson::StringBuffer sb; rapidjson::Writer writer(sb); root.Accept(writer); std::string outputJson = sb.GetString(); return outputJson; } std::string buildReportRequestUrl(const std::string& requestBody, uint32_t timeStamp) { uint32_t randomSerial = rand(); MD5Context md5Context; md5Init(&md5Context); md5Update(&md5Context, (uint8_t*)requestBody.c_str(), (uint32_t)requestBody.size()); std::string requestBodyMD5 = md5ToString(md5Finalize(&md5Context)); char szStringC[1024] = { 0 }; snprintf(szStringC, 1024, "serial=%u×tamp=%u&user=%s&body_md5=%s&token=%s", randomSerial, timeStamp, kReportUser, requestBodyMD5.c_str(), kReportToken); md5Init(&md5Context); md5Update(&md5Context, (uint8_t*)szStringC, (uint32_t)strlen(szStringC)); std::string signString = md5ToString(md5Finalize(&md5Context)); char szRequestURL[1024] = { 0 }; snprintf(szRequestURL, 1024, "%s://%s/%s?serial=%u×tamp=%u&user=%s&sign=%s", kReportProto, kReportHost, kReportUrl, randomSerial, timeStamp, kReportUser, signString.c_str()); return szRequestURL; } bool AceReportInterface::onReceiveReportRequest(GameClient* client, Game::GameReportReq* request) { uint32_t timeStamp = (uint32_t)(time(0) & 0xFFFFFFFF); std::string requestBody = buildReportRequestJson(client, request, timeStamp); std::string requestUrl = buildReportRequestUrl(requestBody, timeStamp); std::string result; int32_t retCode = curlRequest(requestUrl, requestBody, result, true); int32_t errorCode = 0; std::string errorInfo; if (retCode != 0) { CY_LOG(cyclone::L_ERROR, "NetbarInterface::onReceiveNetbarStatusRequest curlRequest failed, retCode=%d", retCode); char szTemp[256] = { 0 }; snprintf(szTemp, 256, "Curl request failed, retCode=%d", retCode); errorInfo = szTemp; } else { } return true; }