สถานะโมดูลระบบ
API Endpoints ที่พร้อมใช้งาน
คู่มือการใช้งาน API
แนะนำ
SmartPR Kiosk API เป็น RESTful API ที่ให้บริการข้อมูลต่างๆ ของระบบ เช่น ข่าวสาร, หลักสูตร, กิจกรรม, Slideshow และอื่นๆ คุณสามารถเรียกใช้ API ผ่าน HTTP GET Request และรับข้อมูลกลับมาในรูปแบบ JSON
Base URL
http://localhost/pr_web/api/
(สำหรับ Production: https://ict.prasat.ac.th/api/)
Slideshow API
GET /api/slideshow.php
ดึงรายการรูปภาพสำหรับแสดงแบบ Slideshow
// JavaScript - Fetch API
fetch('http://localhost/pr_web/api/slideshow.php')
.then(response => response.json())
.then(data => {
console.log(data);
// แสดงผล slideshow
});
Contents API
GET /api/contents.php
ดึงรายการข่าวสาร/ประกาศ
category- กรองตามหมวดหมู่: news, announcement, event, achievementstatus- กรองตามสถานะ: published, draft, archivedlimit- จำนวนรายการต่อหน้า (default: 20)offset- เริ่มต้นที่รายการที่ (default: 0)
// ดึงข่าวสารล่าสุด 10 รายการ
fetch('http://localhost/pr_web/api/contents.php?category=news&limit=10')
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('ข่าวสาร:', data.data.items);
}
});
Courses API
GET /api/courses.php
ดึงรายการหลักสูตร
id- ดึงข้อมูล 1 หลักสูตร (พร้อมคุณสมบัติและอาชีพ)level- กรองตามระดับ: ปวช., ปวส.department- กรองตามแผนกsearch- ค้นหาด้วยชื่อหลักสูตร
// ดึงหลักสูตร ปวส. ทั้งหมด
fetch('http://localhost/pr_web/api/courses.php?level=ปวส.')
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('หลักสูตร:', data.data.items);
}
});
Events API
GET /api/events.php
ดึงรายการกิจกรรม
status- กรองตามสถานะ: upcoming, ongoing, completedevent_type- กรองตามประเภท: academic, sports, culturalmonth- กรองตามเดือน (format: YYYY-MM)start_date,end_date- ช่วงวันที่ (format: YYYY-MM-DD)
// ดึงกิจกรรมที่กำลังจะมาถึง
fetch('http://localhost/pr_web/api/events.php?status=upcoming')
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('กิจกรรม:', data.data.items);
}
});
Emergency Alerts API
GET /api/emergency_alerts.php
ดึงรายการการแจ้งเตือนฉุกเฉิน (เฉพาะที่ active)
// ตรวจสอบการแจ้งเตือนฉุกเฉิน
fetch('http://localhost/pr_web/api/emergency_alerts.php')
.then(response => response.json())
.then(data => {
if (data.success && data.data.length > 0) {
// แสดงการแจ้งเตือน
console.log('แจ้งเตือนฉุกเฉิน:', data.data);
}
});
Settings API
GET /api/settings.php
ดึงการตั้งค่าระบบ
key- ดึงค่าการตั้งค่าเดียว เช่น school_name
// ดึงค่าการตั้งค่าทั้งหมด
fetch('http://localhost/pr_web/api/settings.php')
.then(response => response.json())
.then(data => {
console.log('การตั้งค่า:', data.data);
});
Services API (งานบริการติดต่อ)
GET /api/services.php
ดึงรายการงานบริการติดต่อทั้งหมด เช่น ขอใบรับรอง, ชำระค่าเทอม
id- ดึงรายละเอียดงานบริการ 1 รายการcategory- กรองตามหมวดหมู่ เช่น งานทะเบียน, งานการเงินsearch- ค้นหาจากชื่อหรือคำอธิบายaction=categories- ดึงรายการหมวดหมู่ทั้งหมด
// ดึงงานบริการทั้งหมด
fetch('http://localhost/pr_web/api/services.php')
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('งานบริการ:', data.data);
}
});
// ดึงรายละเอียดงานบริการ ID=1
fetch('http://localhost/pr_web/api/services.php?id=1')
// กรองตามหมวดหมู่
fetch('http://localhost/pr_web/api/services.php?category=งานทะเบียน')
Service Advisor API (AI แนะนำงานบริการ)
POST /api/service_advisor.php
ใช้ AI (DeepSeek) วิเคราะห์คำถามและแนะนำงานบริการที่เหมาะสม
{
"question": "ต้องการขอใบรับรองไปสมัครงาน ต้องทำอย่างไร"
}
{
"success": true,
"data": {
"answer": "สำหรับการขอใบรับรอง...",
"suggested_services": [
{
"id": 1,
"name": "ขอใบรับรองการเป็นนักศึกษา",
"department": "งานทะเบียน",
"fee": "20 บาท"
}
]
}
}
// ถาม AI เพื่อแนะนำงานบริการ
fetch('http://localhost/pr_web/api/service_advisor.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
question: 'ต้องการขอใบรับรองไปสมัครงาน'
})
})
.then(response => response.json())
.then(data => {
console.log('AI ตอบ:', data.data.answer);
console.log('แนะนำ:', data.data.suggested_services);
});
รูปแบบ Response
API ทั้งหมดจะ Return ข้อมูลในรูปแบบ JSON พื้นฐาน:
// สำเร็จ
{
"success": true,
"data": [...],
"message": "Operation successful"
}
// ผิดพลาด
{
"success": false,
"error": "Error message",
"code": 400
}
CORS & Security
- API รองรับ CORS สามารถเรียกใช้จาก Domain ใดก็ได้
- GET requests ไม่ต้องใช้ Authentication
- POST/PUT/DELETE requests จะต้องใช้ Token ในอนาคต
- แนะนำให้ใช้ HTTPS สำหรับ Production