recca0120/twsms

此包已被废弃,不再维护。作者建议使用 taiwan-sms/twsms 包。

台湾簡訊 twsms api client

v1.0.5 2020-05-14 16:33 UTC

This package is auto-updated.

Last update: 2021-12-08 00:04:19 UTC


README

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

此包使得使用 [twsms] 在 Laravel 5.3+ 发送通知变得简单。

内容

安装

您可以通过 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(): 设置通知消息的发送时间。

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

安全

如果您发现任何与安全相关的问题,请通过电子邮件 recca0120@gmail.com 而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

致谢

许可

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',
];
*/