ThaibulkSMS API
Installation
npm install thaibulksms-api
or
yarn add thaibulksms-api
วิธีเรียกใช้
const thaibulksmsApi = require('thaibulksms-api')
OTP
OTP หรือ One Time Password คือ รหัสผ่านที่ได้รับจากข้อความ(SMS) ในมือถือ เพื่อความปลอดภัยในการยืนตัวตนการเป็นเจ้าของ ในทำธุระกรรมทองอินเทอร์เน็ต ซึ่งรหัสผ่านจะมีอายุในการยืนยันตามที่ได้ตั้งค่าไว้
OTP API ของ ThaibulkSms จะมี 2 ส่วนให้เรียกใช้งาน ดังนี้ (ตามในคู่มือการใช้งาน OTP API)
Request OTP คือ การส่งคำขอสร้างรหัส OTP ซึ่งจะใช้แค่เพียงเบอร์โทรอย่างเดียว ก็สามารถสร้างรหัส OTP ได้ โดยรหัสจะส่งผ่านข้อความ SMS
const response = await otp.request(phoneNumber)
ตัวอย่างโค้ด
const thaibulksmsApi = require('thaibulksms-api')
const options = {
apiKey: 'App key',
apiSecret: 'App secret',
}
const otp = thaibulksmsApi.otp(options)
const requestOTP = async (phoneNumber) => {
try {
const response = await otp.request(phoneNumber)
console.log(response.data)
} catch (error) {
console.error(error)
}
}
requestOTP('06xxxxxxxx')
Verfiy OTP คือ การนำเอารหัส OTP ที่ได้จาก SMS มาตรวจสอบว่ารหัสถูกต้องหรือไม่
const response = await otp.verify(token, code_OTP)
ตัวอย่างโค้ด
const verifyOTP = async (token, code_OTP) => {
try {
const response = await otp.verify(token, code_OTP)
console.log(response.data)
} catch (error) {
console.error(error)
}
}
verifyOTP('a12ec2lo-wladkeoDWelso3044', 1234)
Options
Value | Type | Required | Notes |
---|
apiKey | String | Yes | Key of application. |
apiSecret | String | Yes | Secret of application. |
Note: