NIDA Gate Access Service API

เอกสารแสดงฟังก์ชันการทำงานและชุดคำสั่งในการทดสอบเชื่อมต่อประตูห้องสมุด NIDA
Server Base URL: http://localhost:5001

1. Health Check Endpoint

ตรวจสอบสถานะของบริการและตรวจสอบความสามารถในการเชื่อมต่อฐานข้อมูล MySQL (nida_gate_db)

GET /api/gate/health Check service & database connectivity

Parameters

No query or body parameters required.

Example Curl Request

CURL
curl -s http://localhost:5001/api/gate/health

API Playground

กดปุ่มด้านล่างเพื่อทดสอบยิง API จริง

2. Status Check Endpoint

ตรวจสอบข้อมูลการเข้าห้องสมุดล่าสุดของสมาชิก หรือ บัตร Visitor (Kiosk) โดยค้นหาจากรหัสพนักงาน/บัตร

GET /api/gate/status Get user or kiosk status

Query Parameters

Parameter Type Required Description
type string Optional ชนิดของผู้ใช้: user (ค่าเริ่มต้น) หรือ kiosk
id string Yes รหัสพนักงาน (EmpId) หรือรหัสบัตร (CardId)

Example Curl Request

CURL
curl -s "http://localhost:5001/api/gate/status?type=user&id=230353028"

API Playground

ตัวอย่าง ID จริง: 230353028 (User), 9900000068 (Kiosk)

3. Reset Anti-Passback Endpoint

ล้างสถานะ Anti-passback (ตั้งค่า LastAccess เป็น NULL) เพื่ออนุญาตให้สมาชิกคนดังกล่าวยิงบัตรผ่านเข้าออกประตูได้อีกครั้ง

POST /api/gate/reset Reset access status to NULL

JSON Body Parameters

Parameter Type Required Description
type string Optional user (ค่าเริ่มต้น) หรือ kiosk
id string Yes รหัสพนักงาน (EmpId) หรือหมายเลขการ์ด (CardId)

Example Curl Request

CURL
curl -s -X POST -H "Content-Type: application/json" \
  -d '{"type": "user", "id": "230353028"}' \
  http://localhost:5001/api/gate/reset

API Playground

4. Encrypted QR Generator Endpoint

สร้างชุด Payload รหัส QR Code ที่เข้ารหัสลับตามฟอร์แมตมหาวิทยาลัย (AES-GCM และฟอร์แมต 89/90/91 Legacy) พร้อมรูปภาพรหัส QR แบบ Base64

POST /api/gate/qrcode Generate encrypted QR code

JSON Body Parameters

Parameter Type Required Description
id string Yes รหัสนักศึกษา/พนักงาน
name string Yes ชื่อ-นามสกุล
title string Optional คำนำหน้าชื่อ (เช่น นาย, นางสาว)
expiration_date string Yes วันหมดอายุรูปแบบ YYYY-MM-DD

Example Curl Request

CURL
curl -s -X POST -H "Content-Type: application/json" \
  -d '{"id": "60123456", "title": "นาย", "name": "สมชาย รักดี", "expiration_date": "2028-12-31"}' \
  http://localhost:5001/api/gate/qrcode

API Playground

QR Code Preview

5. Scan QR Code Endpoint

จำลองการสแกนรหัส QR Code ที่ผ่านการเข้ารหัส เพื่ออัปเดตสถานะการเข้า/ออกห้องสมุด (IN/OUT) และบันทึกเวลาจริง (LastTime/In/Out) ลงฐานข้อมูล

POST /api/gate/scan Scan and process gate access

JSON Body Parameters

Parameter Type Required Description
qr_code string Yes ค่ารหัส QR Code เต็มรูปแบบ (ที่ได้จากการสร้างในหัวข้อด้านบน)

Example Curl Request

CURL
curl -s -X POST -H "Content-Type: application/json" \
  -d '{"qr_code": "8925id:60123456,dt:..."}' \
  http://localhost:5001/api/gate/scan

API Playground

6. Virtual ID Card Endpoint

สร้างภาพรูปบัตรนักศึกษาเสมือนจริงในรูปแบบ JPEG โดยเขียนชื่อภาษาไทยและนำรหัส QR รหัสมหาวิทยาลัยมาวางซ้อนทับอย่างสวยงามพร้อมส่งคืนในรูปแบบ Binary stream

POST /api/gate/virtual-card Generate virtual ID card JPEG

JSON Body Parameters

มีโครงสร้าง JSON เหมือนกับ API สร้าง QR Code ด้านบน

Example Curl Request

CURL
curl -s -X POST -H "Content-Type: application/json" \
  -d '{"id": "60123456", "title": "นาย", "name": "สมชาย รักดี", "expiration_date": "2028-12-31"}' \
  -o virtual_card.jpg \
  http://localhost:5001/api/gate/virtual-card

API Playground

Virtual ID Card Preview