abdulmatinsanni / api-x
非官方的Laravel包,用于SmartSMSSolutions的APIx。该包帮助将短信发送到“请勿打扰”(DND)的电话号码。
1.2.0
2018-12-09 00:46 UTC
Requires
- php: ~5.6|~7.0
- guzzlehttp/guzzle: ~6.0
- illuminate/routing: ~5.1
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-09-25 00:31:32 UTC
README
非官方的Laravel包,用于SmartSMSSolutions的APIx。该包帮助将短信发送到“请勿打扰”(DND)的电话号码。
结构
以下是该包的文件结构。
\---src
| APIx.php
| APIxMessage.php
| APIxServiceProvider.php
|
+---Channels
| SmartSMSChannel.php
|
+---Commands
| \---Log
| ClearCommand.php
| DisplayCommand.php
|
+---config
| api-x.php
|
+---Controllers
| LogController.php
|
+---Exceptions
| CouldNotSendNotification.php
| InvalidConfiguration.php
|
+---Facades
| APIxFacade.php
|
\---resources
\---views
log.blade.php
安装
您可以通过Composer安装此包
$ composer require abdulmatinsanni/api-x
添加服务提供者(仅在Laravel 5.4或更低版本中需要)
// config/app.php 'providers' => [ ... AbdulmatinSanni\APIx\APIxServiceProvider::class, ], 'aliases' => [ 'APIx' => AbdulmatinSanni\APIx\Facades\APIxFacade::class, ],
设置您的API-x账户
将您的API-x API令牌(字符串)、日志消息(布尔值)、模拟短信(布尔值)和发送者姓名(可选|string)添加到您的.env(环境)文件中
SMARTSMSSOLUTIONS_API_TOKEN=apixtokenhere
SMARTSMSSOLUTIONS_LOG_MESSAGES=true
SMARTSMSSOLUTIONS_FAKE_SMS=true
SMARTSMSSOLUTIONS_SENDER_NAME=sendernamehere
使用方法
在控制器中
以下是在控制器中API-x使用的示例。
... use APIx; class SMSController extends Controller { public function send(Request $request) { $response = APIx::to($request->recipient) ->from($request->name) ->message($request->message) ->send(); return $response; } }
用于通知
在模型中设置
... class User extends Model { use Notifiable; public function routeNotificationForSmartSMS($notification) { return $this->phone_column; } }
在通知中设置
... use AbdulmatinSanni\APIx\APIxMessage; use AbdulmatinSanni\APIx\Channels\SmartSMSChannel; class DemoNotification extends Notification { use Queueable; ... public function via($notifiable) { return [SmartSMSChannel::class]; } ... public function toSmartSMS($notifiable) { return (new APIxMessage()) ->from($this->from) ->message($this->message); } }
在控制器中设置
... public class NotificationsController extends Controller { public function notify() { $user = User::firstOrFail(); $user->notify(new DemoNotification("SarahFound", "Hi, you are invited to our seminar!!!!!")); } }
可用的消息方法
to([])
:接受接收者电话号码的数组或字符串。from('')
:接受用作短信发送者的电话。message('')
:接受短信主体的字符串值。send()
:发送短信。如果省略了message(''),也可以接受代表短信主体的字符串。
命令行
显示所有日志条目
$ php artisan api-x:log
显示最后一条已记录的短信
$ php artisan api-x:log --latest
限制显示的日志条目数量
$ php artisan api-x:log --limit={no_of_messages}
清除所有日志条目
$ php artisan api-x:log clear
变更日志
请参阅CHANGELOG以获取最近更改的详细信息。
测试
$ composer test (NOT YET)
贡献
请参阅CONTRIBUTING和CODE_OF_CONDUCT以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过me@abdulmatinsanni.com而不是使用问题跟踪器发送电子邮件。
致谢
许可协议
MIT许可协议(MIT)。请参阅许可文件以获取更多信息。