akibatech / laravel-ovh-sms
Laravel 5 的 OVH Sms Api 集成。
Requires
- php: >=5.5.9
- illuminate/support: >=5.1
- ovh/php-ovh-sms: 1.0
This package is not auto-updated.
Last update: 2024-09-17 09:09:22 UTC
README
这是 Laravel 5 的 php-ovh-sms 库的非官方集成。
- 原始 PHP OVH SMS 库
- 官方站点上的计划与定价(20个免费积分)(官网)
- 在 OVH Api 探索器 获取凭据
摘要
安装
使用 composer 安装此包
composer require akibatech/laravel-ovh-sms
更新 composer 后,将 ServiceProvider 添加到 config/app.php 中的 providers 数组
Akibatech\Ovhsms\ServiceProvider::class,
如果您想使用 Facade 快速发送消息,可以将此行添加到 config/app.php 中的 aliases 部分
'Ovhsms' => Akibatech\Ovhsms\Facade::class,
然后,您应该使用以下命令将 laravel-ovh-sms 发布到您的配置文件夹。
php artisan vendor:publish --provider="Akibatech\Ovhsms\ServiceProvider"
用法
在您的应用中的任何地方发送消息(使用 Facade)
Ovhsms::sendMessage('+33611223344', 'Hello!');
使用 DI 在控制器中发送消息
public function myControllerAction(Akibatech\Ovhsms\OvhSms $client) { $client->sendMessage('+33611223344', 'Hello!'); }
包 API 工作流程
此包为您提供了一个带有您配置的凭据和默认短信账户(如果有)的 Ovh\Sms\SmsApi 实例的访问权限。
它还提供了一些针对原始 Api 的辅助功能。
$client = app('ovhsms'); // Prepare a new SMS instance and return it. $sms = $client->newMessage('the phone number'); $sms->send('Hi!'); // Same as above but the SMS is marked as a marketing message. $sms = $client->newMarketingMessage($phone); // Alias of newMessage($phone, true); $sms->send('Hello!'); // Attach many receivers $sms = $client->newMessage(['phone1', 'phone2'], ...); $sms->send('Hi guys!'); // Send directly the message $client->sendMessage($phone, 'Hello!'); // Or $client->sendMarketingMessage($phone, 'Super price this sunday!');
原始 API 工作流程
如果您不想使用现成的辅助功能,可以遵循原始工作流程。以下是一个示例
// Retrieve OVH SMS instance $ovhsms = app('ovhsms'); // Or Ovhsms::getClient(); // Get available SMS accounts $accounts = $ovhsms->getAccounts(); // Set the account you will use $ovhsms->setAccount($accounts[0]); // Create a new message that will allow the recipient to answer (to FR receipients only) $sms = $ovh->createMessage(true); $sms->addReceiver("+33601020304"); $sms->setIsMarketing(false); // Plan to send it in the future $sms->setDeliveryDate(new DateTime("2018-02-25 18:40:00")); $sms->send("Hello world!");
与 Laravel 通知一起使用
此包可以用作 Laravel 通知(Laravel >= 5.3)的驱动程序。
示例通知
以下是一个简单的通知示例。
namespace App\Notifications; use Akibatech\Ovhsms\Notifications\OvhSmsChannel; use Akibatech\Ovhsms\Notifications\OvhSmsMessage; use Illuminate\Notifications\Notification; class ExampleNotification extends Notification { /** * Notification via OvhSmsChannel. */ public function via($notifiable) { return [OvhSmsChannel::class]; } /** * Your notification must implements "toOvh()" */ public function toOvh($notifiable) { return (new OvhSmsMessage('A new invoice was paid! Amount: $9.00')); } }
此外,您的可通知模型必须实现 routeNotificationForOvh()。
namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * Returns the user's phone number. */ public function routeNotificationForOvh() { return $this->phone; // Ex: +33611223344 } }
太好了,您现在可以使用新的 Laravel 通知系统了。
获取凭据
您可以从 OVH 的 官方 API 探索器站点 获取您的凭据。
一旦您手头有了凭据,您需要将它们放入 config/laravel-ovh-sms.php。
为了方便,您可以将它们放入您的 .env 文件中。
配置键是
- OVHSMS_APP_KEY => 您的应用程序密钥
- OVHSMS_APP_SECRET => 您的应用程序密钥
- OVHSMS_CONSUMER_KEY => 您的消费者密钥
- OVHSMS_ENDPOINT => 您的端点(默认为 ovh-eu)
可选键
- OVHSMS_ACCOUNT => 您的短信账户 ID(格式如 "sms-LLXXXXX-X")
- OVHSMS_USER_LOGIN => 您的 API 用户 ID
- OVHSMS_SENDER => 电话号码或字母数字发件人标识
支持
与 ovh/php-ovh-sms 相关的问题应发布在其自己的 仓库 上。
对于此 Laravel 包,您可以在问题部分自由发布您的问题。
贡献者
许可证
MIT