2025-01-16 16:17:01 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file: $RCSfile: nacos.cpp,v $
|
|
|
|
|
|
* @brief: $aliyun datahub include
|
|
|
|
|
|
*
|
|
|
|
|
|
* @version: $Revision: 1.00 $
|
|
|
|
|
|
* @date: $Date: 2023/10/24 18:34:00 $
|
|
|
|
|
|
* @author: $Author: wangwei $
|
|
|
|
|
|
* @state: $State: Exp $
|
|
|
|
|
|
*
|
|
|
|
|
|
* @latest: $Id: nacos.cpp,v 1.00 2023/10/24 18:34:00 caizhouyu Exp $
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include "../mms/db_interface.h"
|
|
|
|
|
|
#include "../json/cjson.h"//WW 2023-08-27<32><37><EFBFBD><EFBFBD>json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
#include "../include/curl/curl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-29 15:05:36 +08:00
|
|
|
|
size_t req_reply_nacos(void* ptr, size_t size, size_t nmemb, void* stream)
|
|
|
|
|
|
{
|
|
|
|
|
|
string* str = (string*)stream;
|
|
|
|
|
|
(*str).append((char*)ptr, size * nmemb);
|
|
|
|
|
|
return size * nmemb;
|
|
|
|
|
|
}
|
|
|
|
|
|
void read_nacos_param(const char* ptr, char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret) {
|
|
|
|
|
|
//cout << ">>>GetDevice in reply" << (char*)ptr;
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse((char*)ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error %s\n", cJSON_GetErrorPtr());
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || json_node->valuestring == NULL || json_node->valuestring == "/0" || json_node->valuestring == "" || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || json_node->valuestring == NULL || json_node->valuestring == "/0" || json_node->valuestring == "" || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "postgres_uid"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
|
|
|
|
|
|
strcpy(postgres_uid, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "postgres_pwd"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
|
|
|
|
|
|
strcpy(postgres_pwd, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "web_clientid"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
|
|
|
|
|
|
strcpy(web_clientid, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "web_clientsecret"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
|
|
|
|
|
|
strcpy(web_clientsecret, json_node->valuestring);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
|
|
|
|
|
void releaseMemory(char** ptr) {
|
|
|
|
|
|
if (*ptr != NULL) {
|
|
|
|
|
|
free(*ptr); // <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
void SendWebAPI_Nacos(const string strUrl, const char* code, char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret)
|
|
|
|
|
|
{
|
|
|
|
|
|
// curl<72><6C>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
|
// curl<72><6C><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
|
CURLcode res;
|
|
|
|
|
|
if (curl)
|
2025-01-16 16:17:01 +08:00
|
|
|
|
{
|
2025-04-29 15:05:36 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>curl<72><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
|
|
|
|
|
|
struct curl_slist* header_list = NULL;
|
|
|
|
|
|
header_list = curl_slist_append(header_list, "Content-Type:application/json;");
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧͷ<D3A6><CDB7><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊpost<73><74><EFBFBD><EFBFBD>
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
|
|
|
|
|
cJSON* json_root = cJSON_CreateObject();
|
|
|
|
|
|
cJSON_AddItemToObject(json_root, "code", cJSON_CreateString(code));
|
|
|
|
|
|
char* szjson = cJSON_Print(json_root);
|
|
|
|
|
|
printf(">>>json %s\n", szjson);
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
|
//CURLOPT_VERBOSE<53><45>ֵΪ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ϸ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD>뺯<EFBFBD><EBBAAF>
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_nacos);
|
|
|
|
|
|
string resPost0;
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
|
|
|
|
|
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
|
|
|
|
|
|
printf(">>>Test nacos Post in curl post\n");
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
|
printf("nacos failed res code: ");
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
else {
|
|
|
|
|
|
printf("nacos success,string %s", resPost0.c_str());
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>webapi<70><69><EFBFBD><EFBFBD>ֵ<EFBFBD>ж<EFBFBD>
|
|
|
|
|
|
read_nacos_param(resPost0.c_str(), postgres_uid, postgres_pwd, web_clientid, web_clientsecret);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
curl_slist_free_all(header_list);
|
|
|
|
|
|
free(szjson);
|
|
|
|
|
|
cJSON_Delete(json_root);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
else
|
2025-01-16 16:17:01 +08:00
|
|
|
|
{
|
2025-04-29 15:05:36 +08:00
|
|
|
|
printf(">>> nacos curl init failed");
|
|
|
|
|
|
}
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
|
}
|
|
|
|
|
|
void SendWebAPI_Nacos_Ptr(const string strUrl, const char* code, char** ptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
// curl<72><6C>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
|
// curl<72><6C><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
|
CURLcode res;
|
|
|
|
|
|
if (curl)
|
|
|
|
|
|
{
|
|
|
|
|
|
char url[100];
|
|
|
|
|
|
sprintf(url, "%s?code=%s", strUrl.c_str(), code);
|
|
|
|
|
|
printf(">>>json %s\n", url);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>URL
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD>뺯<EFBFBD><EBBAAF>
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_nacos);
|
|
|
|
|
|
string resPost0;
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
|
|
|
|
|
|
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
|
printf("nacos failed res code: ");
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
printf(">>> nacos return str:%s \n", resPost0.c_str());
|
|
|
|
|
|
*ptr = (char*)malloc(strlen(resPost0.c_str()) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>㹻<EFBFBD><E3B9BB><EFBFBD>ڴ<EFBFBD><DAB4>ռ<EFBFBD>
|
|
|
|
|
|
if (*ptr != NULL) {
|
|
|
|
|
|
strcpy(*ptr, resPost0.c_str());
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2025-04-29 15:05:36 +08:00
|
|
|
|
printf("Memory allocation failed!\n");
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
else
|
2025-01-16 16:17:01 +08:00
|
|
|
|
{
|
2025-04-29 15:05:36 +08:00
|
|
|
|
printf(">>> nacos curl init failed");
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Nacos_GetParam(char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendWebAPI_Nacos("http://127.0.0.1:8091/powerQuality/PQNACOS", "200", postgres_uid, postgres_pwd, web_clientid, web_clientsecret);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Nacos_GetParam_Ptr(const char* code, char** ptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", code, ptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Read_Nacos_Param_Postgres(char** database_ip, char** database_port, char** postgres_database, char** postgres_username, char** postgres_password, char** postgres_schema, char** postgres_dnsname, char** postgres_tableprefix) {
|
|
|
|
|
|
char* ptr=NULL;
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "postgres", &ptr);
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error %s\n", cJSON_GetErrorPtr());
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "ip"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*database_ip != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*database_ip);
|
|
|
|
|
|
}
|
|
|
|
|
|
*database_ip = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*database_ip, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "port"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*database_port != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*database_port);
|
|
|
|
|
|
}
|
|
|
|
|
|
*database_port = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*database_port, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "database"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*postgres_database != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*postgres_database);
|
|
|
|
|
|
}
|
|
|
|
|
|
*postgres_database = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*postgres_database, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "username"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*postgres_username != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*postgres_username);
|
|
|
|
|
|
}
|
|
|
|
|
|
*postgres_username = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*postgres_username, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "password"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*postgres_password != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*postgres_password);
|
|
|
|
|
|
}
|
|
|
|
|
|
*postgres_password = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*postgres_password, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "schema"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*postgres_schema != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*postgres_schema);
|
|
|
|
|
|
}
|
|
|
|
|
|
*postgres_schema = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*postgres_schema, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "dnsname"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*postgres_dnsname != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*postgres_dnsname);
|
|
|
|
|
|
}
|
|
|
|
|
|
*postgres_dnsname = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*postgres_dnsname, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "tablePrefix"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*postgres_tableprefix != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*postgres_tableprefix);
|
|
|
|
|
|
}
|
|
|
|
|
|
*postgres_tableprefix = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*postgres_tableprefix, json_node->valuestring);
|
|
|
|
|
|
}
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
if (ptr) {
|
|
|
|
|
|
free(ptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Read_Nacos_Param_Kafka(char** broker_list, char** topic_stat, char** topic_pst, char** topic_plt, char** topic_event, char** topic_alarm, char** topic_sng,char** protocol ,char** mechanisms, char** service_name, char** principal, char** domain_name) {
|
|
|
|
|
|
char* ptr = NULL;
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "kafka", &ptr);
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "brokerList"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*broker_list != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*broker_list);
|
|
|
|
|
|
}
|
|
|
|
|
|
*broker_list = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*broker_list, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "hisTopic"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*topic_stat != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*topic_stat);
|
|
|
|
|
|
}
|
|
|
|
|
|
*topic_stat = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*topic_stat, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "pstTopic"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*topic_pst != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*topic_pst);
|
|
|
|
|
|
}
|
|
|
|
|
|
*topic_pst = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*topic_pst, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "pltTopic"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*topic_plt != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*topic_plt);
|
|
|
|
|
|
}
|
|
|
|
|
|
*topic_plt = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*topic_plt, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "eventTopic"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*topic_event != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*topic_event);
|
|
|
|
|
|
}
|
|
|
|
|
|
*topic_event = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*topic_event, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "almTopic"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*topic_alarm != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*topic_alarm);
|
|
|
|
|
|
}
|
|
|
|
|
|
*topic_alarm = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*topic_alarm, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "sngTopic"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*topic_sng != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*topic_sng);
|
|
|
|
|
|
}
|
|
|
|
|
|
*topic_sng = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*topic_sng, json_node->valuestring);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "protocol"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*protocol != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*protocol);
|
|
|
|
|
|
}
|
|
|
|
|
|
*protocol = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*protocol, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "mechanisms"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*mechanisms != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*mechanisms);
|
|
|
|
|
|
}
|
|
|
|
|
|
*mechanisms = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*mechanisms, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "serviceName"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*service_name != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*service_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
*service_name = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*service_name, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "principal"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*principal != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*principal);
|
|
|
|
|
|
}
|
|
|
|
|
|
*principal = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*principal, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "domainName"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*domain_name != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*domain_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
*domain_name = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*domain_name, json_node->valuestring);
|
|
|
|
|
|
}
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Read_Nacos_Param_Web(char** client_id, char** client_secret, char** token_url, char** device_url, char** grant_type) {
|
|
|
|
|
|
char* ptr = NULL;
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "web", &ptr);
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "clientId"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*client_id != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*client_id);
|
|
|
|
|
|
}
|
|
|
|
|
|
*client_id = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*client_id, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "clientSecret"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*client_secret != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*client_secret);
|
|
|
|
|
|
}
|
|
|
|
|
|
*client_secret = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*client_secret, json_node->valuestring);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "tokenUrl"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*token_url != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*token_url);
|
|
|
|
|
|
}
|
|
|
|
|
|
*token_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*token_url, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "deviceUrl"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*device_url != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*device_url);
|
|
|
|
|
|
}
|
|
|
|
|
|
*device_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*device_url, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "grantType"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*grant_type != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*grant_type);
|
|
|
|
|
|
}
|
|
|
|
|
|
*grant_type = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*grant_type, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Read_Nacos_Param_Flag(int* file_flag, int* send_flag, int* front_inst, char** front_ip) {
|
|
|
|
|
|
char* ptr = NULL;
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "flag", &ptr);
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error: %s\n", ptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "fileFlag"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
*file_flag= atoi(json_node->valuestring);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "sendFlag"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
*send_flag = atoi(json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "frontInst"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
*front_inst = atoi(json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "frontIP"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
//***postgres_pwd = json_node->valuestring;
|
|
|
|
|
|
if (*front_ip != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*front_ip);
|
|
|
|
|
|
}
|
|
|
|
|
|
*front_ip = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*front_ip, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Read_Nacos_Param_Recall(int* recall_len, int* recall_sta, int* recall_daily) {
|
|
|
|
|
|
char* ptr = NULL;
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "recall", &ptr);
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "recall_lenth"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
*recall_len = atoi(json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "recall_start"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
*recall_sta = atoi(json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "recall_dailytime"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
*recall_daily = atoi(json_node->valuestring);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
|
|
|
|
|
void Read_Nacos_Param_Uds(char** uds_upload_url, char** uds_download_url, char** uds_delete_url) {
|
|
|
|
|
|
char* ptr = NULL;
|
|
|
|
|
|
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "uds", &ptr);
|
|
|
|
|
|
int flag = 1;
|
|
|
|
|
|
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
|
|
|
|
|
|
cJSON* json_node;
|
|
|
|
|
|
cJSON* json_param;
|
|
|
|
|
|
if (json == NULL) {
|
|
|
|
|
|
printf("nacos error %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
|
|
|
|
|
|
printf("status error :%s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
|
|
|
|
|
|
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
printf("read nacos success\n");
|
|
|
|
|
|
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "udsUploadUrl"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*uds_upload_url != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*uds_upload_url);
|
|
|
|
|
|
}
|
|
|
|
|
|
*uds_upload_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*uds_upload_url, json_node->valuestring);
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "udsDownloadUrl"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*uds_download_url != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*uds_download_url);
|
|
|
|
|
|
}
|
|
|
|
|
|
*uds_download_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*uds_download_url, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
json_node = cJSON_GetObjectItem(json_param, "UdsDeleteUrl"); //<2F><>ȡresult
|
|
|
|
|
|
if (json_node && json_node->type == cJSON_String) {
|
|
|
|
|
|
if (*uds_delete_url != NULL) {
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
|
|
|
free(*uds_delete_url);
|
|
|
|
|
|
}
|
|
|
|
|
|
*uds_delete_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
|
strcpy(*uds_delete_url, json_node->valuestring);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-16 16:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-29 15:05:36 +08:00
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
|
}
|
2025-01-16 16:17:01 +08:00
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|