#include <iostream>
#include <map>
#include <string>
#include <openssl/hmac.h>
#include <iomanip>
#include <sstream>
std::string hmac_sha256(const std::string& key, const std::string& data) {
unsigned char hash[EVP_MAX_MD_SIZE];
unsigned int len = 0;
HMAC_CTX* ctx = HMAC_CTX_new();
HMAC_Init_ex(ctx, key.c_str(), key.length(), EVP_sha256(), NULL);
HMAC_Update(ctx, (unsigned char*)data.c_str(), data.length());
HMAC_Final(ctx, hash, &len);
HMAC_CTX_free(ctx);
std::stringstream ss;
for(unsigned int i = 0; i < len; i++) {
ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
}
return ss.str();
}
int main() {
// Configuration
const std::string api_key = "pck_payment_my3T68cbuIXf1x3QOEbWtFEfcJPxeBr8wTewDVM";
const std::string secret_key = "sck_QOoPSlHDSsgXYeNyTP2i0ug1HKLRjHw9Ug7mCc1Q0";
const long request_time = 1743060268000;
// Sample parameters
std::map<std::string, std::string> params = {
{"amount", "44"},
{"bizOrderNo", "B234569885XASA953ASDSAD"},
{"chainId", "11155111"},
{"custNo", "473_860001"},
{"merchantId", "286000260"},
{"symbol", "USDT"},
{"toAddress", "0xc87dd49427a188bf2b601c1d5cd2aaf36bd553d2"},
{"remark", "demo for create payout order"}
};
// Step 1: Sort parameters
std::stringstream query_stream;
for(auto it = params.begin(); it != params.end(); ++it) {
if(it != params.begin()) query_stream << "&";
query_stream << it->first << "=" << it->second;
}
// Step 2: Add timestamp
std::string payload = query_stream.str() + "&time=" + std::to_string(request_time);
// Step 3: Compute HMAC
std::string signature = hmac_sha256(secret_key, payload);
// Prepare headers
std::cout << "Request Headers:" << std::endl;
std::cout << "BlockATM-API-Key: " << api_key << std::endl;
std::cout << "BlockATM-Signature-V1: " << signature << std::endl;
std::cout << "BlockATM-Request-Time: " << request_time << std::endl;
return 0;
}