pyaesone17/sms-poh

SmsPoh Sdk for laravel

1.1 2018-01-13 04:55 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:49:04 UTC


README

https://smspoh.com/

这是我创建的个人库,以便开发人员更容易使用。这不是smspoh的官方SDK。创建此包的主要目的是我讨厌curl、guzzle等,所以我做了抽象。现在我可以轻松地通过调用以下方式来使用它。就是这样。

send_smspoh(
    ['+959790646062','+95943160544'],
    'Nice to meet you'
);

安装

通过Composer

$ composer require pyaesone17/sms-poh:^1.1

设置

首先发布配置文件。

$ php artisan vendor:publish

在sms-poh.php配置文件中配置token。

'token' => env('SMS_POH_TOKEN', 'Your_token_from_the_dashboard'),

SDK使用

用于获取消息。

  1. 使用外观
$results = SmsPohFacade::fetch(1);

2.使用容器

$sms = app()->make(pyaesone17\SmsPoh\SmsPoh::class);
$results = $sms->fetch(1);

3.使用函数

$resutls = fetch_smspoh(1);

用于发送消息。

  1. 使用外观
$results = SmsPohFacade::send(
    ['+959790646062','+95943160544'],
    'Nice to meet you'
);

$results = SmsPohFacade::send(
    '+959790646062',
    'Nice to meet you'
);

2.使用容器

$sms = app()->make(pyaesone17\SmsPoh\SmsPoh::class);
$results = $sms->send(
    ['+959790646062','+95943160544'],
    'Nice to meet you'
);

3.使用函数

$results = send_smspoh(
    ['+959790646062','+95943160544'],
    'Nice to meet you'
);

如果您想以测试目的发送消息,可以将true作为第三个参数传递。

通知通道使用

此包还包括用于与Laravel通知功能交互的自定义通知通道。以下是使用方法。

class SendSmsPohNotification extends Notification
{
    use Queueable;

    public $message;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [pyaesone17\SmsPoh\SmsPohChannel::class];
    }

    /**
     * Get the sms representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toMMSms($notifiable)
    {
        return [
            'message' => $this->message,
            'to' => '+959790646062',
            'test' => 1,
            'callback' => function (...$result)
            {
                // After sms is being sent or failed
                // The callback will fire, here you can
                // do whatever you want with the result.
                // If you don't want, just pass as null
                dd($result);
            }
        ];
    }

并像这样通知

$user = App\User::first();
$user->notify(new App\Notifications\SendSmsPohNotification("Hello world"));

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。