🔌 API Reference
Endpoints สำหรับ integration ภายนอก ทุก API คืน JSON
API ทั้งหมด
Base URL:
https://โดเมนของคุณ/api/ (development) — เปลี่ยนตาม deploy ของคุณ
คำนวณราคาส่งพัสดุ
Endpoint: GET /api/parcel_calc.php
Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
origin | int | ✓ | ID สถานีต้นทาง |
dest | int | ✓ | ID สถานีปลายทาง |
weight | float | ✓ | น้ำหนัก (กก.) |
type | string | optional | document / parcel / fragile / oversized / other (default: parcel) |
declared | float | optional | มูลค่าประกัน (บาท) |
Example
GET /api/parcel_calc.php?origin=1&dest=4&weight=3&type=parcel&declared=1000
Response
{
"success": true,
"distance": 565,
"base": 285,
"weight": 15,
"surcharge": 0,
"insurance": 10,
"total": 310
}
คำนวณราคาตั๋ว
Endpoint: GET /api/calculate_fare.php
Query parameters
| Parameter | Required | Description |
|---|---|---|
route_id | ✓ | ID เส้นทาง |
from | ✓ | ID สถานีต้นทาง (ของลูกค้า) |
to | ✓ | ID สถานีปลายทาง (ของลูกค้า) |
bus_type_id | ✓ | ID ประเภทรถ |
Response
{
"success": true,
"distance": 259,
"fare": 470,
"price_per_km": 1.80,
"base_price": 80
}
เช็คที่นั่งว่าง
Endpoint: GET /api/check_seats.php
Query parameters
| Parameter | Required | Description |
|---|---|---|
trip_id | ✓ | ID เที่ยวรถ |
Response
{
"success": true,
"total_seats": 40,
"available": 32,
"booked_seats": ["1","2","5","8","11","20","25","30"],
"seat_layout": "2-2"
}
รับข้อมูล GPS จากอุปกรณ์
Endpoint: GET /api/gps_ingest.php
ใช้สำหรับอุปกรณ์ GPS (หรือแอพมือถือ Driver) ส่งพิกัดเข้าระบบ
Query parameters
| Parameter | Required | Description |
|---|---|---|
token | ✓ | Device token (32 ตัวอักษร) |
lat | ✓ | Latitude |
lng | ✓ | Longitude |
speed | optional | km/h |
heading | optional | 0-360 องศา |
accuracy | optional | เมตร |
ts | optional | เวลาที่บันทึก (default: NOW) |
Example
curl "http://yoursite.com/api/gps_ingest.php?token=abc123&lat=14.5343&lng=100.9099&speed=85"
Response
{
"success": true,
"device_id": 1,
"trip_id": 5,
"recorded_at": "2026-05-17 15:47:34"
}
Error Response
{ "success": false, "error": "invalid token" } // 401
{ "success": false, "error": "missing token/lat/lng" } // 400
ดึงตำแหน่งรถล่าสุดทั้งหมด
Endpoint: GET /api/gps_live.php
ส่งคืน list ของรถ active ทุกคันพร้อมตำแหน่งล่าสุด — ใช้สำหรับ live map / dashboard
Response
{
"success": true,
"devices": [
{
"id": 1,
"bus": "10-1234",
"imei": "860123456789012",
"lat": 14.5343,
"lng": 100.9099,
"speed": 85,
"last_seen": "15:47:34",
"online": true,
"battery": null
},
{
"id": 2,
"bus": "10-5678",
"imei": "860123456789013",
"lat": null,
"lng": null,
"speed": null,
"last_seen": null,
"online": false,
"battery": null
}
]
}
Field descriptions
online— true ถ้า last_seen_at < 5 นาทีlat/lng— null ถ้าอุปกรณ์ยังไม่เคยส่งข้อมูลlast_seen— เวลา HH:MM:SS (string)
