tomsgad/laravel-beem

将Laravel的强大功能和Beem无懈可击的API完美融合,带来魔法般的体验!

1.1.1 2023-12-06 05:41 UTC

This package is auto-updated.

Last update: 2024-09-08 12:58:58 UTC


README

轻松实现Laravel与Beem的集成

Latest Version on Packagist Github Test Action Status Github Code Style Action Status Total Downloads License

此包提供了一种简单、清晰的方式访问Beem API端点。以Laravel的方式发送短信通知

安装

您可以通过Composer安装此包

composer require tomsgad/laravel-beem

安装包后,您可以选择发布配置文件。

php artisan vendor:publish --tag="beem-config"

这是发布配置文件的内容

return [
    'sms' => [
        /*
        |--------------------------------------------------------------------------
        | Beem SMS API Key
        |--------------------------------------------------------------------------
        |
        | Here we set sms api key that will be used to send the sms. Get your
        | credentials from https://sms.beem.africa/#!/dashboard/profile/authentication
        |
        */
        'api_key' => env('BEEM_SMS_API_KEY', ''),

        /*
        |--------------------------------------------------------------------------
        | Beem SMS Secret Key
        |--------------------------------------------------------------------------
        |
        | Here we set sms secret key that will be used to send the sms. Get your
        | credentials from https://sms.beem.africa/#!/dashboard/profile/authentication
        |
        */
        'secret_key' => env('BEEM_SMS_SECRET_KEY', ''),

        /*
        |--------------------------------------------------------------------------
        | Beem SMS Sender Name
        |--------------------------------------------------------------------------
        |
        | Here we set a sender name that will be used to send the sms. Default
        | sender name is `INFO`. Please only use sender names that have been registered
        | or the sms will not be sent.
        |
        */

        'sender_name' => env('BEEM_SMS_SENDER_NAME', ''),
    ]
];

设置Beem服务

您需要从您的个人资料中获取API详细信息。以下是您可以遵循的步骤(由Beem描述)

  1. https://login.beem.africa上创建一个免费账户。
  2. 完成注册后,您将收到一封确认电子邮件。点击链接或将其粘贴到浏览器中以验证账户。
  3. 使用您的用户名和密码在https://login.beem.africa上登录。
  4. 您应该已经收到一些免费测试余额和一个默认的发件人ID“INFO”,应该处于激活状态。
  5. 访问“个人资料”选项卡并点击“认证信息”。
  6. 点击生成API密钥和密钥以获取这些信息。请注意,密钥只显示一次,因此请安全地存储。
  7. 使用此API密钥和密钥开始使用以下定义的API发送消息。

使用上面步骤中获取的凭证设置您的.env文件

BEEM_SMS_API_KEY=""
BEEM_SMS_SECRET_KEY=""
BEEM_SMS_SENDER_NAME=""

routeNotificationForBeem添加到您的可通知模型中,并定义如何获取电话号码。注意:该方法应返回一个数组或可计数的对象。我已经让它保持这种方式,以便您可以按照自己的方式实现。

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use  Notifiable;

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

用法

现在您可以在通知中的(via)方法中使用此通道。此示例将使用.env文件中的设置。

use Illuminate\Notifications\Notification;
use Tomsgad\Beem\SMS\BeemMessage;

class Demo extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['beem'];
    }

    public function toBeem($notifiable)
    {
        return (new BeemMessage())
            ->content('Message Goes Here');
    }
}

您还可以在不设置.env变量的情况下动态发送通知。如果您动态设置详细信息或您有一个多租户应用程序,这将很有用。

use Illuminate\Notifications\Notification;
use Tomsgad\Beem\SMS\BeemMessage;

class Demo extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['beem'];
    }

    public function toBeem($notifiable)
    {
        return (new BeemMessage())
            ->content('Message Goes Here')
            ->sender('senderNameGoesHere')
            ->secretKey('secretKeyGoesHere')
            ->apiKey('apiKeyGoesHere');
    }
}

测试

composer test

变更日志

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

贡献

有关详细信息,请参阅CONTRIBUTING

安全漏洞

如果您发现任何安全相关的问题,请通过电子邮件thomson@magurugroup.co.tz报告,而不是使用问题跟踪器。

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件