Skip to content

Commit 12c41eb

Browse files
committed
Authentication Updated
Added optional functionality to preserve access token.
1 parent 9fd6bca commit 12c41eb

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobiweb/sdk",
3-
"description": "4.0.2 PHP library for communicating with the MobiWeb REST APIs.",
3+
"description": "4.0.3 PHP library for communicating with the MobiWeb REST APIs.",
44
"minimum-stability": "stable",
55
"keywords": [
66
"sms", "api", "mobiweb", "php", "messaging", "hlr", "hlr lookup", "mobile lookup", "mobile number lookup", "OTP", "one time password", "2FA", "two factor authentication", "smpp api", "smpp", "asynch"

src/MobiWeb/Rest/Authentication.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ class Authentication {
2222
protected $refresh_token;
2323
protected $timestamp;
2424
protected $endpoint;
25+
protected $preserve;
2526

2627

27-
public function __construct(string $username = null, string $password = null, string $endpoint){
28+
public function __construct(string $username = null, string $password = null, string $endpoint, bool $preserve){
2829

2930
if (!$username || !$password) {
3031
throw new \Exception("Username and Password are required to authenticate");
@@ -33,6 +34,7 @@ public function __construct(string $username = null, string $password = null, st
3334
$this->username=$username;
3435
$this->password=$password;
3536
$this->endpoint=$endpoint;
37+
$this->preserve=$preserve;
3638
}
3739

3840
public function authenticate() :bool{
@@ -43,6 +45,7 @@ public function authenticate() :bool{
4345
$body->username = $this->username;
4446
$body->password = $this->password;
4547
$body->type = Authentication::TYPE_ACCESS;
48+
$body->preserve = $this->preserve;
4649
$executedRequest=$http->request($this->endpoint . Authentication::AUTH_ENDPOINT, Authentication::AUTH_METHOD, $headers, $body);
4750

4851
if($executedRequest->response->body->status_code != HttpClient::HTTP_OK){

src/MobiWeb/Rest/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class Client {
2020
const OTP = "otp";
2121

2222

23-
public function __construct(string $username = null, string $password = null, string $endpoint = Client::API_ENDPOINT){
23+
public function __construct(string $username = null, string $password = null, string $endpoint = Client::API_ENDPOINT, bool $preserve = false){
2424

2525
if (!$username || !$password) {
2626
throw new \Exception("Username and Password are required to create a Client");
2727
}
2828

29-
$this->auth = new Auth($username,$password,$endpoint);
29+
$this->auth = new Auth($username,$password,$endpoint,$preserve);
3030
if(!$this->auth->authenticate()){
3131
throw new \Exception("Authentication failed");
3232
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
require __DIR__ . '/../../../autoload.php'; // Loads MobiWeb package
4+
5+
use MobiWeb\Rest\Client as APIClient;
6+
7+
8+
//Your account username and password
9+
$username = "";
10+
$password = "";
11+
12+
//Preserve an access_token if it already exists and it is not expired. Used when multiple nodes use the same account to access the API.
13+
$preserve=true;
14+
15+
//Endpoint Options:
16+
// APIClient::API_ENDPOINT - REST API (SMS, OTP, HLR) - Default
17+
// APIClient::SMPP_API_1_ENDPOINT - Asynchronous SMS API (SMS)
18+
// APIClient::SMPP_API_2_ENDPOINT - Asynchronous SMS API (SMS) - Alternative
19+
$endpoint = APIClient::SMPP_API_1_ENDPOINT;
20+
21+
$client = new APIClient($username, $password, $endpoint, $preserve);
22+
23+
//Submit message
24+
$message = $client->broadcast(
25+
[[
26+
"from" => "HelloWorld", //The sender displayed upon the SMS arrival. Can be composed of 2-11 alphanumeric characters (A-z,0-9, ,-,.) or 14 numeric characters (0-9). Special characters are not allowed.
27+
"to" => ["44xxxxxxxxxx"], //The full international number(s) of the recipient(s) in international E.164 format https://en.wikipedia.org/wiki/E.164.
28+
"message" => "Hello from MobiWeb!" //The text of the SMS message. If all characters in the message belong to the 3GPP GSM 7-bit GSM 03.38 ASCII character table https://en.wikipedia.org/wiki/GSM_03.38#GSM_7-bit_default_alphabet_and_extension_table_of_3GPP_TS_23.038_/_GSM_03.38, you can send up to 160 characters in a single SMS. You can send longer messages automatically by setting message parameter with your preffered text. In long SMS (multi-part SMS), each SMS part can be up to 153 characters. Each part costs as 1 SMS. If one or more characters in the message belong to the 16-bit Unicode / UCS-2 character table https://en.wikipedia.org/wiki/UTF-16, because of the increased memory requirement for each character, you can send up to 70 characters in a single SMS. In long SMS (multi-part SMS), each SMS part can be up to 67 characters. Each part costs as 1 SMS.
29+
30+
]]
31+
);
32+
33+
//Print message
34+
print_r($message);
35+
36+
?>

0 commit comments

Comments
 (0)