台灣簡訊 twsms api 客戶端

v1.0.7 2022-12-06 10:05 UTC

This package is auto-updated.

Last update: 2024-09-18 10:58:11 UTC


README

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License Monthly Downloads Daily Downloads Scrutinizer Code Quality Code Coverage

此包裝使得使用 Laravel 5.3+ 通過 [twsms]發送通知變得更加容易。

內容

安裝

您可以使用 composer 安裝此包裝

composer require taiwan-sms/twsms illuminate/notifications php-http/guzzle6-adapter

然後您必須安裝服務提供者

// config/app.php
'providers' => [
    ...
    TaiwanSms\TwSMS\TwSMSServiceProvider::class,
],

設置 TwSMS 服務

將您的 TwSMS 登錄名、秘密鍵(哈希密碼)和默認發送者名稱(或電話號碼)添加到您的 config/services.php

// config/services.php
...
'twsms' => [
    'username' => env('SERVICES_TWSMS_USERNAME'),
    'password' => env('SERVICES_TWSMS_PASSWORD'),
],
...

使用方法

您可以在通知內部的 via() 方法中使用該通道

use TaiwanSms\TwSMS\TwSMSMessage;
use TaiwanSms\TwSMS\TwSMSChannel;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [TwSMSChannel::class];
    }

    public function toTwSMS($notifiable)
    {
        return TwSMSMessage::create("Task #{$notifiable->id} is complete!");
    }
}

在您的可通知模型中,請確保包含 routeNotificationForTwSMS() 方法,该方法返回電話號碼。

public function routeNotificationForTwSMS()
{
    return $this->phone;
}

可用的方法

content():設置通知消息的內容。

sendTime():設置通知消息的發送時間。

變更記錄

請參考 變更記錄 以了解最近有哪些變化。

測試

$ composer test

安全性

如果您發現任何安全相關問題,請發送電子郵件至 recca0120@gmail.com,而不是使用問題追蹤器。

貢獻

請參考 貢獻指南 以获取详细信息。

致謝

版權

MIT 协議(MIT)。請參考 版權文件 以获取更多信息。

僅限 API

composer require taiwan-sms/twsms php-http/guzzle6-adapter

使用方法

require __DIR__.'/vendor/autoload.php';

use TaiwanSms\TwSMS\Client;

$userId = 'xxx';
$password = 'xxx';

$client = new Client($userId, $password);

var_dump($client->credit()); // 取得額度
var_dump($client->send([
    'to' => '09xxxxxxxx',
    'text' => 'test message',
]));
/*
return [
    'code' => '00000',
    'text' => 'Success',
    'msgid' => '265078525',
];
*/