Socket
Socket
Sign inDemoInstall

thaibulksms-api

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    thaibulksms-api

วิธีส่ง SMS ง่ายๆด้วย Thaibulksms API ทั้งแบบข้อความและ OTP


Version published
Weekly downloads
454
increased by37.58%
Maintainers
1
Install size
414 kB
Created
Weekly downloads
 

Readme

Source

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)

//ตัวอย่างข้อความที่ได้รับ
/* 
    TBS Code: 093892. Valid for 5 minutes.
*/

ตัวอย่างโค้ด

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')

// Response success
/*
    {
        data: {
            status : "string",
            token  : "string"
        }
    }
*/

// Response fail
/*
    {
        code: 400,
        statusText: 'Bad Request',
        message: {
            detail: {
                ...
            },
            message: 'Invalid Paramete.'
        }
        
    }
*/

Verfiy OTP คือ การนำเอารหัส OTP ที่ได้จาก SMS มาตรวจสอบว่ารหัสถูกต้องหรือไม่

//ทำการเรียกฟังนี้ ก็สามารถส่งรหัสได้
const response = await otp.verify(token, code_OTP)

//  token     ได้จากตอนที่ตอนขอ request otp
//  code_OTP  ได้จากข้อความ SMS

ตัวอย่างโค้ด

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)

// Response success
/*
    {
        "data": {
            "status": "success",
            "message": "Code is correct."
        }
    }
*/


// Response fail
/*
    {
        code: 400,
        statusText: 'Bad Request',
        message: { detail: [], message: 'Token is expire.' }
    }
*/

Options

ValueTypeRequiredNotes
apiKeyStringYesKey of application.
apiSecretStringYesSecret of application.

Note:

  • คุณต้องเป็นสมาชิกของ ThaibulkSMS ก่อน จึงจะส่ง OTP ได้ สมาชิก ThaibulkSMS
  • สร้าง Key กับ Secret ได้ที่ ThaibulkSMS OTP Console
  • ขั้นการสร้าง Key กับ Secret เพื่อนําไปใช้กับ API สําหรับส่ง SMS OTP ศึกษาได้จากลิงค์นี้ เรียนรู้เพิ่มเติม

Keywords

FAQs

Last updated on 09 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc