ตรวจสอบสลิปด้วย Base64
ตรวจสอบสลิปธนาคารด้วยรูปภาพที่เข้ารหัส Base64
Endpoint
http
POST /verifyURL เต็ม: https://developer.easyslip.com/api/v1/verify
การยืนยันตัวตน
จำเป็น ดูคู่มือการยืนยันตัวตน
http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/jsonRequest
พารามิเตอร์
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
image | string | ใช่ | รูปภาพ Base64 (มีหรือไม่มี data URI prefix ก็ได้) |
checkDuplicate | boolean | ไม่ | ตรวจสอบสลิปซ้ำ |
รูปแบบ Base64
รับได้ทั้งสองรูปแบบ:
# มี data URI prefix
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA...
# ไม่มี prefix
/9j/4AAQSkZJRgABAQAA...ข้อกำหนดรูปภาพ
| ข้อกำหนด | ค่า |
|---|---|
| ขนาดสูงสุดหลัง decode | 4 MB |
| รูปแบบที่รองรับ | JPEG, PNG, GIF, WebP |
Type Definitions
typescript
// Request
interface VerifyByBase64Request {
image: string; // รูปภาพ Base64
checkDuplicate?: boolean;
}
// Response
interface VerifyResponse {
status: 200;
data: SlipData;
}
interface SlipData {
payload: string;
transRef: string;
date: string; // ISO 8601
countryCode: string;
amount: Amount;
fee: number;
ref1: string;
ref2: string;
ref3: string;
sender: Party;
receiver: Party;
}
interface Amount {
amount: number;
local: {
amount: number;
currency: string;
};
}
interface Party {
bank: {
id: string;
name: string;
short: string;
};
account: {
name: {
th?: string;
en?: string;
};
bank?: {
type: 'BANKAC' | 'TOKEN' | 'DUMMY';
account: string;
};
proxy?: {
type: 'NATID' | 'MSISDN' | 'EWALLETID' | 'EMAIL' | 'BILLERID';
account: string;
};
};
}
// Error Response
interface ErrorResponse {
status: number;
message: string;
data?: SlipData; // สำหรับกรณีสลิปซ้ำ
}ตัวอย่าง
bash
curl -X POST https://developer.easyslip.com/api/v1/verify \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA...",
"checkDuplicate": true
}'javascript
// แปลงไฟล์เป็น Base64
const fileToBase64 = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(file);
});
};
// ตรวจสอบสลิป
const verifyByBase64 = async (base64, options = {}) => {
const response = await fetch('https://developer.easyslip.com/api/v1/verify', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
image: base64,
checkDuplicate: options.checkDuplicate
})
});
const result = await response.json();
if (result.status !== 200) {
throw new Error(result.message);
}
return result.data;
};
// การใช้งานกับ file input
const fileInput = document.getElementById('slipImage');
fileInput.addEventListener('change', async (e) => {
const file = e.target.files[0];
const base64 = await fileToBase64(file);
try {
const slip = await verifyByBase64(base64, { checkDuplicate: true });
console.log('จำนวนเงิน:', slip.amount.amount);
} catch (error) {
console.error('Error:', error.message);
}
});php
function verifyByBase64(string $base64, bool $checkDuplicate = false): array
{
$apiKey = getenv('EASYSLIP_API_KEY');
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://developer.easyslip.com/api/v1/verify',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'image' => $base64,
'checkDuplicate' => $checkDuplicate
])
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['status'] !== 200) {
throw new Exception($result['message']);
}
return $result['data'];
}
// การใช้งานกับไฟล์
$imageData = file_get_contents('/path/to/slip.jpg');
$base64 = base64_encode($imageData);
$slip = verifyByBase64($base64, true);
echo "จำนวนเงิน: " . $slip['amount']['amount'];python
import requests
import base64
import os
def verify_by_base64(base64_data: str, check_duplicate: bool = False) -> dict:
response = requests.post(
'https://developer.easyslip.com/api/v1/verify',
headers={
'Authorization': f'Bearer {os.environ["EASYSLIP_API_KEY"]}',
'Content-Type': 'application/json'
},
json={
'image': base64_data,
'checkDuplicate': check_duplicate
}
)
result = response.json()
if result['status'] != 200:
raise Exception(result['message'])
return result['data']
# การใช้งานกับไฟล์
with open('./slip.jpg', 'rb') as f:
image_data = f.read()
base64_data = base64.b64encode(image_data).decode('utf-8')
slip = verify_by_base64(base64_data, check_duplicate=True)
print(f"จำนวนเงิน: {slip['amount']['amount']}")Response
สำเร็จ (200)
json
{
"status": 200,
"data": {
"payload": "00000000000000000000000000000000000000000000000",
"transRef": "68370160657749I376388B35",
"date": "2024-01-15T14:30:00+07:00",
"amount": {
"amount": 1500.00
},
"sender": {
"bank": { "id": "004", "name": "กสิกรไทย", "short": "KBANK" },
"account": { "name": { "th": "นาย ผู้โอน ทดสอบ" } }
},
"receiver": {
"bank": { "id": "014", "name": "ไทยพาณิชย์", "short": "SCB" },
"account": { "name": { "th": "นาย รับเงิน ทดสอบ" } }
}
}
}Error Responses
Base64 ไม่ถูกต้อง (400)
json
{
"status": 400,
"message": "invalid_base64"
}รูปภาพใหญ่เกินไป (400)
json
{
"status": 400,
"message": "image_size_too_large"
}ไม่พบ QR Code (404)
json
{
"status": 404,
"message": "qrcode_not_found"
}หมายเหตุ
- บีบอัดรูปก่อนเข้ารหัสเพื่อลดขนาด payload
- สำหรับ JPEG ใช้ quality 0.7-0.9 มักจะเพียงพอ
- ใส่ data URI prefix ช่วยให้ตรวจจับ MIME type ได้
- ล้าง Base64 string หลังใช้งานในแอปที่ sensitive