Tài Liệu Tích Hợp License Key Cho Dev
Hướng dẫn gắn API xác thực bản quyền AutoMarket vào code Python hoặc Node.js để bảo vệ tool chống leak
1. Tích Hợp Vào Script Python
Dán đoạn code sau vào đầu file `main.py` của tool để tự động kiểm tra key và khóa HWID của người mua:
import requests
import uuid
import sys
LICENSE_KEY = "AM-HQ98-4721-ABCD" # Người dùng điền vào file .env hoặc config.json
API_URL = "http://localhost:3000/api/license/verify" # Thay bằng domain của bạn
def get_hwid():
return str(uuid.getnode())
def verify_license():
try:
hwid = get_hwid()
res = requests.post(API_URL, json={
"key": LICENSE_KEY,
"hwid": hwid,
"toolSlug": "hack-quest-automate"
}, timeout=10)
data = res.json()
if data.get("valid"):
print(f"[+] License hợp lệ! Xin chào {data['license']['owner']}")
return True
else:
print(f"[-] Lỗi xác thực: {data.get('message')}")
sys.exit(1)
except Exception as e:
print(f"[-] Không thể kết nối server xác thực: {e}")
sys.exit(1)
verify_license()
2. Tích Hợp Vào Script Node.js
import os from 'os';
async function checkLicense(licenseKey, toolSlug) {
const hwid = os.hostname() + '-' + os.userInfo().username;
try {
const res = await fetch('http://localhost:3000/api/license/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: licenseKey, hwid, toolSlug })
});
const data = await res.json();
if (data.valid) {
console.log('✅ Kích hoạt bản quyền thành công!');
return true;
} else {
console.error('❌ ' + data.message);
process.exit(1);
}
} catch (err) {
console.error('Lỗi kết nối máy chủ xác thực');
process.exit(1);
}
}