### Development Environment Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Example for setting up the SMSAPI client in a development environment, including loading environment variables and setting a debug logger. ```php load(); $client = new SmsapiHttpClient(); $client->setLogger(new DebugLogger()); $service = $client->smsapiComService($_ENV['SMSAPI_TOKEN']); ``` -------------------------------- ### Production Environment Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Example for setting up the SMSAPI client in a production environment, emphasizing the use of environment variables for API tokens, explicit disabling of test mode, and enabling logging. ```php test = false; // Default, but explicit for clarity // Enable logging and monitoring $client = new SmsapiHttpClient(); $client->setLogger(new ProductionLogger()); $service = $client->smsapiComService($apiToken); ``` -------------------------------- ### Logging Configuration with Monolog Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Enable logging by setting a PSR-3 compatible logger, using Monolog as an example. ```php pushHandler(new StreamHandler('/var/log/smsapi.log')); $client = new SmsapiHttpClient(); $client->setLogger($logger); $service = $client->smsapiComService('api-token'); ``` -------------------------------- ### Custom PSR-18 Client Setup with Guzzle Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Use any PSR-18 compliant HTTP client, with Guzzle as an example. ```php smsapiComService('your-api-token'); ``` -------------------------------- ### Optional Dependencies for Curl Adapter Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Install Guzzle HTTP helpers for the built-in Curl HTTP client adapter. ```bash composer require guzzlehttp/psr7:^1 ``` -------------------------------- ### Custom PSR-18 Client Setup with Symfony HttpClient Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Use any PSR-18 compliant HTTP client, with Symfony HttpClient as an example. ```php smsapiComService('your-api-token'); ``` -------------------------------- ### Curl Adapter Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Simple setup using PHP's built-in cURL extension. ```php smsapiComService('your-api-token'); ``` -------------------------------- ### Logging Configuration with Custom Logger Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Enable logging by setting a PSR-3 compatible logger, with a custom FileLogger as an example. ```php file = fopen($path, 'a'); } public function log($level, $message, array $context = []): void { $line = sprintf( "[%s] [%s] %s %s\n", date('Y-m-d H:i:s'), strtoupper($level), $message, json_encode($context) ); fwrite($this->file, $line); } public function emergency($message, array $context = []): void { $this->log(LogLevel::EMERGENCY, $message, $context); } // ... other log level methods } $client = new SmsapiHttpClient(); $client->setLogger(new FileLogger('/var/log/smsapi.log')); ``` -------------------------------- ### SMSAPI.PL Service Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Setup for the Poland-specific SMSAPI.PL service. ```php smsapiPlService('api-token'); // or with custom URI $service = $client->smsapiPlServiceWithUri('api-token', 'https://api.smsapi.pl'); ``` -------------------------------- ### Caching Responses Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Example of caching profile and pricing information using PSR-11 compatible cache. ```php service = $service; $this->cache = $cache; } public function getProfile() { $key = 'smsapi_profile'; if ($this->cache->has($key)) { return $this->cache->get($key); } $profile = $this->service->profileFeature()->findProfile(); $this->cache->set($key, $profile, 3600); // Cache 1 hour return $profile; } } ``` -------------------------------- ### Proxy Server Configuration with Guzzle Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Configures a Guzzle HTTP client to use a proxy server, with an example showing both basic proxy setup and proxy with authentication. ```php 'tcp://proxy.example.com:8080', // or with authentication 'proxy' => 'tcp://user:password@proxy.example.com:8080' ]); $client = new SmsapiHttpClient( $httpClient, new GuzzleHttp\Psr7\RequestFactory(), new GuzzleHttp\Psr7\StreamFactory() ); ``` -------------------------------- ### setLogger Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of setting a PSR-3 logger for request/response logging. ```php $logger = new YourPsr3Logger(); $client->setLogger($logger); ``` -------------------------------- ### smsapiPlService Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of creating a service instance for SMSAPI.PL API using the default URI. ```php $service = $client->smsapiPlService('your-api-token'); ``` -------------------------------- ### Testing Environment Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Demonstrates how to enable test mode for sending SMS messages to avoid charges, using the `test` flag. ```php test = true; // Enable test mode // API accepts but doesn't send or charge $result = $service->smsFeature()->sendSms($sms); ``` -------------------------------- ### Other Regional Services Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Setup for other regional services like SMSAPI.SE or SMSAPI.BG using the generic .COM service with a custom URI. ```php smsapiComServiceWithUri( 'api-token', 'https://api.smsapi.io/' // or other endpoint ); ``` -------------------------------- ### Curl-Based HTTP Client Constructor Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of instantiating the Curl-based SmsapiHttpClient. ```php smsapiComService('your-api-token'); ``` -------------------------------- ### smsapiComService Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of creating a service instance for SMSAPI.COM API using the default URI. ```php $service = $client->smsapiComService('your-api-token'); ``` -------------------------------- ### Get contact from group Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of retrieving contact details from a specific group using the SMSAPI PHP client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionGroupMemberGet = $smsApi->actionGroupMemberGet('Numer id kontaktu', 'Numer id grupy'); $response = $actionGroupMemberGet->execute(); echo $response->getFirstName().'
'; } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### SMSAPI.COM Service Setup Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Setup for the default international SMSAPI.COM service. ```php smsapiComService('api-token'); // or with custom URI $service = $client->smsapiComServiceWithUri('api-token', 'https://api.smsapi.com'); ``` -------------------------------- ### smsapiPlServiceWithUri Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of creating a service instance for SMSAPI.PL API using a custom URI. ```php $service = $client->smsapiPlServiceWithUri('your-api-token', 'https://custom-uri.pl'); ``` -------------------------------- ### Get group from contact Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of retrieving group information associated with a specific contact using the SMSAPI PHP client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionContactGroupGet = $smsApi->actionContactGroupGet('Numer id kontaktu', 'Numer id grupy'); $response = $actionContactGroupGet->execute(); echo $response->getDescription().'
'; } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### smsapiComServiceWithUri Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of creating a service instance for SMSAPI.COM API using a custom URI. ```php $service = $client->smsapiComServiceWithUri('your-api-token', 'https://api.smsapi.io/'); ``` -------------------------------- ### SmsapiHttpClient Constructor Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/01-client-initialization.md Example of how to instantiate the SmsapiHttpClient with PSR-18 compliant HTTP client and PSR-17 factories. ```php encoding = 'utf-8'; $sms->normalize = true; // Normalize to compatible characters // Or use noUnicode flag for GSM-only content $sms->noUnicode = true; ``` -------------------------------- ### Default Sender Name Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Shows how to set a default sender name for SMS messages, with an example of per-request override. ```php from = 'MyCompany'; $result = $service->smsFeature()->sendSms($sms); ``` -------------------------------- ### Profile Feature Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Get account profile information. ```php profileFeature()->findProfile(); echo "Name: " . $profile->name . "\n"; echo "Email: " . $profile->email . "\n"; echo "Points: " . $profile->points . "\n"; echo "Payment Type: " . $profile->paymentType . "\n"; echo "User Type: " . $profile->userType . "\n"; ?> ``` -------------------------------- ### Dependency Injection with Symfony Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Configuration for dependency injection using Symfony's services.yaml. ```yaml # services.yaml services: smsapi.http_client: class: Smsapi\Client\Curl\SmsapiHttpClient smsapi.service: class: Smsapi\Client\Service\SmsapiComService factory: ['@smsapi.http_client', 'smsapiComService'] arguments: - '%env(SMSAPI_TOKEN)%' ``` -------------------------------- ### createSendername() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Example of how to register a new sender name. ```php smsFeature()->sendernameFeature()->createSendername($sender); echo "Created sender: " . $result->sender . " (Status: " . $result->status . ")"; ``` -------------------------------- ### Get group Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples This code snippet demonstrates how to retrieve information about a specific group using its ID with the SMSAPI PHP Client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionGroupGet = $smsApi->actionGroupGet('Numer id grupy'); $response = $actionGroupGet->execute(); echo $response->getName().'
'; } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Send SMS Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example of sending an SMS message using the SMSAPI client. ```php smsFeature() ->sendSms($sms); ``` -------------------------------- ### Dependency Injection with Laravel Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Service provider for dependency injection in Laravel. ```php // app/Providers/SmsapiServiceProvider.php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Smsapi\Client\Curl\SmsapiHttpClient; use Smsapi\Client\Service\SmsapiComService; class SmsapiServiceProvider extends ServiceProvider { public function register() { $this->app->singleton(SmsapiComService::class, function () { $client = new SmsapiHttpClient(); return $client->smsapiComService(config('services.smsapi.token')); }); } } ``` -------------------------------- ### findSendernames() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Example of how to retrieve and display registered sender names. ```php smsFeature()->sendernameFeature()->findSendernames(); foreach ($sendernames as $name) { echo $name->sender . " - Status: " . $name->status . "\n"; } ``` -------------------------------- ### createSubuser() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Example of how to create a new subuser account with specific point allocations using the createSubuser() method. ```php setPoints(100.0, 50.0); // from_account, per_month $subuser->active = true; $created = $service->subusersFeature()->createSubuser($subuser); echo "Created subuser: " . $created->username . "\n"; echo "Points: " . $created->points->fromAccount . " / month\n"; ``` -------------------------------- ### Add subuser permissions to contact group Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of granting read, send, and write permissions to a subuser for a contact group. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionGroupPermissionAdd = $smsApi->actionGroupPermissionAdd('Numer id grupy', 'Nazwa podużytkownika') ->enableRead() ->enableSend() ->enableWrite(); $response = $actionGroupPermissionAdd->execute(); } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Create Group Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Example of how to create a new contact group using the `createGroup` method. ```php description = 'Premium tier customers'; $created = $service->contactsFeature()->groupsFeature()->createGroup($group); echo "Created group ID: " . $created->id; ``` -------------------------------- ### Create a Contact Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/INDEX.md Example of creating a new contact with a name and phone number. ```php $contact = CreateContactBag::withPhoneNumber('+48123456789'); $contact->setName('John', 'Doe'); $created = $service->contactsFeature()->createContact($contact); echo "Created: " . $created->id; ``` -------------------------------- ### Add contact to group Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of adding a contact to a specific group using the SMSAPI PHP client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionContactGroupAdd = $smsApi->actionContactGroupAdd('Numer id kontaktu', 'Numer id grupy'); $response = $actionContactGroupAdd->execute(); } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Using SMSAPI.PL Service Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example of how to instantiate a service client for the SMSAPI.PL API using an API token. ```php smsapiPlService($apiToken); ``` -------------------------------- ### Find contacts by group ids Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of finding contacts across multiple groups by their IDs using the SMSAPI PHP client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionContactList = $smsApi->actionContactList() ->setGroupIds(array('Numer id #1', 'Numer id #2', 'Numer id #N')); $response = $actionContactList->execute(); $contacts = $response->getCollection(); foreach ( $contacts as $contact ) { echo $contact->getId().'
'; } } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Timeout Configuration with Guzzle Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Sets timeout and connect_timeout parameters for a Guzzle HTTP client. ```php 30.0, // seconds 'connect_timeout' => 5.0 // seconds ]); ``` -------------------------------- ### Find Fields Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Example of how to retrieve all custom field definitions using the `findFields` method. ```php contactsFeature()->fieldsFeature()->findFields(); foreach ($fields as $field) { echo $field->name . " (" . $field->type . ")\n"; } ``` -------------------------------- ### Dependency Injection with PSR-11 Container Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Factory class for creating an SMSAPI service with a PSR-11 compatible container. ```php smsapiComService($container->get('config')['smsapi_token']); } } // Usage $service = SmsapiServiceFactory::createService($container); ``` -------------------------------- ### Create Contact Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Create a new contact. ```php setName('John', 'Doe'); $contact->email = 'john@example.com'; $created = $service->contactsFeature()->createContact($contact); echo "Created contact ID: " . $created->id; ``` -------------------------------- ### List all groups Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples This code snippet shows how to list all available groups using the SMSAPI PHP Client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionGroupList = $smsApi->actionGroupList(); $response = $actionGroupList->execute(); $groups = $response->getCollection(); foreach ( $groups as $group ) { echo $group->getName().'
'; } } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### createBlacklistedPhoneNumber() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Example of how to add a phone number to the blacklist using the createBlacklistedPhoneNumber() method. ```php blacklistFeature()->createBlacklistedPhoneNumber($blacklist); echo "Blacklisted: " . $result->phoneNumber . "\n"; echo "Created: " . $result->createdAt->format('Y-m-d H:i:s') . "\n"; ``` -------------------------------- ### Using SMSAPI.COM Service Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example of how to instantiate a service client for the SMSAPI.COM API using an API token. ```php smsapiComService($apiToken); ``` -------------------------------- ### Connection Pooling with Guzzle Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Configures connection pooling parameters for a Guzzle HTTP client to optimize performance. ```php 5, 'pool_max_parallel_requests' => 10 ]); ``` -------------------------------- ### findProfilePrices() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Example of how to retrieve SMS pricing by country and network using the findProfilePrices() method. ```php profileFeature()->findProfilePrices(); foreach ($prices as $price) { echo $price->type . " - "; echo $price->country->name . " (" . $price->country->mcc . ") - "; echo $price->network->name . " (" . $price->network->mnc . ") - "; echo $price->price->amount . " " . $price->price->currency . "\n"; } ``` -------------------------------- ### Edit subuser permissions in contact group Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of revoking read, send, and write permissions for a subuser from a contact group. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionGroupPermissionEdit = $smsApi->actionGroupPermissionEdit('Numer id grupy', 'Nazwa podużytkownika') ->disableRead() ->disableSend() ->disableWrite(); $response = $actionGroupPermissionEdit->execute(); } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Message Encoding Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Illustrates setting different character encodings for SMS messages, including UTF-8 (default), GSM, and Unicode. ```php encoding = 'utf-8'; // GSM 7-bit $sms->encoding = 'gsm'; // Unicode $sms->encoding = 'unicode'; ``` -------------------------------- ### Configure Logging Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/INDEX.md Example of configuring Monolog logger for the SMSAPI HTTP client. ```php use Monolog\Logger; use Monolog\Handlers\StreamHandler; $logger = new Logger('smsapi'); $logger->pushHandler(new StreamHandler('php://stdout')); $client = new SmsapiHttpClient(); $client->setLogger($logger); ``` -------------------------------- ### Find contacts by group id Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples Example of finding contacts within a specific group by its ID using the SMSAPI PHP client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionContactList = $smsApi->actionContactList() ->setGroupId('Numer id'); $response = $actionContactList->execute(); $contacts = $response->getCollection(); foreach ( $contacts as $contact ) { echo $contact->getId().'
'; } } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Batch Operations Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Shows how to send multiple SMS messages in a single operation using `SendSmssBag` for improved performance. ```php smsFeature()->sendSmss($sms); ``` -------------------------------- ### Error Context Debug Output Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/errors.md Example of logging detailed error information for debugging purposes. ```php getMessage(), $e->getCode(), $e instanceof ApiErrorException ? $e->getError() : 'N/A' )); } ``` -------------------------------- ### Check Credentials Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/INDEX.md Example of checking if the API credentials are valid by pinging the service. ```php $result = $service->pingFeature()->ping(); if ($result->authorized) { echo "Credentials valid"; } ``` -------------------------------- ### Using API Token Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/configuration.md Demonstrates how to use an API token with the SMSAPI client, including using a single token, from an environment variable (recommended), and from a configuration file. ```php smsapiComService('0123456789abcdef0123456789abcdef01234567'); // Token from environment variable (recommended for production) $apiToken = getenv('SMSAPI_TOKEN'); if (!$apiToken) { throw new Exception('SMSAPI_TOKEN environment variable not set'); } $service = $client->smsapiComService($apiToken); // Token from configuration file (use for non-sensitive setups) $config = parse_ini_file('/etc/app/smsapi.ini'); $service = $client->smsapiComService($config['api_token']); ``` -------------------------------- ### Log requests and responses Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example of how to set a logger for the SmsapiHttpClient instance to log requests and responses. ```php setLogger($logger); ``` -------------------------------- ### PaginationBag Trait Usage Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/REQUEST-BAGS.md Examples demonstrating how to use the setPaging method from the PaginationBag trait to control pagination. ```php setPaging(0, 50); // Get first 50 results $find->setPaging(50, 50); // Get next 50 results ``` -------------------------------- ### Ping Feature Usage Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example demonstrating how to use the ping feature to check authorization status. ```php pingFeature() ->ping(); if ($result->authorized) { echo 'Authorized'; } else { echo 'Not authorized'; } ``` -------------------------------- ### JsonException Usage Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/errors.md Example of catching a JsonException when the API response is not valid JSON. ```php smsFeature()->sendSms($sms); } catch (JsonException $e) { echo "Invalid API response format: " . $e->getMessage(); // The API returned non-JSON data } ``` -------------------------------- ### MFA Feature - Verify MFA Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Verify MFA code provided by user. ```php mfaFeature()->verifyMfa($verify); echo "Code verified successfully"; } catch (ApiErrorException $e) { echo "Invalid code"; } ?> ``` -------------------------------- ### Send an SMS Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/INDEX.md Example of sending a simple SMS message using the SMSAPI client. ```php $sms = SendSmsBag::withMessage('+48123456789', 'Hello'); $sms->from = 'MyApp'; $result = $service->smsFeature()->sendSms($sms); echo "Sent: " . $result->id; ``` -------------------------------- ### Create Short URL Link Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Example of creating a shortened URL using the `createShortUrlLink` method. ```php name = 'Campaign A'; $link->description = 'Q4 promotional campaign'; $short = $service->shortUrlFeature()->createShortUrlLink($link); echo "Short URL: " . $short->shortUrl . "\n"; echo "Hits: " . $short->hits . "\n"; echo "Unique hits: " . $short->hitsUnique . "\n"; ``` -------------------------------- ### Find Contact Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Get a single contact by ID. ```php contactsFeature()->findContact($find); ``` -------------------------------- ### Using SMSAPI.SE or SMSAPI.BG Services Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example of how to instantiate a service client for SMSAPI.SE or SMSAPI.BG by providing a custom URI. ```php smsapiComServiceWithUri($apiToken, $uri); ``` -------------------------------- ### deleteScheduledSms() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Example of how to delete scheduled SMS messages. ```php smsFeature()->deleteScheduledSms($delete); ``` -------------------------------- ### Run unit tests Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Command to run unit tests. ```shell make test-suite SUITE="unit" ``` -------------------------------- ### Run integration tests Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Command to run integration tests. ```shell make test-suite SUITE="integration" ``` -------------------------------- ### Error Handling Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/INDEX.md Demonstrates how to catch different types of exceptions thrown by the SMSAPI client. ```php try { $result = $service->smsFeature()->sendSms($sms); } catch (ApiErrorException $e) { echo "API Error: " . $e->getError(); } catch (NetworkException $e) { echo "Network Error: " . $e->getMessage(); } catch (SmsapiClientException $e) { echo "Unknown Error: " . $e->getMessage(); } ``` -------------------------------- ### Create a new group Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples This code snippet demonstrates how to create a new group using the SMSAPI PHP Client, including optional parameters like 'idx'. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionGroupAdd = $smsApi->actionGroupAdd('Nazwa grupy') // opcjonalne: ->setDescription('Opis') ->setIdx('Extra numer id'); // Nie mylić z numerem id $response = $actionGroupAdd->execute(); } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ``` -------------------------------- ### Run tests against PHP8 Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Instructions to run tests against PHP8 using make targets with 'php8' suffix. ```shell See Makefile.php8 ``` -------------------------------- ### scheduleSms() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Schedule SMS delivery for a specific date/time. ```php smsFeature()->scheduleSms($sms); echo "Scheduled SMS ID: " . $result->id; ``` -------------------------------- ### sendSmsToGroup() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Send SMS to all contacts in a contact group. ```php smsFeature()->sendSmsToGroup($smsGroup); foreach ($results as $sms) { echo "Sent to " . $sms->number . " - ID: " . $sms->id . "\n"; } ``` -------------------------------- ### Delete Contacts Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Delete all contacts in the account. ```php contactsFeature()->deleteContacts(); // Use with caution! ``` -------------------------------- ### Update Contact Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Update an existing contact. ```php setName('Jane', 'Doe'); $update->phoneNumber = '+48987654321'; $updated = $service->contactsFeature()->updateContact($update); ``` -------------------------------- ### sendSmss() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Send SMS to multiple recipients in a single operation. ```php smsFeature()->sendSmss($sms); echo "Sent " . count($results) . " messages"; ``` -------------------------------- ### sendSms() Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/02-sms-feature.md Send a single SMS message to one recipient. ```php from = 'MySender'; $result = $service->smsFeature()->sendSms($sms); echo "SMS ID: " . $result->id; echo "Points cost: " . $result->points; echo "Status: " . $result->status; ``` -------------------------------- ### Basic Usage Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/INDEX.md Demonstrates the basic usage of the SMSAPI PHP Client to send an SMS message. ```php smsapiComService('your-api-token'); $sms = SendSmsBag::withMessage('+48123456789', 'Hello World'); $result = $service->smsFeature()->sendSms($sms); echo "SMS ID: " . $result->id; ``` -------------------------------- ### Delete Contact Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/03-contacts-feature.md Delete a single contact by ID. ```php contactsFeature()->deleteContact($delete); ``` -------------------------------- ### Run feature tests Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Command to run feature tests for contacts. ```shell make test-suite SUITE="feature-contacts" ``` -------------------------------- ### Change SMS encoding Source: https://github.com/smsapi/smsapi-php-client/blob/master/README.md Example demonstrating how to set the SMS encoding to UTF-8. ```php encoding = 'utf-8'; ``` -------------------------------- ### FindBlacklistedPhoneNumbersBag Usage Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/REQUEST-BAGS.md Example of how to use the FindBlacklistedPhoneNumbersBag to search for blacklisted phone numbers. ```php phoneNumber = '+48123456789'; $find->offset = 0; $find->limit = 50; $results = $service->blacklistFeature()->findBlacklistedPhoneNumbers($find); ``` -------------------------------- ### DeleteScheduledSmssBag Usage Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/REQUEST-BAGS.md Example of how to use the DeleteScheduledSmssBag to delete scheduled SMS messages. ```php smsFeature()->deleteScheduledSms($delete); ``` -------------------------------- ### HLR Feature Usage Example Source: https://github.com/smsapi/smsapi-php-client/blob/master/_autodocs/api-reference/04-other-features.md Query HLR information for a phone number. ```php hlrFeature()->sendHlr($hlr); echo "Number: " . $result->number . "\n"; echo "Status: " . $result->status . "\n"; echo "Price: " . $result->price . "\n"; echo "ID: " . $result->id . "\n"; ?> ``` -------------------------------- ### Find contacts by ids Source: https://github.com/smsapi/smsapi-php-client/wiki/Examples This code snippet demonstrates how to find contacts by their IDs using the SMSAPI PHP Client. ```php require_once 'smsapi/Autoload.php'; $client = new \SMSApi\Client('Login_API'); $client->setPasswordHash( ('Haslo_API_w_md5') ); $smsApi = new \SMSApi\Api\ContactsFactory(); $smsApi->setClient($client); try { $actionContactList = $smsApi->actionContactList() ->setIds(array('Numer id #1', 'Numer id #2', 'Numer id #N')); $response = $actionContactList->execute(); $contacts = $response->getCollection(); foreach ( $contacts as $contact ) { echo $contact->getId().'
'; } } catch ( \SMSApi\Exception\SmsapiException $e ) { echo 'ERROR: ' . $e->getMessage(); } ```