|
1 | | -# 📱 SMS Gateway for Android™ PHP API Client |
| 1 | +# 📱 SMSGate PHP Client |
2 | 2 |
|
3 | | -[](https://opensource.org/licenses/Apache-2.0) |
4 | | -[](https://packagist.org/packages/capcom6/android-sms-gateway) |
5 | | -[](https://packagist.org/packages/capcom6/android-sms-gateway) |
6 | | -[](https://packagist.org/packages/capcom6/android-sms-gateway) |
| 3 | +[![Contributors][contributors-shield]][contributors-url] |
| 4 | +[![Forks][forks-shield]][forks-url] |
| 5 | +[![Stars][stars-shield]][stars-url] |
| 6 | +[![Issues][issues-shield]][issues-url] |
| 7 | +[![License][license-shield]][license-url] |
| 8 | +[![Packagist Version][version-shield]][version-url] |
7 | 9 |
|
8 | | -A modern PHP client for seamless integration with the [SMSGate](https://sms-gate.app) API. Send SMS messages, manage devices, and configure webhooks through your PHP applications with this intuitive library. |
| 10 | +A modern PHP client for the [SMSGate](https://sms-gate.app) API: send SMS messages and manage devices, webhooks, settings, and JWT tokens through your Android devices. PSR-18/PSR-17 compatible with any HTTP client via [php-http/discovery](https://github.com/php-http/discovery). See the [client libraries overview](https://docs.sms-gate.app/integration/client-libraries/) for the full ecosystem. |
9 | 11 |
|
10 | | -## 🔖 Table of Contents |
| 12 | +## 📖 About |
11 | 13 |
|
12 | | -- [📱 SMS Gateway for Android™ PHP API Client](#-sms-gateway-for-android-php-api-client) |
13 | | - - [🔖 Table of Contents](#-table-of-contents) |
14 | | - - [✨ Features](#-features) |
15 | | - - [⚙️ Prerequisites](#️-prerequisites) |
| 14 | +`capcom6/android-sms-gateway` is a type-safe PHP library for the SMSGate 3rd-party API. It covers messages (send, state, listing, cancellation), inbox refresh with attachment download, devices, webhooks, settings, logs, health checks, and the JWT token lifecycle, with a fluent `MessageBuilder` for message construction and an optional `Encryptor` for end-to-end encryption. Works with any PSR-18 HTTP client (Guzzle, curl, or others) and PHP 7.4+. |
| 15 | + |
| 16 | +## 📚 Table of Contents |
| 17 | + |
| 18 | +- [📱 SMSGate PHP Client](#-smsgate-php-client) |
| 19 | + - [📖 About](#-about) |
| 20 | + - [📚 Table of Contents](#-table-of-contents) |
| 21 | + - [⭐ Features](#-features) |
16 | 22 | - [📦 Installation](#-installation) |
17 | | - - [🚀 Quickstart](#-quickstart) |
18 | | - - [Sending an SMS](#sending-an-sms) |
19 | | - - [Managing Devices](#managing-devices) |
20 | | - - [🔐 Authentication](#-authentication) |
| 23 | + - [🔑 Authentication](#-authentication) |
21 | 24 | - [Basic Authentication](#basic-authentication) |
22 | 25 | - [JWT Authentication](#jwt-authentication) |
23 | | - - [Generating a JWT Token](#generating-a-jwt-token) |
24 | | - - [Using a JWT Token](#using-a-jwt-token) |
25 | | - - [Revoking a JWT Token](#revoking-a-jwt-token) |
26 | | - - [📚 Full API Reference](#-full-api-reference) |
27 | | - - [Client Initialization](#client-initialization) |
28 | | - - [Basic Authentication](#basic-authentication-1) |
29 | | - - [Core Methods](#core-methods) |
30 | | - - [Builder Methods](#builder-methods) |
31 | | - - [🔒 Security Notes](#-security-notes) |
32 | | - - [Best Practices](#best-practices) |
33 | | - - [Encryption Support](#encryption-support) |
34 | | - - [👥 Contributing](#-contributing) |
35 | | - - [Development Setup](#development-setup) |
| 26 | + - [🚀 Quickstart](#-quickstart) |
| 27 | + - [💻 Usage](#-usage) |
| 28 | + - [📖 API Reference](#-api-reference) |
| 29 | + - [🤝 Contributing](#-contributing) |
36 | 30 | - [📄 License](#-license) |
37 | 31 |
|
38 | | -## ✨ Features |
| 32 | +## ⭐ Features |
39 | 33 |
|
40 | | -- **Builder Pattern**: Fluent interface for message and settings configuration |
41 | | -- **PSR Standards**: Compatible with any PSR-18 HTTP client |
42 | | -- **Comprehensive API**: Access to all SMS Gateway endpoints |
43 | | -- **Error Handling**: Structured exception management |
44 | | -- **Type Safety**: Strict typing throughout the codebase |
45 | | -- **Encryption Support**: End-to-end message encryption |
46 | | -- **Dual Authentication**: Support for both Basic and JWT authentication |
47 | | -- **Token Management**: Generate, use, and revoke JWT tokens with configurable scopes and TTL |
48 | | - |
49 | | -## ⚙️ Prerequisites |
50 | | - |
51 | | -- PHP 7.4+ |
52 | | -- [Composer](https://getcomposer.org/) |
53 | | -- PSR-18 compatible HTTP client (e.g., [Guzzle](https://github.com/guzzle/guzzle)) |
54 | | -- SMS Gateway for Android account |
| 34 | +- Fluent `MessageBuilder` for messages and `SettingsBuilder` for settings |
| 35 | +- PSR-18 HTTP client and PSR-17 factories, auto-discovered |
| 36 | +- Basic and JWT authentication with token generation and revocation |
| 37 | +- Webhooks, devices, settings, logs, and health checks |
| 38 | +- Inbox refresh with webhook delivery and MMS attachment download |
| 39 | +- Optional end-to-end encryption via `Encryptor` |
| 40 | +- Structured `HttpException` error handling |
55 | 41 |
|
56 | 42 | ## 📦 Installation |
57 | 43 |
|
58 | 44 | ```bash |
59 | 45 | composer require capcom6/android-sms-gateway |
60 | 46 | ``` |
61 | 47 |
|
62 | | -## 🚀 Quickstart |
| 48 | +Requires PHP 7.4+ and a PSR-18 HTTP client implementation (e.g. Guzzle, `php-http/curl-client`). |
63 | 49 |
|
64 | | -### Sending an SMS |
65 | | -```php |
66 | | -<?php |
67 | | - |
68 | | -require 'vendor/autoload.php'; |
| 50 | +## 🔑 Authentication |
69 | 51 |
|
70 | | -use AndroidSmsGateway\Client; |
71 | | -use AndroidSmsGateway\Domain\MessageBuilder; |
72 | | - |
73 | | -// Initialize client with credentials |
74 | | -$client = new Client('your_login', 'your_password'); |
75 | | - |
76 | | -// Build message with fluent interface |
77 | | -$message = (new MessageBuilder('Your message text here.', ['+1234567890'])) |
78 | | - ->setTtl(3600) // Message time-to-live in seconds |
79 | | - ->setSimNumber(1) // Use SIM slot 1 |
80 | | - ->setWithDeliveryReport(true) // Request delivery report |
81 | | - ->setPriority(100) // Higher priority message |
82 | | - ->build(); |
83 | | - |
84 | | -// Send message |
85 | | -try { |
86 | | - $messageState = $client->SendMessage($message); |
87 | | - echo "✅ Message sent! ID: " . $messageState->ID() . PHP_EOL; |
88 | | - |
89 | | - // Check status after delay |
90 | | - sleep(5); |
91 | | - $updatedState = $client->GetMessageState($messageState->ID()); |
92 | | - echo "📊 Message status: " . $updatedState->State() . PHP_EOL; |
93 | | -} catch (\Exception $e) { |
94 | | - echo "❌ Error: " . $e->getMessage() . PHP_EOL; |
95 | | - exit(1); |
96 | | -} |
97 | | -``` |
98 | | - |
99 | | -### Managing Devices |
100 | | - |
101 | | -```php |
102 | | -// List registered devices |
103 | | -$devices = $client->ListDevices(); |
104 | | -echo "📱 Registered devices: " . count($devices) . PHP_EOL; |
105 | | - |
106 | | -// Remove a device |
107 | | -try { |
108 | | - $client->RemoveDevice('device-id-123'); |
109 | | - echo "🗑️ Device removed successfully" . PHP_EOL; |
110 | | -} catch (\Exception $e) { |
111 | | - echo "❌ Device removal failed: " . $e->getMessage() . PHP_EOL; |
112 | | -} |
113 | | -``` |
114 | | - |
115 | | -## 🔐 Authentication |
116 | | - |
117 | | -The SMSGate client supports two authentication methods: Basic Authentication and JWT (JSON Web Token) authentication. Each method has its own use cases and benefits. |
| 52 | +Two methods are supported: Basic authentication with account credentials, and JWT bearer tokens with scoped permissions. JWT is recommended for production. |
118 | 53 |
|
119 | 54 | ### Basic Authentication |
120 | 55 |
|
121 | 56 | ```php |
122 | | -// Initialize client with Basic authentication |
| 57 | +// Basic authentication with account credentials |
123 | 58 | $client = new Client('your_login', 'your_password'); |
124 | 59 | ``` |
125 | 60 |
|
126 | 61 | ### JWT Authentication |
127 | 62 |
|
128 | | -JWT authentication uses bearer tokens for authentication. |
129 | | - |
130 | | -#### Generating a JWT Token |
131 | | - |
132 | 63 | ```php |
133 | | -use AndroidSmsGateway\Client; |
134 | 64 | use AndroidSmsGateway\Domain\TokenRequest; |
135 | 65 |
|
136 | | -// First, create a client with Basic authentication to generate a token |
137 | 66 | $basicClient = new Client('your_login', 'your_password'); |
138 | 67 |
|
139 | | -// Create a token request with specific scopes and TTL |
140 | | -$tokenRequest = new TokenRequest( |
141 | | - ['messages:send', 'messages:read'], // Scopes for permissions |
142 | | - 3600 // Token TTL in seconds (optional) |
| 68 | +$token = $basicClient->GenerateToken( |
| 69 | + new TokenRequest(['messages:send', 'messages:read'], 3600) |
143 | 70 | ); |
144 | 71 |
|
145 | | -// Generate the token |
146 | | -$tokenResponse = $basicClient->GenerateToken($tokenRequest); |
147 | | -$jwtToken = $tokenResponse->AccessToken(); |
148 | | - |
149 | | -echo "Token generated! Expires at: " . $tokenResponse->ExpiresAt() . PHP_EOL; |
| 72 | +$jwtClient = new Client(null, $token->AccessToken()); |
150 | 73 | ``` |
151 | 74 |
|
152 | | -#### Using a JWT Token |
153 | | - |
154 | | -```php |
155 | | -// Initialize client with JWT authentication |
156 | | -$jwtClient = new Client(null, $jwtToken); |
157 | | - |
158 | | -// Now use the client as usual |
159 | | -$message = (new MessageBuilder('Your message text here.', ['+1234567890']))->build(); |
160 | | -$messageState = $jwtClient->SendMessage($message); |
161 | | -``` |
162 | | - |
163 | | -#### Revoking a JWT Token |
| 75 | +## 🚀 Quickstart |
164 | 76 |
|
165 | 77 | ```php |
166 | | -// Revoke a token using its ID (jti) |
167 | | -$basicClient->RevokeToken($tokenResponse->ID()); |
168 | | -echo "Token revoked successfully!" . PHP_EOL; |
169 | | -``` |
170 | | - |
171 | | -## 📚 Full API Reference |
172 | | - |
173 | | -### Client Initialization |
| 78 | +<?php |
174 | 79 |
|
175 | | -The client supports two authentication methods: Basic Authentication and JWT Bearer Tokens. |
| 80 | +require 'vendor/autoload.php'; |
176 | 81 |
|
177 | | -#### Basic Authentication |
178 | | -```php |
179 | | -$clientBasic = new Client( |
180 | | - string $login, |
181 | | - string $password, |
182 | | - string $serverUrl = 'https://api.sms-gate.app/3rdparty/v1', |
183 | | - ?\Psr\Http\Client\ClientInterface $httpClient = null, |
184 | | - ?\AndroidSmsGateway\Encryptor $encryptor = null |
185 | | -); |
| 82 | +use AndroidSmsGateway\Client; |
| 83 | +use AndroidSmsGateway\Domain\MessageBuilder; |
186 | 84 |
|
187 | | -$clientJWT = new Client( |
188 | | - null, // Set login to null for JWT |
189 | | - string $jwtToken, // JWT token as the second parameter |
190 | | - string $serverUrl = 'https://api.sms-gate.app/3rdparty/v1', |
191 | | - ?\Psr\Http\Client\ClientInterface $httpClient = null, |
192 | | - ?\AndroidSmsGateway\Encryptor $encryptor = null |
193 | | -); |
194 | | -``` |
| 85 | +$client = new Client('your_login', 'your_password'); |
195 | 86 |
|
196 | | -### Core Methods |
197 | | - |
198 | | -| Category | Method | Description | |
199 | | -| ------------------ | -------------------------------------------- | --------------------------------- | |
200 | | -| **Messages** | `SendMessage(Message $message)` | Send SMS message | |
201 | | -| | `GetMessageState(string $id)` | Get message status by ID | |
202 | | -| | `RefreshInbox(InboxRefreshRequest $request)` | Refresh inbox, deliver webhooks | |
203 | | -| **Devices** | `ListDevices()` | List registered devices | |
204 | | -| | `RemoveDevice(string $id)` | Remove device by ID | |
205 | | -| **System** | `HealthCheck()` | Check API health status | |
206 | | -| | `GetLogs(?string $from, ?string $to)` | Retrieve system logs | |
207 | | -| **Settings** | `GetSettings()` | Get account settings | |
208 | | -| | `PatchSettings(Settings $settings)` | Partially update account settings | |
209 | | -| | `ReplaceSettings(Settings $settings)` | Replace account settings | |
210 | | -| **Webhooks** | `ListWebhooks()` | List registered webhooks | |
211 | | -| | `RegisterWebhook(Webhook $webhook)` | Register new webhook | |
212 | | -| | `DeleteWebhook(string $id)` | Delete webhook by ID | |
213 | | -| **Authentication** | `GenerateToken(TokenRequest $request)` | Generate a new JWT token | |
214 | | -| | `RevokeToken(string $jti)` | Revoke a JWT token by ID | |
215 | | - |
216 | | -### Builder Methods |
217 | | -```php |
218 | | -// Message Builder |
219 | | -$message = (new MessageBuilder(string $text, array $recipients)) |
220 | | - ->setTtl(int $seconds) |
221 | | - ->setSimNumber(int $simSlot) |
222 | | - ->setWithDeliveryReport(bool $enable) |
223 | | - ->setPriority(int $value) |
| 87 | +$message = (new MessageBuilder('Hello from PHP', ['+15550100'])) |
| 88 | + ->setWithDeliveryReport(true) |
224 | 89 | ->build(); |
225 | | -``` |
226 | | - |
227 | | -## 🔒 Security Notes |
228 | | - |
229 | | -### Best Practices |
230 | 90 |
|
231 | | -1. **Never store credentials in code** - Use environment variables: |
232 | | - ```php |
233 | | - $login = getenv('SMS_GATEWAY_LOGIN'); |
234 | | - $password = getenv('SMS_GATEWAY_PASSWORD'); |
235 | | - ``` |
236 | | -2. **Use HTTPS** - Ensure all API traffic is encrypted |
237 | | -3. **Validate inputs** - Sanitize phone numbers and message content |
238 | | -4. **Rotate credentials** - Regularly update your API credentials |
| 91 | +$state = $client->SendMessage($message); |
| 92 | +echo 'Message ID: ' . $state->ID() . PHP_EOL; |
| 93 | +``` |
239 | 94 |
|
240 | | -### Encryption Support |
| 95 | +## 💻 Usage |
241 | 96 |
|
242 | | -```php |
243 | | -use AndroidSmsGateway\Encryptor; |
| 97 | +Beyond sending, the client covers message listing and cancellation, inbox listing and refresh, device management, health checks, logs, settings (get, patch, replace), webhooks, and token lifecycle. See [src/Client.php](https://github.com/android-sms-gateway/client-php/blob/master/src/Client.php) for the complete method list with signatures and [src/Domain](https://github.com/android-sms-gateway/client-php/tree/master/src/Domain) for the domain models. |
244 | 98 |
|
245 | | -// Initialize client with encryption |
246 | | -$encryptor = new Encryptor('your-secret-passphrase'); |
247 | | -$client = new Client($login, $password, Client::DEFAULT_URL, null, $encryptor); |
248 | | -``` |
| 99 | +## 📖 API Reference |
249 | 100 |
|
250 | | -## 👥 Contributing |
| 101 | +- [Official API Reference](https://docs.sms-gate.app/integration/api/) - endpoints, payloads, and error codes |
| 102 | +- [Authentication Guide](https://docs.sms-gate.app/integration/authentication/) - scopes and token management |
| 103 | +- [Client libraries overview](https://docs.sms-gate.app/integration/client-libraries/) |
| 104 | +- [Client source](https://github.com/android-sms-gateway/client-php/blob/master/src/Client.php) - full method reference and examples |
251 | 105 |
|
252 | | -We welcome contributions! Please follow these steps: |
| 106 | +## 🤝 Contributing |
253 | 107 |
|
254 | | -1. Fork the repository |
255 | | -2. Create your feature branch (`git checkout -b feature/AmazingFeature`) |
256 | | -3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) |
257 | | -4. Push to the branch (`git push origin feature/AmazingFeature`) |
258 | | -5. Open a Pull Request |
259 | | - |
260 | | -### Development Setup |
261 | | -```bash |
262 | | -git clone https://github.com/android-sms-gateway/client-php.git |
263 | | -cd client-php |
264 | | -composer install |
265 | | -``` |
| 108 | +Contributions are welcome. Open an issue to discuss major changes before submitting a pull request; PRs target the `master` branch. |
266 | 109 |
|
267 | 110 | ## 📄 License |
268 | | -This library is open-sourced software licensed under the [Apache-2.0 license](LICENSE). |
269 | | - |
270 | | ---- |
271 | 111 |
|
272 | | -**Note**: Android is a trademark of Google LLC. This project is not affiliated with or endorsed by Google. |
| 112 | +Distributed under the Apache License 2.0. See [LICENSE](https://github.com/android-sms-gateway/client-php/blob/master/LICENSE). |
| 113 | + |
| 114 | +<!-- Badge references: Shields.io style=for-the-badge is mandatory --> |
| 115 | +[contributors-shield]: https://img.shields.io/github/contributors/android-sms-gateway/client-php?style=for-the-badge |
| 116 | +[contributors-url]: https://github.com/android-sms-gateway/client-php/graphs/contributors |
| 117 | +[forks-shield]: https://img.shields.io/github/forks/android-sms-gateway/client-php?style=for-the-badge |
| 118 | +[forks-url]: https://github.com/android-sms-gateway/client-php/network/members |
| 119 | +[stars-shield]: https://img.shields.io/github/stars/android-sms-gateway/client-php?style=for-the-badge |
| 120 | +[stars-url]: https://github.com/android-sms-gateway/client-php/stargazers |
| 121 | +[issues-shield]: https://img.shields.io/github/issues/android-sms-gateway/client-php?style=for-the-badge |
| 122 | +[issues-url]: https://github.com/android-sms-gateway/client-php/issues |
| 123 | +[license-shield]: https://img.shields.io/github/license/android-sms-gateway/client-php?style=for-the-badge |
| 124 | +[license-url]: https://github.com/android-sms-gateway/client-php/blob/master/LICENSE |
| 125 | +[version-shield]: https://img.shields.io/packagist/v/capcom6/android-sms-gateway?style=for-the-badge |
| 126 | +[version-url]: https://packagist.org/packages/capcom6/android-sms-gateway |
0 commit comments