上报安装,崩溃等日志时,携带上appName等信息

This commit is contained in:
luoliangyi 2022-07-15 13:45:13 +08:00
parent 72b3b55a2a
commit 895fecbeb7
3 changed files with 107 additions and 17 deletions

View File

@ -9,6 +9,11 @@ HG_DECLARE_HANDLE(HGVersionMgr);
#define HGVERSION_APPNAME_SCANNER "Scanner" #define HGVERSION_APPNAME_SCANNER "Scanner"
#define HGVERSION_APPNAME_DRIVER "Driver" #define HGVERSION_APPNAME_DRIVER "Driver"
#define HGVERSION_DEVACTION_START "start"
#define HGVERSION_DEVACTION_CLOSE "close"
#define HGVERSION_DEVACTION_CLEAN "clean"
#define HGVERSION_DEVACTION_COUNT "count"
typedef struct typedef struct
{ {
HGBool postCrashInfo; /* 是否上报崩溃信息 */ HGBool postCrashInfo; /* 是否上报崩溃信息 */

View File

@ -536,31 +536,104 @@ static HGResult PostInfo(int type, const std::string& appName, const std::string
std::string osName = GetOSName(); std::string osName = GetOSName();
std::string archName = GetArchName(); std::string archName = GetArchName();
std::string oemName = GetOemName(); std::string oemName = GetOemName();
std::string source = osName + "-" + archName + "-" + oemName;
char json[1024]; std::string jsonStr;
if (1 == type || 2 == type) cJSON* json = cJSON_CreateObject();
if (NULL != json)
{ {
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\"}", cJSON_AddItemToObject(json, "type", cJSON_CreateNumber(type));
type, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str()); cJSON_AddItemToObject(json, "mac", cJSON_CreateString(macList[0].c_str()));
cJSON_AddItemToObject(json, "localid", cJSON_CreateString(md5Str));
cJSON_AddItemToObject(json, "v", cJSON_CreateString(version.c_str()));
cJSON_AddItemToObject(json, "desc", cJSON_CreateString(desc.c_str()));
cJSON_AddItemToObject(json, "sys", cJSON_CreateString(osName.c_str()));
cJSON_AddItemToObject(json, "cpu", cJSON_CreateString(archName.c_str()));
cJSON_AddItemToObject(json, "oem", cJSON_CreateString(oemName.c_str()));
cJSON_AddItemToObject(json, "app", cJSON_CreateString(appName.c_str()));
if (3 == type)
{
cJSON_AddItemToObject(json, "crashaddress", cJSON_CreateString(exceptionAddr.c_str()));
cJSON_AddItemToObject(json, "crash_data", cJSON_CreateString(crashFileUrl.c_str()));
} }
else if (3 == type) else if (4 == type)
{ {
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\", \"crashaddress\":\"%s\", \"crash_data\":\"%s\"}", cJSON_AddItemToObject(json, "contact", cJSON_CreateString(feedbackContact.c_str()));
type, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str(), exceptionAddr.c_str(), crashFileUrl.c_str()); cJSON_AddItemToObject(json, "content", cJSON_CreateString(feedbackInfo.c_str()));
} }
else
{ jsonStr = cJSON_Print(json);
assert(4 == type); cJSON_Delete(json);
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\", \"content\":\"%s\", \"contact\":\"%s\"}",
type, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str(), feedbackInfo.c_str(), feedbackContact.c_str());
} }
struct curl_slist* headers = NULL; struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8"); headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonStr.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
/* Perform the request, res will get the return code */
CURLcode res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
else
{
std::string str_json = out.str(); // 返回值
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str());
cJSON* json = cJSON_Parse(str_json.c_str());
if (NULL != json)
{
cJSON* p = json->child;
while (NULL != p)
{
if (0 == strcmp(p->string, "code") && p->type == cJSON_Number)
{
if (1 == p->valueint)
ret = HGBASE_ERR_OK;
}
p = p->next;
}
cJSON_Delete(json);
}
}
curl_slist_free_all(headers);
/* always cleanup */
curl_easy_cleanup(curl);
}
return ret;
}
static HGResult PostDeviceInfo(const std::string& sn, const std::string& type, const std::string& name,
const std::string& fw, const std::string& act, int cnt)
{
HGResult ret = HGBASE_ERR_FAIL;
CURL* curl = curl_easy_init();
if (NULL != curl)
{
std::stringstream out;
char countStr[16];
sprintf(countStr, "%d", cnt);
std::string url = "http://up.appqy.com/api/bhs?sn=" + sn + "&type=" + type + "&name=" + name + "&fw=" + fw
+ "&act=" + act + "&cnt" + countStr;
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Accept-Encoding:gzip, deflate, sdch");
headers = curl_slist_append(headers, "Accept-Language:zh-CN,zh;q=0.8");
headers = curl_slist_append(headers, "Connection:keep-alive");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
@ -825,9 +898,20 @@ HGResult HGVersionMgrImpl::PostUninstallInfo(const HGChar* appName, const HGChar
HGResult HGVersionMgrImpl::PostCrashInfo(const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr) HGResult HGVersionMgrImpl::PostCrashInfo(const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr)
{ {
if (!m_serverCfg.postCrashInfo)
return HGBASE_ERR_FAIL;
return ::PostCrashInfo(appName, desc, crashFilePath, exceptionAddr); return ::PostCrashInfo(appName, desc, crashFilePath, exceptionAddr);
} }
HGResult HGVersionMgrImpl::PostDeviceInfo(const HGChar* sn, const HGChar* type, const HGChar* name, const HGChar* fw, const HGChar* act, int cnt)
{
if (!m_serverCfg.postDeviceInfo)
return HGBASE_ERR_FAIL;
return ::PostDeviceInfo(sn, type, name, fw, act, cnt);
}
HGResult HGVersionMgrImpl::PostUserFeedback(const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact) HGResult HGVersionMgrImpl::PostUserFeedback(const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact)
{ {
return ::PostUserFeedback(appName, desc, feedback, contact); return ::PostUserFeedback(appName, desc, feedback, contact);

View File

@ -14,6 +14,7 @@ public:
HGResult PostInstallInfo(const HGChar* appName, const HGChar* desc); HGResult PostInstallInfo(const HGChar* appName, const HGChar* desc);
HGResult PostUninstallInfo(const HGChar* appName, const HGChar* desc); HGResult PostUninstallInfo(const HGChar* appName, const HGChar* desc);
HGResult PostCrashInfo(const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr); HGResult PostCrashInfo(const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr);
HGResult PostDeviceInfo(const HGChar *sn, const HGChar* type, const HGChar* name, const HGChar* fw, const HGChar* act, int cnt);
HGResult PostUserFeedback(const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact); HGResult PostUserFeedback(const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact);
HGResult GetVersionList(const HGChar* appName, HGVersionInfo** info, HGUInt* count); HGResult GetVersionList(const HGChar* appName, HGVersionInfo** info, HGUInt* count);
HGResult HttpDownload(const HGChar* url, const HGChar* saveFilePath, HGHttpDownloadFunc func, HGPointer param); HGResult HttpDownload(const HGChar* url, const HGChar* saveFilePath, HGHttpDownloadFunc func, HGPointer param);