capcom6 / android-sms-gateway
提供访问 Android SMS Gateway API 的权限
v2.0.0
2024-09-17 07:51 UTC
Requires
- php: >=7.4
- php-http/discovery: ^1.17
- psr/http-client-implementation: ^1.0
Requires (Dev)
- laminas/laminas-diactoros: ^2.17
- php-http/curl-client: ^2.2
- php-http/message: ^1.0
- php-http/mock-client: ^1.0
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-23 11:58:36 UTC
README
这是一个用于与 Android SMS Gateway API 交互的 PHP 客户端库。
要求
- PHP 7.4 或更高版本
- PSR-18 兼容的 HTTP 客户端实现
安装
您可以通过 composer 安装此包
composer require capcom6/android-sms-gateway
用法
以下是一个使用库发送消息的简单示例
<?php require 'vendor/autoload.php'; use AndroidSmsGateway\Client; use AndroidSmsGateway\Encryptor; use AndroidSmsGateway\Domain\Message; $login = 'your_login'; $password = 'your_password'; $client = new Client($login, $password); // or // $encryptor = new Encryptor('your_passphrase'); // $client = new Client($login, $password, Client::DEFAULT_URL, $httpClient, $encryptor); $message = new Message('Your message text here.', ['+1234567890']); try { $messageState = $client->Send($message); echo "Message sent with ID: " . $messageState->ID() . PHP_EOL; } catch (Exception $e) { echo "Error sending message: " . $e->getMessage() . PHP_EOL; die(1); } try { $messageState = $client->GetState($messageState->ID()); echo "Message state: " . $messageState->State() . PHP_EOL; } catch (Exception $e) { echo "Error getting message state: " . $e->getMessage() . PHP_EOL; die(1); }
客户端
Client
用于发送纯文本短信,但也可以通过提供 Encryptor
来发送加密消息。
方法
Client
类有以下方法
Send(Message $message)
: 发送新的 SMS 消息。GetState(string $id)
: 通过 ID 获取之前发送的消息的状态。
贡献
欢迎贡献!请提交一个 pull 请求或创建一个 issue,以添加或更改您想要的内容。
许可证
此库是开源软件,根据 Apache-2.0 许可证 许可。