bahricanli / netgsm
使用Netgsm API发送短信
1.0.2
2023-04-04 15:07 UTC
Requires
- php: >=7
- bahricanli/netgsm-php: dev-master
- illuminate/notifications: 8.*
- illuminate/queue: 8.*
- illuminate/support: 8.*
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-18 18:03:18 UTC
README
此包使用Laravel 5.3轻松通过Netgsm发送通知。
内容
安装
您可以通过composer安装此包。
composer require bahricanli/Netgsm
接下来,将服务提供者添加到您的 config/app.php
文件中。
/* * Package Service Providers... */ NotificationChannels\Netgsm\NetgsmServiceProvider::class,
将Netgsm别名注册到您的应用程序中。此注册不是可选的,因为通道本身使用此别名。
'Netgsm' => NotificationChannels\Netgsm\Netgsm::class,
设置Netgsm服务
将您想要的客户端、用户名、密码、发起者(出站名称、发送者名称)和请求超时配置添加到您的 config/services.php
文件中。
... 'Netgsm' => [ 'client' => 'http', // or xml 'http' => [ 'endpoint' => 'https://service.jetsms.com.tr/SMS-Web/HttpSmsSend', ], 'xml' => [ 'endpoint' => 'www.biotekno.biz:8080/SMS-Web/xmlsms', ], 'username' => '', 'password' => '', 'originator' => "", // Sender name. 'timeout' => 60, ], ...
使用
现在您可以在通知内的via()方法中使用该通道。
use NotificationChannels\Netgsm\NetgsmChannel; use NotificationChannels\Netgsm\NetgsmMessage; class ResetPasswordWasRequested extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [NetgsmChannel::class]; } /** * Get the Netgsm representation of the notification. * * @param mixed $notifiable * @return string|\NotificationChannels\Netgsm\NetgsmMessage */ public function toNetgsm($notifiable) { return "Test notification"; // Or return new ShortMessage($notifiable->phone_number, 'Test notification'); } }
不要忘记在您的notifiables中放置Netgsm的专用方法。(例如User)
class User extends Authenticatable { use Notifiable; public function routeNotificationForNetgsm() { return "905123456789"; } }
可用方法
Netgsm也可以直接用来发送短信。
示例
Netgsm::sendShortMessage($to, $message); Netgsm::sendShortMessages([[ 'recipient' => $to, 'message' => $message, ], [ 'recipient' => $anotherTo, 'message' => $anotherMessage, ]]);
更多信息请参阅 Netgsm-php 文档。
可用事件
Netgsm通知通道提供了一些方便的事件,这些事件提供了关于短信消息所需的信息。
- 消息已发送 (
NotificationChannels\Netgsm\Events\MessageWasSent
) - 消息已发送 (
NotificationChannels\Netgsm\Events\MessageWasSent
) - 正在发送消息 (
NotificationChannels\Netgsm\Events\SendingMessage
) - 正在发送消息 (
NotificationChannels\Netgsm\Events\SendingMessages
)
示例
namespace App\Listeners; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use NotificationChannels\Netgsm\Events\MessageWasSent; class SentMessageHandler { /** * Handle the event. * * @param MessageWasSent $event * @return void */ public function handle(MessageWasSent $event) { $response = $event->response; $message = $event->message; } }
注意
如果客户端设置为 'http',$response->groupId() 将引发 BadMethodCallException。如果客户端设置为 'xml',$response->messageReportIdentifiers() 将引发 BadMethodCallException。
请谨慎更改客户端配置。
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件 bahri@bahri.info 联系我们,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件。