เอกสาร Waypoint
หน้าเว็บไซต์ หลังบ้าน

🔌 API Reference

Endpoints สำหรับ integration ภายนอก ทุก API คืน JSON
Base URL: https://โดเมนของคุณ/api/ (development) — เปลี่ยนตาม deploy ของคุณ

คำนวณราคาส่งพัสดุ

Endpoint: GET /api/parcel_calc.php

Query parameters

ParameterTypeRequiredDescription
originint✓ID สถานีต้นทาง
destint✓ID สถานีปลายทาง
weightfloat✓น้ำหนัก (กก.)
typestringoptionaldocument / parcel / fragile / oversized / other (default: parcel)
declaredfloatoptionalมูลค่าประกัน (บาท)

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

ParameterRequiredDescription
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

ParameterRequiredDescription
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

ParameterRequiredDescription
token✓Device token (32 ตัวอักษร)
lat✓Latitude
lng✓Longitude
speedoptionalkm/h
headingoptional0-360 องศา
accuracyoptionalเมตร
tsoptionalเวลาที่บันทึก (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