258 行
8.9 KiB
MQL5
258 行
8.9 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| Customers.mqh |
| |||
//| Copyright 2025, Niquel Mendoza. |
| |||
//| https://www.mql5.com/es/users/nique_372 |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "Copyright 2025, Niquel Mendoza."
| |||
#property link "https://www.mql5.com/es/users/nique_372"
| |||
#property strict
| |||
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
#include "Base.mqh"
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
class CTbpCustomers : public CTbpBase
| |||
{
| |||
private:
| |||
ITbpAdditionalData* m_aditional_data;
| |||
string m_software_id;
| |||
| |||
public:
| |||
CTbpCustomers(void) : m_software_id(NULL), m_aditional_data(NULL) {}
| |||
~CTbpCustomers(void) {}
| |||
| |||
//--- Getters \ Setters
| |||
// Dato adicional
| |||
ITbpAdditionalData* AdditionalData() { return m_aditional_data; }
| |||
void AdditionalData(ITbpAdditionalData* ptr) { m_aditional_data = ptr; }
| |||
| |||
// Software id
| |||
string SoftwareId() const { return m_software_id; }
| |||
void SoftwareId(const string& software_id) { m_software_id = software_id; }
| |||
| |||
//---
| |||
// Nota importante
| |||
// Las funciones reontanr un bool de exito o falso en la llamda \ parse json como tal no el valor
| |||
// Para eso consulten el json o hay funciones que ya trean un &out
| |||
| |||
// Get customers of a software
| |||
// Lista clientes de un software concreto.
| |||
bool GetCustomersSotfware(); // Para el resultado consultar el json
| |||
| |||
//---
| |||
// User has software
| |||
// Verifica licencia incluyendo datos adicionales.
| |||
bool UserHasSoftware(const string& userd_id, bool &out); // Resultado en out
| |||
| |||
//---
| |||
// User has software (no additional data)
| |||
// Comprueba si un usuario posee una licencia sin la necesidad de enviar un dato adicional.
| |||
// ATENCIÓN: este endpoint no valida datos adicionales asociados a la licencia, por lo que puede si un
| |||
// tercero posee el userId podrá usar tu bot. Este endpoint está pensado para la reventa de bots.
| |||
bool UserHastSoftwareNoaAdditionalData(const string& userd_id, bool &out); // Resultado en out
| |||
| |||
| |||
//---
| |||
// User has software (Telegram)
| |||
// Comprueba licencia usando identificador de Telegram.
| |||
bool UserHastSoftwareTelegram(const string& telegram_user, bool use_aditional_data, bool& out); // Resultado en out
| |||
| |||
//---
| |||
// First demo download
| |||
// Comprueba si es la primera descarga de demo de un software.
| |||
bool FirstDemoDowlandSoftware(const string& user_id, datetime& out); // Resultado en out
| |||
| |||
| |||
//---
| |||
// Check job delivery access
| |||
// Verifica si un usuario puede acceder a la entrega de un trabajo.
| |||
// bool CheckJobDeliveryAccess();
| |||
| |||
};
| |||
| |||
//+------------------------------------------------------------------+
| |||
bool CTbpCustomers::GetCustomersSotfware(void)
| |||
{
| |||
//---
| |||
string res_headers;
| |||
char data[], result[];
| |||
string req_headers = "api-key: " + m_api_key + "\r\n";
| |||
const string url = THE_BOT_PLACE_BASE_URL + "customers/" + m_software_id;
| |||
| |||
//---
| |||
const int request = WebRequest(
| |||
"GET",
| |||
url,
| |||
req_headers,
| |||
m_timeout,
| |||
data,
| |||
result,
| |||
res_headers
| |||
);
| |||
| |||
//---
| |||
const string msg = CharArrayToString(result);
| |||
| |||
//---
| |||
if(request != 200)
| |||
{
| |||
LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
return m_json.Parse(msg);
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
bool CTbpCustomers::UserHasSoftware(const string& userd_id, bool &out)
| |||
{
| |||
//---
| |||
string res_headers;
| |||
char data[], result[];
| |||
string req_headers = "api-key: " + m_api_key + "\r\n";
| |||
// URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/customers/user-has-product?userId=<userId>&softwareId=<softwareId>&additional=<additional>
| |||
const string url = StringFormat("%scustomers/user-has-product?userId=%s&softwareId=%s&additional=%s",
| |||
THE_BOT_PLACE_BASE_URL, userd_id, m_software_id, m_aditional_data.Get());
| |||
| |||
//---
| |||
const int request = WebRequest(
| |||
"GET",
| |||
url,
| |||
req_headers,
| |||
m_timeout,
| |||
data,
| |||
result,
| |||
res_headers
| |||
);
| |||
| |||
//---
| |||
const string msg = CharArrayToString(result);
| |||
| |||
//---
| |||
if(request != 200)
| |||
{
| |||
LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
out = (msg == "true");
| |||
return true;
| |||
}
| |||
//+------------------------------------------------------------------+
| |||
bool CTbpCustomers::UserHastSoftwareNoaAdditionalData(const string &userd_id, bool &out)
| |||
{
| |||
//---
| |||
string res_headers;
| |||
char data[], result[];
| |||
string req_headers = "api-key: " + m_api_key + "\r\n";
| |||
// URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/customers/user-has-product-no-additional?userId=<userId>&softwareId=<softwareId>
| |||
const string url = StringFormat("%scustomers/user-has-product-no-additional?userId=%s&softwareId=%s",
| |||
THE_BOT_PLACE_BASE_URL, userd_id, m_software_id);
| |||
| |||
//---
| |||
const int request = WebRequest(
| |||
"GET",
| |||
url,
| |||
req_headers,
| |||
m_timeout,
| |||
data,
| |||
result,
| |||
res_headers
| |||
);
| |||
| |||
//---
| |||
const string msg = CharArrayToString(result);
| |||
| |||
//---
| |||
if(request != 200)
| |||
{
| |||
LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
out = (msg == "true");
| |||
return true;
| |||
}
| |||
//+------------------------------------------------------------------+
| |||
bool CTbpCustomers::UserHastSoftwareTelegram(const string &telegram_user, bool use_aditional_data, bool &out)
| |||
{
| |||
//---
| |||
string res_headers;
| |||
char data[], result[];
| |||
string req_headers = "api-key: " + m_api_key + "\r\n";
| |||
// URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/customers/user-has-product-by-telegram?telegram=<telegram>&softwareId=<softwareId>&additional=<additional>
| |||
string url = StringFormat("%scustomers/user-has-product-by-telegram?telegram=%s&softwareId=%s",
| |||
THE_BOT_PLACE_BASE_URL, telegram_user, m_software_id);
| |||
if(use_aditional_data)
| |||
url += "&additional=" + m_aditional_data.Get();
| |||
| |||
//---
| |||
const int request = WebRequest(
| |||
"GET",
| |||
url,
| |||
req_headers,
| |||
m_timeout,
| |||
data,
| |||
result,
| |||
res_headers
| |||
);
| |||
| |||
//---
| |||
const string msg = CharArrayToString(result);
| |||
| |||
//---
| |||
if(request != 200)
| |||
{
| |||
LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
out = (msg == "true");
| |||
return true;
| |||
}
| |||
//+------------------------------------------------------------------+
| |||
bool CTbpCustomers::FirstDemoDowlandSoftware(const string &user_id, datetime &out)
| |||
{
| |||
//---
| |||
string res_headers;
| |||
char data[], result[];
| |||
string req_headers = "api-key: " + m_api_key + "\r\n";
| |||
// URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/software/first-demo-download?userId=<userId>&softwareId=<softwareId>
| |||
const string url = StringFormat("%ssoftware/first-demo-download?userId=%s&softwareId=%s",
| |||
THE_BOT_PLACE_BASE_URL, user_id, m_software_id);
| |||
| |||
//---
| |||
const int request = WebRequest(
| |||
"GET",
| |||
url,
| |||
req_headers,
| |||
m_timeout,
| |||
data,
| |||
result,
| |||
res_headers
| |||
);
| |||
| |||
//---
| |||
const string msg = CharArrayToString(result);
| |||
| |||
//---
| |||
if(request != 200)
| |||
{
| |||
LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
out = datetime(long(msg)); // Viene en unix
| |||
return true;
| |||
}
| |||
//+------------------------------------------------------------------+
|