vonage/vonage-laravel
Composer 安装命令:
composer require vonage/vonage-laravel
包简介
Service provider for Laravel for the Vonage PHP SDK
README 文档
README
Vonage Package for Laravel
Introduction
This is a Laravel Service Provider for integrating the Vonage PHP Client Library.
Requirements
This Package is for use with Laravel versions 9.x and upwards due to PHP Version restrictions. You will need to be running PHP8.0 and upwards - for older compatibility you will need to look at previous versions.
Installation
Using Composer, run the terminal command:
composer require vonage/vonage-laravel
Dealing with Guzzle Client issues
By default, this package uses vonage/client, which includes a Guzzle adapter for
accessing the API. Some other libraries supply their own Guzzle adapter, leading
to composer not being able to resolve a list of dependencies. You may get an
error when adding vonage/vonage-laravel to your application because of this.
The Vonage client allows you to override the HTTP adapter that is being used.
This takes a bit more configuration, but this package allows you to use vonage/client-core to supply
your own HTTP adapter.
To do this:
Run composer require vonage/client-core to install the Core SDK with Composer.
Install your own httplug-compatible adapter. For example, to use Symfony's HTTP Client:
composer require symfony/http-client php-http/message-factory php-http/httplug nyholm/psr7
composer require vonage/vonage-laravel to install this package
In your .env file, add the following configuration:
VONAGE_HTTP_CLIENT="Symfony\\Component\\HttpClient\\HttplugClient"
You can now pull the Vonage\Client object from the Laravel Service Container, or use the Facade provided by this package.
Configuration
You can use artisan vendor:publish to copy the distribution configuration file to your app's
config directory:
php artisan vendor:publish --provider="Vonage\Laravel\VonageServiceProvider"
Then update config/vonage.php with your credentials. Alternatively, you can update your .env file
with the following:
VONAGE_KEY=my_api_key VONAGE_SECRET=my_secret
Optionally, you could also set an application_id and private_key if required:
VONAGE_APPLICATION_ID=my_application_id VONAGE_PRIVATE_KEY=./private.key
Private keys can either be a path to a file, like above, or the string of the key itself:
VONAGE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n[...]\n-----END PRIVATE KEY-----\n"
VONAGE_PRIVATE_KEY="-----BEGIN PRIVATE KEY----- [...] -----END PRIVATE KEY----- "
Usage
To use the Vonage Client Library you can use the Facade, or request the instance from the service container:
$text = new \Vonage\SMS\Message\SMS($toNumber, $fromNumber, 'Test SMS using Laravel'); Vonage::sms()->send($text);
Or
$vonage = app('Vonage\Client'); $text = new \Vonage\SMS\Message\SMS($toNumber, $fromNumber, 'Test SMS using Laravel'); $vonage->sms()->send($text);
If you're using private key authentication, you can make a voice call:
$outboundCall = new \Vonage\Voice\OutboundCall( new \Vonage\Voice\Endpoint\Phone('14843331234'), new \Vonage\Voice\Endpoint\Phone('14843335555') ); $outboundCall ->setAnswerWebhook( new \Vonage\Voice\Webhook('https://example.com/answer') ) ->setEventWebhook( new \Vonage\Voice\Webhook('https://example.com/event') ) ; $response = Vonage::voice()->createOutboundCall($outboundCall);
For more information on using the Vonage Client library, see the official client library repository.
vonage/vonage-laravel 适用场景与选型建议
vonage/vonage-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.28M 次下载、GitHub Stars 达 39, 最近一次更新时间为 2022 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vonage/vonage-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vonage/vonage-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.28M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 39
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-27
