digitalcz / gosms
Go SMS PHP 库 - 通过 PSR-18 HTTP 客户端在 PHP 中与 https://www.gosms.cz/api/ 通信
v2.0.1
2024-05-20 11:01 UTC
Requires
- php: ^8.0
- ext-json: *
- php-http/discovery: ^1.13
- php-http/multipart-stream-builder: ^1.1
- psr/http-client: ^1.0
- psr/http-message: ^1.0.1 || ^2.0
- psr/simple-cache: ^1.0 || ^3.0
Requires (Dev)
- digitalcz/coding-standard: ^0.2.0
- nyholm/nsa: ^1.2.1
- nyholm/psr7: ^1.3
- php-http/httplug: ^2.1
- php-http/mock-client: ^1.3
- phpstan/extension-installer: ^1.2.0
- phpstan/phpstan: ^1.11
- phpstan/phpstan-phpunit: ^1.4
- phpstan/phpstan-strict-rules: ^1.4.4
- phpunit/phpunit: ^9.5 || ^11.0
- symfony/cache: ^6.0 || ^7.0
- symfony/http-client: ^6.0 || ^7.0
- symfony/var-dumper: ^6.0 || ^7.0
Suggests
README
GoSms PHP 库 - 使用 PSR-18 HTTP 客户端、PSR-17 HTTP 工厂和 PSR-16 SimpleCache 在 PHP 中与 https://doc.gosms.cz 通信
安装
通过 Composer
$ composer require digitalcz/gosms
配置
PHP 中的示例配置
use DigitalCz\GoSms\Auth\ApiKeyCredentials; use DigitalCz\GoSms\GoSms; // Via constructor options $goSms = new GoSms([ 'client_id' => '...', 'client_secret' => '...' ]); // Or via methods $goSms = new GoSms(); $goSms->setCredentials(new ApiKeyCredentials('...', '...'));
可用的构造函数选项
client_id
- 字符串;ApiKey client_id 键client_secret
- 字符串;ApiKey client_secret 键credentials
- DigitalCz\GoSms\Auth\Credentials 实例client
- DigitalCz\GoSms\GoSmsClient 实例,包含您的自定义 PSR17/18 对象http_client
- 您自定义的 PSR18 客户端 Psr\Http\Client\ClientInterface 实例cache
- 用于缓存 Credentials Tokens 的 Psr\SimpleCache\CacheInterfaceapi_base
- 字符串;覆盖基本 API URL
可用的配置方法
use DigitalCz\GoSms\Auth\Token; use DigitalCz\GoSms\Auth\TokenCredentials; use DigitalCz\GoSms\GoSms; use DigitalCz\GoSms\GoSmsClient; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Psr16Cache; use Symfony\Component\HttpClient\Psr18Client; $goSms = new GoSms(); // To set your own PSR-18 HTTP Client, if not provided Psr18ClientDiscovery is used $goSms->setClient(new GoSmsClient(new Psr18Client())); // If you already have the auth-token, i can use TokenCredentials $goSms->setCredentials(new TokenCredentials(new Token('...', 123))); // Cache will be used to store auth-token, so it can be reused in later requests $goSms->setCache(new Psr16Cache(new FilesystemAdapter())); // Overwrite API base $goSms->setApiBase('https://example.com/api');
Symfony 中的示例配置
services: DigitalCz\GoSms\GoSms: $options: # minimal config client_id: '%gosms.client_id%' client_secret: '%gosms.client_secret%' # other options cache: '@psr16.cache' http_client: '@psr18.http_client'
使用方法
创建并发送消息
$goSms = new DigitalCz\GoSms\GoSms(['client_id' => '...', 'client_secret' => '...']); $organization = $goSms->organization()->detail(); echo "Detail organization " . var_dump($organization) . PHP_EOL; $messages = $goSms->messages(); $message = $messages->create( [ 'message' => 'Hello Hans, please call me back.', 'recipients' => '+420775300500', 'channel' => 6, ], ); echo "Created Message " . $message->link() . PHP_EOL; $message = $messages->get('example_message_id'); echo "Detail Message " . var_dump($message) . PHP_EOL; $messages->delete('example_message_id'); echo "Message was deleted " . PHP_EOL;
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
测试
$ composer csfix # fix codestyle $ composer checks # run all checks # or separately $ composer tests # run phpunit $ composer phpstan # run phpstan $ composer cs # run codesniffer
贡献
有关详细信息,请参阅 CONTRIBUTING
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件 devs@digital.cz 而不是使用问题跟踪器来报告。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件