lihiSMS | 行銷簡訊系統API串接 (OTP 服務)
lihiSMS OTP 串接教學:快速整合簡訊驗證到網站與 APP
核心功能
- OTP 發送:傳送一次性密碼至用戶手機。
- OTP 驗證:使用者輸入收到的驗證碼後,系統比對是否正確。
如何申請 Verify Token
-
登入 短網址後台
如何查看串接文件
- 登入 短網址後台
- 點選左側選單:進階工具 > 串接 API > 簡訊 OTP API
- 點擊收合選單即可查看

使用範例:PHP 實作
<?php
// 發送 OTP 的範例
function sendOtpExample() {
$data = [
'phone' => '+886912345678'
];
$headers = [
'X-VERIFY-TOKEN: your_verification_token_here',
'Content-Type: application/json'
];
$ch = curl_init('https://app.lihi.io/api/otp/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode === 200) {
echo "OTP 發送成功:" . $result['message'] . "\n";
} else {
echo "OTP 發送失敗:" . $result['message'] . "\n";
}
}
// 驗證 OTP 的範例
function verifyOtpExample() {
$data = [
'phone' => '+886912345678',
'otp' => '123456'
];
$headers = [
'X-VERIFY-TOKEN: your_verification_token_here',
'Content-Type: application/json'
];
$ch = curl_init('https://app.lihi.io/api/otp/verify');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode === 200) {
echo "OTP 驗證成功:" . $result['message'] . "\n";
} else {
echo "OTP 驗證失敗:" . $result['message'] . "\n";
}
}
try {
echo "正在發送 OTP...\n";
sendOtpExample();
echo "\n正在驗證 OTP...\n";
verifyOtpExample();
} catch (Exception $e) {
echo "發生錯誤:" . $e->getMessage() . "\n";
}
?>