PHPackages                             jackmartin/bsg-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. jackmartin/bsg-php

ActiveLibrary[API Development](/categories/api)

jackmartin/bsg-php
==================

BSG.WORLD API library

1.0.0(6y ago)0326BSD 2-ClausePHP

Since Oct 9Pushed 6y agoCompare

[ Source](https://github.com/martinjack/bsg-php)[ Packagist](https://packagist.org/packages/jackmartin/bsg-php)[ Docs](https://github.com/martinjack/bsg-php)[ RSS](/packages/jackmartin-bsg-php/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

bsg-sdk
=======

[](#bsg-sdk)

This repository contains the open source Php client for BSG's REST API.

Requirements
============

[](#requirements)

- [Sign up](https://bsg.world) for a free account
- Get api key

Instalation
===========

[](#instalation)

Download and use files from "src" directory. No installation needed. Composer used only for phpunit tests.

BSG class
---------

[](#bsg-class)

Bsg class provide access to the hlr/sms/viber clients

**Parameters**

> **apiKey** *(string)* Api key from bsg.world. Required.
>
> **sender** *(string)* Sender name for sms
>
> **viberSender** *(string)* Sender name for viber (alpha name)
>
> **tariff** *(int)* Tariff that should be used for this session
>
> **api source** *(string)* Name of your application (not required)

```
$apiKey = 'test_8zWaPwOaHDPRFmgIldhl'
$bsg = new BSG($apiKey, 'originator', 'aplhaname', 3, 'Bitrix-24')

```

API function "balance"
----------------------

[](#api-function-balance)

BSG provides an API to get the balance information of your account.

```
$apikey = 'test_8zWaPwOaHDPRFmgIldhl';
$api = new BSG($apikey);
$client = $api->getSmsClient(); //get one of the clients
$balance = $client->getBalance();

```

#### Simple response

[](#simple-response)

```
$balance = array(5) {
             ["error"]=>
             int(0)
             ["errorDescription"]=>
             string(9) "No errors"
             ["amount"]=>
             string(10) "-4.0999333"
             ["currency"]=>
             string(3) "EUR"
             ["limit"]=>
             string(1) "7"
           }

```

API functions "sendHLR"
-----------------------

[](#api-functions-sendhlr)

Number Lookup helps you keep your mobile numbers database up to date.

Mobile subscribers often change numbers, go into roaming and change providers while retaining their original phone number. Knowing which mobile numbers are in use and available, or which network your client is currently using can greatly improve accuracy and cost effectiveness for many types of businesses. With Number Lookup, you can determine:

- which numbers are currently active
- is the mobile number in roaming
- is the mobile number ported

**Parameters**

> **msisdn** *(int)* The telephone number. Required.
>
> **reference** *(string)* A client reference. Required.
>
> **tariff** *(int)* Tariff code of a price grid. Use value from BSG class if it empty. Use default value from bsg cabinet if it wasn't set at all

#### HLR request:

[](#hlr-request)

```
$hlr = $bsg->getHLRClient();
$responce = $hlr->sendHLR('+380501111111', (string)time());

```

Example response:

```
   $response = array(3) {
                ["result"]=>
                array(1) {
                  [0]=>
                  array(9) {
                    ["error"]=>
                    int(0)
                    ["errorDescription"]=>
                    string(9) "No errors"
                    ["msisdn"]=>
                    string(12) "380501111111"
                    ["reference"]=>
                    string(10) "1488536778"
                    ["tariff_code"]=>
                    string(1) "0"
                    ["callback_url"]=>
                    string(0) ""
                    ["price"]=>
                    float(0.0025)
                    ["currency"]=>
                    string(3) "EUR"
                    ["id"]=>
                    string(6) "174568"
                  }
                }
                ["total_price"]=>
                float(0.0025)
                ["currency"]=>
                string(3) "EUR"
              }

```

#### Multiple HLR request. API function sendHLRS:

[](#multiple-hlr-request-api-function-sendhlrs)

Send multiple hlr queries in one time.
Exaple:

```
$response = $hlr->sendHLRS(
      [
        [
          "msisdn"=>"380501111111", //required
          "reference"=>"extid1",  //required
          "tariff"=>"0",
        ],
        [
          "msisdn"=>"380501111112",
          "reference"=>"extid2",
          "tariff"=>"0",
        ]
      ]
)

```

Example response:

```
$response = {array(3) {
               ["result"]=>
               array(2) {
                 [0]=>
                 array(8) {
                   ["error"]=>
                   int(0)
                   ["msisdn"]=>
                   string(12) "380501111111"
                   ["reference"]=>
                   string(14) "extid1"
                   ["tariff_code"]=>
                   string(1) "0"
                   ["callback_url"]=>
                   string(0) ""
                   ["price"]=>
                   float(0.0025)
                   ["currency"]=>
                   string(3) "EUR"
                   ["id"]=>
                   string(6) "174573"
                 }
                 [1]=>
                 array(8) {
                   ["error"]=>
                   int(0)
                   ["msisdn"]=>
                   string(12) "380501111112"
                   ["reference"]=>
                   string(14) "extid2"
                   ["tariff_code"]=>
                   string(1) "0"
                   ["callback_url"]=>
                   string(0) ""
                   ["price"]=>
                   float(0.0025)
                   ["currency"]=>
                   string(3) "EUR"
                   ["id"]=>
                   string(6) "174574"
                 }
               }
               ["total_price"]=>
               float(0.005)
               ["currency"]=>
               string(3) "EUR"
             }

```

API function "getStatusByReference"
-----------------------------------

[](#api-function-getstatusbyreference)

Retrieves the information of an existing HLR. You only need to supply the unique message reference that was set upon creation.

```
$response = $hlr->getStatusByReference('ref1);

```

Example response:

```
$response = array(14) {
              ["error"]=>
              int(0)
              ["errorDescription"]=>
              string(9) "No errors"
              ["name_ru"]=>
              string(14) "Украина"
              ["name_en"]=>
              string(7) "Ukraine"
              ["brand"]=>
              string(3) "MTS"
              ["name"]=>
              string(11) "MTS Ukraine"
              ["msisdn"]=>
              string(12) "380501111111"
              ["id"]=>
              string(12) "380501111111"
              ["reference"]=>
              string(12) "su1488546296"
              ["network"]=>
              string(5) "25501"
              ["status"]=>
              string(6) "failed"
              ["details"]=>
              NULL
              ["createdDatetime"]=>
              string(25) "2017-03-03T13:04:56+00:00"
              ["statusDatetime"]=>
              string(25) "2017-03-03T13:04:56+00:00"
            }

```

API function "getStatusById"
----------------------------

[](#api-function-getstatusbyid)

Retrieves the information of an existing HLR. You only need to supply the unique message id that was returned upon creation or receiving.
Example:

```
$response = $hlr->getStatusById('1);

```

Example response:

```
$response = array(14) {
              ["error"]=>
              int(0)
              ["errorDescription"]=>
              string(9) "No errors"
              ["name_ru"]=>
              string(14) "Украина"
              ["name_en"]=>
              string(7) "Ukraine"
              ["brand"]=>
              string(3) "MTS"
              ["name"]=>
              string(11) "MTS Ukraine"
              ["msisdn"]=>
              string(12) "380501111111"
              ["id"]=>
              string(12) "380501111111"
              ["reference"]=>
              string(12) "su1488546296"
              ["network"]=>
              string(5) "25501"
              ["status"]=>
              string(6) "failed"
              ["details"]=>
              NULL
              ["createdDatetime"]=>
              string(25) "2017-03-03T13:04:56+00:00"
              ["statusDatetime"]=>
              string(25) "2017-03-03T13:04:56+00:00"
            }

```

SMS message
-----------

[](#sms-message)

BSG provides an API to send SMS messages to any country across the world.

BSG are identified by a unique random ID. And with this ID you can always check the status of the message through the provided endpoint.

### API function sendSms

[](#api-function-sendsms)

Creates a new message object. BSG returns the created message object with each request. Per request, a max of 50 phones can be entered.

**Parameters**

> **msisdn** *(string)* The telephone number. Required

> **body** *(string)* The body of the SMS message. Required

> **reference** *(string)* A client reference. Required

> **validity** *(int)* The amount of seconds that the message is valid.

> **tariff** *(int)* Tariff code of a price grid.

> **originator** *(string)* The sender of the message. This can be a telephone number (including country code) or an alphanumeric string. In case of an alphanumeric string, the maximum length is 11 characters. Uses value from BSG if it was set. In all other cases - required

#### Single sms

[](#single-sms)

```
$smsClient = $BSG->getSmsClient();
$smsClient->sendSms(
    '380501111111',
    'test',
    'successSend' . (string)time()
);

```

#### Multiple sms

[](#multiple-sms)

```
$smsclient->$answer = $this->smsClient->sendSmsMulti([
                            ['msisdn' => 380501111111, 'body' =>'test', 'reference' => 'successSendM' . (string)time()],
                            ['msisdn' => 380501111112, 'body' =>'tes2', 'reference' => 'successSendM1' . (string)time()],
                        ]);

```

Example response:

```
  $answer = array(3) {
              ["result"]=>
              array(2) {
                [0]=>
                array(6) {
                  ["error"]=>
                  int(0)
                  ["errorDescription"]=>
                  string(9) "No errors"
                  ["reference"]=>
                  string(22) "successSendM1488547867"
                  ["id"]=>
                  string(6) "174584"
                  ["price"]=>
                  float(0.1)
                  ["currency"]=>
                  string(3) "EUR"
                }
                [1]=>
                array(6) {
                  ["error"]=>
                  int(0)
                  ["errorDescription"]=>
                  string(9) "No errors"
                  ["reference"]=>
                  string(23) "successSendM11488547867"
                  ["id"]=>
                  string(6) "174585"
                  ["price"]=>
                  float(0.1)
                  ["currency"]=>
                  string(3) "EUR"
                }
              }
              ["total_price"]=>
              float(0.2)
              ["currency"]=>
              string(3) "EUR"
            }

```

### View a status

[](#view-a-status)

#### by SMS ID

[](#by-sms-id)

```
$response = $smsClient->getStatusById(214);

```

#### by reference

[](#by-reference)

```
$response = $smsClient->getStatusByReference(ref1);

```

#### by task ID

[](#by-task-id)

```
$response = $smsClient->getTaskStatus(214);

```

Example response:

### SINGLE SMS RESPONSE

[](#single-sms-response)

```
  array(11) {
    ["error"]=>
    int(0)
    ["errorDescription"]=>
    string(9) "No errors"
    ["id"]=>
    string(12) "380501111111"
    ["msisdn"]=>
    string(12) "380501111111"
    ["reference"]=>
    string(21) "successSend1488548141"
    ["time_in"]=>
    string(19) "2017-03-03 13:35:42"
    ["time_sent"]=>
    string(19) "2017-03-03 13:35:42"
    ["time_dr"]=>
    string(19) "2017-03-03 13:35:42"
    ["status"]=>
    string(7) "unknown"
    ["price"]=>
    int(0)
    ["currency"]=>
    string(3) "EUR"
  }

```

\###TASK SMS RESPONSE

```
  array(10) {
    ["originator"]=>
    string(4) "name"
    ["body"]=>
    string(4) "body"
    ["validity"]=>
    int(72)
    ["totalprice"]=>
    float(0.1)
    ["currency"]=>
    string(3) "EUR"
    ["sent"]=>
    int(1)
    ["delivered"]=>
    int(1)
    ["expired"]=>
    int(0)
    ["undeliverable"]=>
    int(0)
    ["unknown"]=>
    int(0)
  }

```

Viber message
-------------

[](#viber-message)

VIBER provides an API to send VIBER messages to any country across the world.

BSG are identified by a unique random ID. And with this ID you can always check the status of the message through the provided endpoint.

### API function addMessage

[](#api-function-addmessage)

Add a VIBER message into queue

**Parameters**

> **to** *(array)* The array of recipients msisdn's &amp; reference's. Required

> **messages** *(string)* Viber message. Required.

> **options**: *(hash)* An hash with VIBER options.

> **alpha\_name** *(string)* The sender of the message. Uses the value of "viber sender name" from BSG class if not setted. Required if it is empty

> **is\_promotional** *(bool)* Set is this message promotional. Default is true

> **callback\_url** *(string)* Link for delivery reports. Reference id is required in message arrray

```
$viberClient = $bsg->getViberClient();

$response = $viberClient->addMessage([['msisdn' => 380501111111]], 'test');

```

Add image and link to the message:

```
$viberClient->addMessage([['msisdn' => msisdn' => 380501111111]], 'test', [
                    "img" => "http://my-cool-webpage.com/logo.png",
                    "caption" => "Join us!",
                    "action" => "http://my-cool-webpage.com"
                ]);

```

Return: Void

### API function sendMessages

[](#api-function-sendmessages)

Send all messages from queue

**Parameters**

> **validity** *(int)* The amount of seconds that the message is valid.

> **tariff** *(int)* Tariff code of a price grid.

```
$viberClient = $bsg->sendMessages();

```

Example of response:

```
$response = array(3) {
  ["result"]=>
  array(1) {
    [0]=>
    array(5) {
      ["error"]=>
      int(0)
      ["errorDescription"]=>
      string(9) "No errors"
      ["id"]=>
      string(6) "174592"
      ["price"]=>
      int(0)
      ["currency"]=>
      string(3) "EUR"
    }
  }
  ["currency"]=>
  string(3) "EUR"
  ["total_price"]=>
  int(0)
}

```

### View a status

[](#view-a-status-1)

Retrieves the information of an existing message. This message can be a sent or a received message. You only need to supply the unique message id that was returned upon creation or receiving.

```
$response = $viberClient->getStatusById(216);

```

or by reference

```
$response = $api->getStatusByReference("ext_id_19");

```

Example response:

```
  $response = array(11) {
                ["error"]=>
                int(0)
                ["errorDescription"]=>
                string(9) "No errors"
                ["id"]=>
                string(12) "380501111111"
                ["msisdn"]=>
                string(12) "380501111111"
                ["reference"]=>
                string(25) "38050111111158b977704621d"
                ["time_in"]=>
                string(19) "2017-03-03 14:02:24"
                ["time_sent"]=>
                string(19) "2017-03-03 14:02:24"
                ["time_dr"]=>
                string(19) "2017-03-03 14:02:24"
                ["status"]=>
                string(7) "expired"
                ["price"]=>
                int(0)
                ["currency"]=>
                string(3) "EUR"
              }

```

Price
-----

[](#price)

BSG provides an API to get the price information of your account.

API function "getPrices"
------------------------

[](#api-function-getprices)

Return chosen tariff prices

**Parameters**

> **tariff** *(int)* The type of message campaign

#### HLR Price

[](#hlr-price)

```
$response = $hlrClient->getPrices();

```

#### SMS Price

[](#sms-price)

```
$response = $smsClient->getPrices();

```

#### Viber price by tarif ID

[](#viber-price-by-tarif-id)

```
$response = $viberClient->getPrices();

```

Example response:

```
$response = array(3) {
                ["error"]=>
                int(0)
                ["errorDescription"]=>
                string(9) "No errors"
                ["prices"]=>
                array(191) {
                  [0]=>
                  array(6) {
                    ["type"]=>
                    string(3) "hlr"
                    ["country"]=>
                    string(0) ""
                    ["country_name"]=>
                    string(15) "Other countries"
                    ["mcc"]=>
                    string(0) ""
                    ["price"]=>
                    string(9) "0.0034000"
                    ["currency"]=>
                    string(3) "EUR"
                  }
                  [1]=>
                  array(6) {
                    ["type"]=>
                    string(3) "hlr"
                    ["country"]=>
                    string(2) "AB"
                    ["country_name"]=>
                    string(8) "Abkhazia"
                    ["mcc"]=>
                    string(3) "289"
                    ["price"]=>
                    string(9) "0.0050000"
                    ["currency"]=>
                    string(3) "EUR"
                  }
                  [2]=>
                  array(6) {
                    ["type"]=>
                    string(3) "hlr"
                    ["country"]=>
                    string(2) "AD"
                    ["country_name"]=>
                    string(7) "Andorra"
                    ["mcc"]=>
                    string(3) "213"
                    ["price"]=>
                    string(9) "0.0025000"
                    ["currency"]=>
                    string(3) "EUR"
                  }
                 }
                }

```

\###Tests This sdk also contain phpunit tests with for all functions our API (with checking errors). To start them, check "/tests/TestConfig.php" and change value of api key, sender name and viber sender name. After that, just use:

```
$ phpunit -c tests/

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2410d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8a1483333bcef52a341ab14c3c096a0e577ca3e7499ab224202e47991434217?d=identicon)[jackmartin](/maintainers/jackmartin)

---

Top Contributors

[![fantom79022](https://avatars.githubusercontent.com/u/9367541?v=4)](https://github.com/fantom79022 "fantom79022 (24 commits)")[![martinjack](https://avatars.githubusercontent.com/u/11950689?v=4)](https://github.com/martinjack "martinjack (4 commits)")[![Naurzalin](https://avatars.githubusercontent.com/u/355087?v=4)](https://github.com/Naurzalin "Naurzalin (1 commits)")

---

Tags

apilibrarysmsbsg.world

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jackmartin-bsg-php/health.svg)

```
[![Health](https://phpackages.com/badges/jackmartin-bsg-php/health.svg)](https://phpackages.com/packages/jackmartin-bsg-php)
```

###  Alternatives

[smsfactor/smsfactor-php-sdk

SMSFactor client library for PHP

15382.5k2](/packages/smsfactor-smsfactor-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
