💻 Ví dụ gọi API
Port mặc định 8765. Không header auth. Trên Windows, JSON trong curl -d dễ lỗi quoting — dùng PowerShell Invoke-RestMethod cho chắc.
curl
# Health
curl -s http://127.0.0.1:8765/api/v1/health
# Cửa sổ / exe
curl -s "http://127.0.0.1:8765/api/v1/windows?process=dnplayer.exe"
curl -s "http://127.0.0.1:8765/api/v1/exes?process=dnplayer"
curl -s http://127.0.0.1:8765/api/v1/windows/198764
# Scripts + jobs
curl -s http://127.0.0.1:8765/api/v1/scripts
curl -s http://127.0.0.1:8765/api/v1/jobs
curl -s http://127.0.0.1:8765/api/v1/scripts/DemoFlow/status
# Start 1 cửa sổ
curl -s -X POST -H "Content-Type: application/json" \
-d "{\"hwnd\":198764,\"variables\":{\"mode\":\"fast\"}}" \
http://127.0.0.1:8765/api/v1/scripts/DemoFlow/start
# Đa luồng mọi dnplayer, tối đa 3 luồng
curl -s -X POST -H "Content-Type: application/json" \
-d "{\"process\":\"dnplayer.exe\",\"max_threads\":3,\"arrange\":true}" \
http://127.0.0.1:8765/api/v1/scripts/DemoFlow/start-mt
# Stop một HWND
curl -s -X POST -H "Content-Type: application/json" \
-d "{\"hwnd\":198764}" \
http://127.0.0.1:8765/api/v1/scripts/DemoFlow/stop
# Stop all
curl -s -X POST http://127.0.0.1:8765/api/v1/run/stopPython
import requests
BASE = "http://127.0.0.1:8765/api/v1"
def api(method, path, **kw):
r = requests.request(method, BASE + path, timeout=30, **kw)
r.raise_for_status()
return r.json()
print(api("GET", "/health"))
# Check exe còn mở không
exes = api("GET", "/exes", params={"process": "dnplayer.exe"})["exes"]
windows = exes[0]["windows"] if exes else []
for w in windows:
one = api("GET", f"/windows/{w['hwnd']}")
print(w["title"], one["window"]["alive"], one["window"]["client_w"], one["window"]["client_h"])
# Chạy đa luồng
body = {
"windows": [{"hwnd": w["hwnd"], "title": w["title"], "process": w["process"]} for w in windows],
"max_threads": min(3, len(windows) or 1),
"arrange": True,
"variables": {"taikhoan": "acc01"},
}
print(api("POST", "/scripts/DemoFlow/start-mt", json=body))
# Poll
st = api("GET", "/scripts/DemoFlow/status")
print(st["running_count"], st["jobs"])PowerShell
$Base = "http://127.0.0.1:8765/api/v1"
Invoke-RestMethod "$Base/health"
$exes = (Invoke-RestMethod "$Base/exes?process=dnplayer.exe").exes
$wins = $exes[0].windows
Invoke-RestMethod -Method Post -Uri "$Base/scripts/DemoFlow/start-mt" -ContentType "application/json" -Body (@{
windows = @($wins | ForEach-Object { @{ hwnd = $_.hwnd; title = $_.title; process = $_.process } })
max_threads = 2
arrange = $true
} | ConvertTo-Json -Depth 5)
Invoke-RestMethod "$Base/scripts/DemoFlow/status"
Invoke-RestMethod -Method Post -Uri "$Base/scripts/DemoFlow/stop" -ContentType "application/json" -Body (@{ hwnd = $wins[0].hwnd } | ConvertTo-Json)