// Sunucu API'si: kendi sitenden, botundan ya da mağaza entegrasyonundan lisans yönetmek. // Bu kod SENİN sunucunda / bilgisayarında çalışır, son kullanıcıya dağıttığın programa ASLA konmaz: // API anahtarı (sk_tenant_...) ele geçirilirse herkes adına lisans üretebilir. // // Kimlik: "Authorization: Bearer ". Ek olarak her istek HMAC ile imzalanır (X-WS-* başlıkları). // İmza şu an isteğe bağlı olsa da imzalı istek hem bugün hem imza zorunlu hâle gelirse çalışır. // anahtar = SHA256(API anahtarı) // kanonik = METOT \n yol+sorgu \n unix_zaman \n nonce \n sha256hex(gövde) // imza = base64(HMAC-SHA256(anahtar, kanonik)), bilgisayar saati ±5 dk doğru olmalı #include #include #include #include #include #include #include #include #include #pragma comment(lib, "winhttp.lib") #pragma comment(lib, "bcrypt.lib") #pragma comment(lib, "crypt32.lib") struct ApiResponse { DWORD status = 0; // HTTP durum kodu (200, 400, 401, 403, 404 ...) std::string body; // JSON metni }; class VendorClient { public: explicit VendorClient(std::string apiKey, std::wstring host = L"oyuncusteroidi.com", INTERNET_PORT port = INTERNET_DEFAULT_HTTPS_PORT, bool https = true) : key_(std::move(apiKey)), host_(std::move(host)), port_(port), https_(https) { hmacKey_ = Sha256(key_); } // ---- uçlar ---------------------------------------------------------------------------- ApiResponse Me() { return Call("GET", "/api/tenant/v1/me", ""); } // count: 1-50, durationSeconds: 0 = süresiz, mask: "*****-*****-*****-*****" gibi (en az 12 '*') ApiResponse Create(const std::string& product, int count, long long durationSeconds, int level, const std::string& note, const std::string& mask = "") { std::string body = "{\"gameName\":\"" + Esc(product) + "\",\"count\":" + std::to_string(count) + ",\"durationSeconds\":" + std::to_string(durationSeconds) + ",\"level\":" + std::to_string(level) + ",\"note\":\"" + Esc(note) + "\""; if (!mask.empty()) body += ",\"mask\":\"" + Esc(mask) + "\""; body += "}"; return Call("POST", "/api/tenant/v1/vendor/licenses/create", body); } // seconds > 0 süre ekler, < 0 süre düşer. Süresiz lisanslar atlanır ("skipped"). ApiResponse Extend(const std::string& key, long long seconds) { return Call("POST", "/api/tenant/v1/vendor/licenses/extend", "{\"key\":\"" + Esc(key) + "\",\"seconds\":" + std::to_string(seconds) + "}"); } ApiResponse Ban(const std::string& key, const std::string& reason) { return Call("POST", "/api/tenant/v1/vendor/licenses/ban", "{\"key\":\"" + Esc(key) + "\",\"note\":\"" + Esc(reason) + "\"}"); } ApiResponse Unban(const std::string& key) { return KeyAction("unban", key); } ApiResponse Pause(const std::string& key) { return KeyAction("pause", key); } ApiResponse Resume(const std::string& key) { return KeyAction("resume", key); } ApiResponse HwidReset(const std::string& key) { return KeyAction("hwid-reset", key); } ApiResponse Get(const std::string& key) { return Call("GET", "/api/tenant/v1/vendor/licenses/" + key, ""); } ApiResponse Delete(const std::string& key) { return Call("DELETE", "/api/tenant/v1/vendor/licenses/" + key, ""); } // status: "" | active | unused | expired | paused | banned. Sayfa başına 50 kayıt. ApiResponse List(const std::string& product, const std::string& status, int page) { std::string q = "/api/tenant/v1/vendor/licenses?page=" + std::to_string(page); if (!product.empty()) q += "&game=" + product; if (!status.empty()) q += "&status=" + status; return Call("GET", q, ""); } private: ApiResponse KeyAction(const char* action, const std::string& key) { return Call("POST", std::string("/api/tenant/v1/vendor/licenses/") + action, "{\"key\":\"" + Esc(key) + "\"}"); } ApiResponse Call(const std::string& method, const std::string& pathAndQuery, const std::string& body) { ApiResponse r; std::string ts = std::to_string((long long)time(nullptr)); std::string nonce = RandomHex(16); std::string canonical = method + "\n" + pathAndQuery + "\n" + ts + "\n" + nonce + "\n" + Hex(Sha256(body)); std::string sig = Base64(HmacSha256(hmacKey_, canonical)); HINTERNET ses = WinHttpOpen(L"OrnekSatisBotu/1.0", WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); HINTERNET con = ses ? WinHttpConnect(ses, host_.c_str(), port_, 0) : nullptr; HINTERNET req = con ? WinHttpOpenRequest(con, Wide(method).c_str(), Wide(pathAndQuery).c_str(), nullptr, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, https_ ? WINHTTP_FLAG_SECURE : 0) : nullptr; if (req) { std::wstring headers = L"Authorization: Bearer " + Wide(key_) + L"\r\nContent-Type: application/json" + L"\r\nX-WS-Timestamp: " + Wide(ts) + L"\r\nX-WS-Nonce: " + Wide(nonce) + L"\r\nX-WS-Signature: " + Wide(sig); BOOL ok = WinHttpSendRequest(req, headers.c_str(), (DWORD)-1L, body.empty() ? WINHTTP_NO_REQUEST_DATA : (LPVOID)body.data(), (DWORD)body.size(), (DWORD)body.size(), 0) && WinHttpReceiveResponse(req, nullptr); if (ok) { DWORD len = sizeof(r.status); WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX, &r.status, &len, WINHTTP_NO_HEADER_INDEX); DWORD avail = 0; while (WinHttpQueryDataAvailable(req, &avail) && avail > 0) { std::string chunk(avail, '\0'); DWORD got = 0; if (!WinHttpReadData(req, chunk.data(), avail, &got) || got == 0) break; r.body.append(chunk.data(), got); } } } if (req) WinHttpCloseHandle(req); if (con) WinHttpCloseHandle(con); if (ses) WinHttpCloseHandle(ses); return r; // status 0 = bağlantı kurulamadı } // ---- yardımcılar ---------------------------------------------------------------------- static std::wstring Wide(const std::string& s) { int n = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), nullptr, 0); std::wstring w(n, L'\0'); MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), w.data(), n); return w; } static std::string Esc(const std::string& s) // JSON metni için kaçış { std::string o; for (char c : s) { if (c == '"' || c == '\\') { o += '\\'; o += c; } else if ((unsigned char)c < 0x20) { char b[8]; sprintf_s(b, "\\u%04x", c); o += b; } else o += c; } return o; } static std::vector Digest(const std::vector* key, const std::string& data) { std::vector out(32); BCRYPT_ALG_HANDLE alg = nullptr; if (BCryptOpenAlgorithmProvider(&alg, BCRYPT_SHA256_ALGORITHM, nullptr, key ? BCRYPT_ALG_HANDLE_HMAC_FLAG : 0) == 0) { BCryptHash(alg, key ? (PUCHAR)key->data() : nullptr, key ? (ULONG)key->size() : 0, (PUCHAR)data.data(), (ULONG)data.size(), out.data(), (ULONG)out.size()); BCryptCloseAlgorithmProvider(alg, 0); } return out; } static std::vector Sha256(const std::string& data) { return Digest(nullptr, data); } static std::vector HmacSha256(const std::vector& key, const std::string& data) { return Digest(&key, data); } static std::string Hex(const std::vector& b) { static const char* d = "0123456789abcdef"; std::string s; for (BYTE x : b) { s += d[x >> 4]; s += d[x & 15]; } return s; } static std::string RandomHex(size_t bytes) { std::vector b(bytes); BCryptGenRandom(nullptr, b.data(), (ULONG)b.size(), BCRYPT_USE_SYSTEM_PREFERRED_RNG); return Hex(b); } static std::string Base64(const std::vector& b) { DWORD n = 0; CryptBinaryToStringA(b.data(), (DWORD)b.size(), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &n); std::string s(n, '\0'); CryptBinaryToStringA(b.data(), (DWORD)b.size(), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, s.data(), &n); s.resize(n); return s; } std::string key_; std::wstring host_; INTERNET_PORT port_; bool https_; std::vector hmacKey_; }; static void Print(const char* what, const ApiResponse& r) { printf("%-8s HTTP %lu %s\n", what, r.status, r.body.c_str()); } int main() { SetConsoleOutputCP(CP_UTF8); // Anahtarı koda yazma: ortam değişkeninden ya da sunucunun gizli ayarlarından oku. char* key = nullptr; size_t len = 0; if (_dupenv_s(&key, &len, "OS_API_KEY") != 0 || key == nullptr) { printf("OS_API_KEY ortam değişkeni ayarlı değil.\n"); return 1; } VendorClient api(key); free(key); Print("me", api.Me()); // {"ok":true,"tenant":{...},"active_packages":[...]} // Satış oldu: 30 günlük 1 anahtar üret ve müşteriye gönder. ApiResponse created = api.Create("t12_ornek", 1, 30LL * 86400, 1, "Sipariş #1042"); Print("create", created); // {"ok":true,"count":1,"keys":["ABCDE-..."]} // Örnek işlemler (kendi anahtarınla dene): // Print("extend", api.Extend("ABCDE-FGHJK-LMNPQ-RSTUV", 7LL * 86400)); // 7 gün ekle // Print("get", api.Get("ABCDE-FGHJK-LMNPQ-RSTUV")); // Print("ban", api.Ban("ABCDE-FGHJK-LMNPQ-RSTUV", "Ödeme iadesi")); Print("list", api.List("t12_ornek", "expired", 1)); return 0; }