https://api-proxy.gizadata.vn/
Trước khi sử dụng, cần cấu hình trong file config.php:
define('BACKEND_PROXY_URL', 'https://api-proxy.gizadata.vn/');
define('AGENT_ID', '1');
define('AGENT_API_KEY', 'your_api_key_here');
Có 2 cách để gọi API:
<?php
require_once 'agent_api.php';
$api = new AgentAPI($agent_id, $api_key);
// Xác thực
$result = $api->authenticate();
// Lấy số dư
$result = $api->getBalance();
// Tạo VPS
$result = $api->createVPS(
customer: [],
hostname: 'vps1.example.com',
planid: 1,
billingcycle: 'monthly',
password: 'SecurePassword123',
os: 'ubuntu-22.04',
quantity: 1
);
Frontend gọi API qua file setup.php với format JSON:
fetch('', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'authenticate'
})
})
.then(response => response.json())
.then(data => console.log(data));
| Action | Mô tả | Parameters | Response |
|---|---|---|---|
authenticate |
Xác thực agent | Không có | Thông tin agent (ID, tên, số dư, discount...) |
get_balance |
Lấy số dư ví | Không có | Số dư hiện tại |
| Action | Mô tả | Parameters |
|---|---|---|
create_vps |
Tạo VPS mới |
hostname (string),planid (int),billingcycle (string: monthly/quarterly/semiannually/annually),password (string),os (string),quantity (int, default: 1)
|
vps_action |
Thực hiện action trên VPS |
service_id (int),vps_action (string: start/stop/reboot/poweroff/reinstall/changehostname/changepassword/vnc),os_name (string, nếu action = reinstall),rootpass (string, nếu action = reinstall),new_hostname (string, nếu action = changehostname),new_password (string, nếu action = changepassword)
|
get_vps_status |
Lấy trạng thái VPS | service_id (int, optional - null để lấy tất cả) |
| Action | Mô tả | Parameters |
|---|---|---|
create_hosting |
Tạo Hosting mới |
domain (string),planid (int),billingcycle (string),password (string)
|
get_hosting_login_info |
Lấy thông tin đăng nhập Hosting | service_id (int) |
| Action | Mô tả | Parameters |
|---|---|---|
create_email |
Tạo Email mới (cPanel account) |
domain (string, required),planid (int, required),billingcycle (string, required: monthly/quarterly/semiannually/annually),password (string, required, min 8 chars)Lưu ý: Nếu password không đủ mạnh (thiếu uppercase/lowercase/numbers/symbols), hệ thống sẽ tự động generate password mạnh |
get_email_login_info |
Lấy thông tin đăng nhập Email | service_id (int, required) |
| Action | Mô tả | Parameters |
|---|---|---|
create_key |
Tạo Key mới |
product_id (int),quantity (int, default: 1),months (int, default: 1)
|
| Action | Mô tả | Parameters |
|---|---|---|
get_public_plans |
Lấy danh sách gói dịch vụ công khai | Không có |
get_customers |
Lấy danh sách customers | page (int), per_page (int) |
get_services |
Lấy danh sách services |
page (int),per_page (int),service_type (string, optional: vps/hosting/email/key)
|
get_transactions |
Lấy lịch sử giao dịch | page (int), per_page (int) |
get_package_os_templates |
Lấy danh sách OS templates cho package | package_id (int) |
Tất cả API đều trả về JSON với format:
{
"status": "success" | "error",
"message": "Mô tả kết quả",
"data": { ... },
"http_code": 200
}
{
"status": "success",
"message": "Tạo VPS thành công",
"data": {
"service_id": 123,
"order_id": 456,
"invoice_id": 789,
"hostname": "vps1.example.com",
"username": "vpsuser",
"price": 150000,
"wallet_balance_before": 1000000,
"wallet_balance_after": 850000,
"agent_transaction_id": 42
},
"http_code": 200
}
{
"status": "success",
"message": "Tạo Email thành công",
"data": {
"service_id": 123,
"order_id": 456,
"invoice_id": 789,
"domain": "example.com",
"username": "mail1234",
"price": 15000,
"amount_deducted": 15000,
"service_status": "Active",
"account_created": true,
"account_error": null,
"account_warning": null,
"discount_amount": 1500,
"discount_percentage": 10,
"wallet_balance_before": 1000000,
"wallet_balance_after": 985000,
"agent_transaction_id": 42
},
"http_code": 200
}
Giải thích các trường:
• amount_deducted: Số tiền thực tế đã trừ (chỉ khi account được tạo thành công)
• service_status: Trạng thái dịch vụ (Active/Pending)
• account_created: true nếu cPanel account được tạo thành công
• account_error: Thông báo lỗi nếu tạo account thất bại
• account_warning: Cảnh báo (ví dụ: DNS warning nhưng account vẫn được tạo)
{
"status": "error",
"message": "Số dư không đủ",
"http_code": 400
}
Frontend-agent gọi API qua backend-api với các action sau:
agent_auth - Xác thực agentagent_balance - Lấy số dưagent_customers - Lấy danh sách customersagent_services - Lấy danh sách servicesagent_transactions - Lấy lịch sử giao dịchagent_public_plans - Lấy danh sách gói dịch vụ công khaiagent_vps_create - Tạo VPSagent_vps_start - Start VPSagent_vps_stop - Stop VPSagent_vps_reboot - Reboot VPSagent_vps_poweroff - Power Off VPSagent_vps_reinstall - Reinstall OS VPSagent_vps_changehostname - Đổi hostname VPSagent_vps_changepassword - Đổi password VPSagent_vps_renew - Gia hạn VPSagent_vps_suspend - Suspend VPSagent_vps_unsuspend - Unsuspend VPSagent_vps_terminate - Terminate VPSagent_vps_status - Lấy trạng thái VPSagent_vps_vnc - Lấy VNC linkagent_hosting_create - Tạo Hostingagent_hosting_login_info - Lấy thông tin đăng nhập Hostingagent_email_create - Tạo Emailagent_email_login_info - Lấy thông tin đăng nhập Emailagent_key_create - Tạo Keyagent_id và api_key trong payload<?php
require_once 'agent_api.php';
$api = new AgentAPI('1', 'your_api_key_here');
$result = $api->createVPS(
customer: [],
hostname: 'vps1.example.com',
planid: 1,
billingcycle: 'monthly',
password: 'SecurePassword123!',
os: 'ubuntu-22.04',
quantity: 1
);
if ($result['status'] === 'success') {
echo "VPS đã được tạo thành công! Service ID: " . $result['data']['service_id'];
} else {
echo "Lỗi: " . $result['message'];
}
fetch('', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'create_vps',
hostname: 'vps1.example.com',
planid: 1,
billingcycle: 'monthly',
password: 'SecurePassword123!',
os: 'ubuntu-22.04',
quantity: 1
})
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
console.log('VPS đã được tạo:', data.data);
} else {
console.error('Lỗi:', data.message);
}
});
fetch('', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'create_email',
domain: 'example.com',
planid: 1,
billingcycle: 'monthly',
password: 'SecurePassword123!'
})
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
console.log('Email đã được tạo:', data.data);
console.log('Service ID:', data.data.service_id);
console.log('Username:', data.data.username);
console.log('Account Created:', data.data.account_created);
if (data.data.account_warning) {
console.warn('Warning:', data.data.account_warning);
}
} else {
console.error('Lỗi:', data.message);
}
});
curl -X POST "https://api-proxy.gizadata.vn/api.php?action=agent_auth" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "1",
"api_key": "your_api_key_here"
}'