Laravel串接簡訊王API

hosomikai
Jun 5, 2021

在我們開發web服務的時候有時候難免會需要使用到簡訊發送服務,
前陣子串接了簡訊王的API,也把他打包成了可以使用的套件供大家使用。
這篇用來說明如何快速串接簡訊王的API

安裝套件

$ composer require hosomikai/kotsms

安裝完套件之後我們必須設定 .env

KOTSMS_USERNAME="你的簡訊王帳號"
KOTSMS_PASSWORD="你的簡訊王密碼"

這樣我們的設定就完成了。

發送簡訊

use Hosomikai\Kotsms\Facade\Kotsms;...$smsNumber = '接收簡訊的手機號碼';
$content = '你要發送的簡訊內容';
$response = Kotsms::to($smsNumber)
->content($content)
->send();

這樣就可以發送簡訊了。
如果你想要確認api回傳的結果:

if ($response->isSuccess()) {    //成功} else {    $message = $this->getMessage(); //失敗訊息}

查詢剩餘點數

use Hosomikai\Kotsms\Facade\Kotsms;...$points = Kotsms::queryUserPoints();  //你的剩餘點數

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response