Skip to content

Commit f9275c3

Browse files
committed
1.0.2
1 parent f210a7d commit f9275c3

21 files changed

+186
-200
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# sms
2-
Simple SMS Gateway Package for sending short text messages. Currently Bulksms, Clickatell, Gupshup, Infobip, Mocker, MVaayoo, Nexmo, SmsAchariya, Smsapi, SmsCountry, SmsLane, twilio and Any HTTP/s based Gateways are supported with Custom Gateway. Default Log gateway can be used for testing.
2+
Simple SMS Gateway Package for sending short text messages. Currently Bulksms, Clickatell, Gupshup, Infobip, Itexmo, Mocker, MVaayoo, Nexmo, SmsAchariya, Smsapi, SmsCountry, SmsLane, twilio and Any HTTP/s based Gateways are supported with Custom Gateway. Default Log gateway can be used for testing.
33

44
### Installation
55

@@ -51,15 +51,16 @@ Currently these gateways are supported
5151
2. Clickatell
5252
3. Gupshup
5353
4. Infobip
54-
5. Mocker
55-
6. MVaayoo
56-
7. Nexmo
57-
8. SmsAchariya
58-
9. Smsapi
59-
10. SmsCountry
60-
11. SmsLane
61-
12. twilio
62-
12. Custom
54+
5. Itexmo
55+
6. Mocker
56+
7. MVaayoo
57+
8. Nexmo
58+
9. SmsAchariya
59+
10. Smsapi
60+
11. SmsCountry
61+
12. SmsLane
62+
13. Twilio
63+
14. Custom
6364

6465
Default Gateway: `Log`
6566

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tecdiary/sms",
3-
"description": "Simple SMS Gateway Package for sending short text messages. Currently Bulksms, Clickatell, Gupshup, Infobip, Mocker, MVaayoo, Nexmo, SmsAchariya, Smsapi, SmsCountry, SmsLane, twilio and Any HTTP/s based Gateways are supported with Custom Gateway. Default Log gateway can be used for testing.",
3+
"description": "Simple SMS Gateway Package for sending short text messages. Currently Bulksms, Clickatell, Gupshup, Infobip, Itexmo, Mocker, MVaayoo, Nexmo, SmsAchariya, Smsapi, SmsCountry, SmsLane, twilio and Any HTTP/s based Gateways are supported with Custom Gateway. Default Log gateway can be used for testing.",
44
"license": "MIT",
55
"keywords": ["PHP SMS", "Bulksms", "Clickatell", "Gupshup", "Infobip", "Mocker", "MVaayoo", "Nexmo", "SmsAchariya", "Smsapi", "SmsCountry", "SmsLane", "twilio", "Custom Sms", "sms gateway"],
66
"authors": [

demo/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
$sms = new \Tecdiary\Sms\Sms($config);
1515

1616
$result = $sms->send(['+919090909090', '009190909090901'], 'This is test message for Log gateway.')->response();
17+
1718
?><html>
1819
<head>
1920
<meta charset="UTF-8">

sampleConfig.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'Gupshup' => ['userid' => '', 'password' => ''],
3535

3636
// API_CODE
37-
'itexmo' => ['api_code' => ''],
37+
'Itexmo' => ['api_code' => ''],
3838

3939
// http://mvaayoo.com
4040
'MVaayoo' => ['user' => '', 'senderID' => ''],
@@ -52,7 +52,7 @@
5252
'Nexmo' => ['api_key' => '', 'api_secret' => '', 'from' => ''],
5353

5454
// http://twilio.com
55-
'twilio' => ['account_sid' => '', 'auth_token' => '', 'from' => ''],
55+
'Twilio' => ['account_sid' => '', 'auth_token' => '', 'from' => ''],
5656

5757
// http://mocker.in
5858
'Mocker' => ['sender_id' => ''],
@@ -79,13 +79,13 @@
7979
'param1' => '',
8080
'param2' => '',
8181
'param3' => '',
82-
'param4' => '',
82+
'param4' => ''
8383
]
8484
]
85-
]
85+
],
8686

8787
'log' => [
88-
'path' => __DIR__ . '\path\to\logs\sma.log';
88+
'path' => __DIR__ . '\path\to\logs\sma.log',
8989
'level' => 400
9090
]
9191
];

src/Gateways/BulksmsGateway.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,41 @@
55
class BulksmsGateway implements SmsGatewayInterface
66
{
77
public $config;
8-
public $logger;
98
public $response = '';
109

1110
protected $params = [];
1211
protected $request = '';
1312
protected $url = '';
1413

15-
public function __construct($config, $logger)
14+
public function __construct($config)
1615
{
1716
$this->config = $config;
18-
$this->logger = $logger;
1917
$this->params['msisdn'] = '';
2018
$this->params['message'] = '';
2119
$this->params['username'] = $this->config[$this->config['gateway']]['username'];
22-
$this->params['username'] = $this->config[$this->config['gateway']]['username'];
20+
$this->params['password'] = $this->config[$this->config['gateway']]['password'];
2321
$this->url = $this->config[$this->config['gateway']]['eapi_url']."/submission/send_sms/2/2.0?";
2422
}
2523

2624
public function getUrl()
2725
{
28-
foreach ($this->params as $key => $val) {
29-
$this->request .= $key . "=" . urlencode($val);
30-
$this->request .= "&";
31-
}
32-
$this->request = substr($this->request, 0, strlen($this->request)-1);
33-
return $this->url.$this->request;
26+
return $this->url.http_build_query($this->params);
3427
}
3528

3629
public function sendSms($mobile, $message)
3730
{
3831
$this->params['msisdn'] = $mobile;
3932
$this->params['message'] = $message;
4033
$client = new \GuzzleHttp\Client(['headers' => ['Accept' => 'application/json']]);
41-
$this->response = $client->get($this->getUrl())->getBody()->getContents();
42-
$this->logger->info('Bulksms Response: '.$this->response);
34+
try {
35+
$response = $client->get($this->getUrl())->getBody()->getContents();
36+
$this->response = explode('|', $response);
37+
if ($this->response[0] > 1) {
38+
throw new \Exception($response);
39+
}
40+
} catch (\Exception $e) {
41+
$this->response = ['error' => $e->getMessage()];
42+
}
4343
return $this;
4444
}
4545

src/Gateways/ClickatellGateway.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,39 @@
55
class ClickatellGateway implements SmsGatewayInterface
66
{
77
public $config;
8-
public $logger;
98
public $response = '';
109

1110
protected $params = [];
1211
protected $request = '';
13-
protected $url = 'http://api.clickatell.com/http/sendmsg?';
12+
protected $url = 'https://platform.clickatell.com/messages/http/send?';
1413

15-
public function __construct($config, $logger)
14+
public function __construct($config)
1615
{
1716
$this->config = $config;
18-
$this->logger = $logger;
1917
$this->params['to'] = '';
20-
$this->params['text'] = '';
21-
$this->params['user'] = $this->config[$this->config['gateway']]['user'];
22-
$this->params['api_id'] = $this->config[$this->config['gateway']]['api_id'];
23-
$this->params['password'] = $this->config[$this->config['gateway']]['password'];
18+
$this->params['content'] = '';
19+
$this->params['apiKey'] = $this->config[$this->config['gateway']]['apiKey'];
2420
}
2521

2622
public function getUrl()
2723
{
28-
foreach ($this->params as $key => $val) {
29-
$this->request .= $key . "=" . urlencode($val);
30-
$this->request .= "&";
31-
}
32-
$this->request = substr($this->request, 0, strlen($this->request)-1);
33-
return $this->url.$this->request;
24+
return $this->url.http_build_query($this->params);
3425
}
3526

3627
public function sendSms($mobile, $message)
3728
{
3829
$this->params['to'] = $mobile;
39-
$this->params['text'] = $message;
30+
$this->params['content'] = $message;
4031
$client = new \GuzzleHttp\Client();
41-
$this->response = $client->get($this->getUrl())->getBody()->getContents();
42-
$this->logger->info('Clickatell Response: '.$this->response);
32+
try {
33+
$response = $client->get($this->getUrl())->getBody()->getContents();
34+
$this->response = json_decode($response, true);
35+
if ($this->response['errorCode']) {
36+
throw new \Exception($this->response['errorCode'].': '.$this->response['error']);
37+
}
38+
} catch (\Exception $e) {
39+
$this->response = ['error' => $e->getMessage()];
40+
}
4341
return $this;
4442
}
4543

src/Gateways/CustomGateway.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,33 @@
55
class CustomGateway implements SmsGatewayInterface
66
{
77
public $config;
8-
public $logger;
98
public $response = '';
109

1110
protected $url = '';
1211
protected $params = [];
13-
protected $request = '';
1412

15-
public function __construct($config, $logger)
13+
public function __construct($config)
1614
{
1715
$this->config = $config;
18-
$this->logger = $logger;
1916
$this->url = $this->config[$this->config['gateway']]['url'];
2017
$this->params = $this->config[$this->config['gateway']]['params']['others'];
2118
}
2219

2320
public function getUrl()
2421
{
25-
foreach ($this->params as $key => $val) {
26-
$this->request.= $key."=".urlencode($val);
27-
$this->request.= "&";
28-
}
29-
$this->request = substr($this->request, 0, strlen($this->request)-1);
30-
return $this->url.$this->request;
22+
return $this->url.http_build_query($this->params);
3123
}
3224

3325
public function sendSms($mobile, $message)
3426
{
3527
$this->params[$this->config[$this->config['gateway']]['params']['send_to_name']] = $mobile;
3628
$this->params[$this->config[$this->config['gateway']]['params']['msg_name']] = $message;
3729
$client = new \GuzzleHttp\Client();
38-
$this->response = $client->get($this->getUrl())->getBody()->getContents();
39-
$this->logger->info('Custom SMS Gateway Response: '.$this->response);
30+
try {
31+
$this->response = $client->get($this->getUrl())->getBody()->getContents();
32+
} catch (\Exception $e) {
33+
$this->response = ['error' => $e->getMessage()];
34+
}
4035
return $this;
4136
}
4237

src/Gateways/GupshupGateway.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
class GupshupGateway implements SmsGatewayInterface
66
{
77
public $config;
8-
public $logger;
98
public $response = '';
109

1110
protected $params = [];
12-
protected $request = '';
1311
protected $url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest?';
1412

15-
public function __construct($config, $logger)
13+
public function __construct($config)
1614
{
1715
$this->config = $config;
18-
$this->logger = $logger;
1916
$this->params['send_to'] = '';
2017
$this->params['msg'] = '';
2118
$this->params['method'] = 'sendMessage';
@@ -28,21 +25,20 @@ public function __construct($config, $logger)
2825

2926
public function getUrl()
3027
{
31-
foreach ($this->params as $key => $val) {
32-
$this->request.= $key."=".urlencode($val);
33-
$this->request.= "&";
34-
}
35-
$this->request = substr($this->request, 0, strlen($this->request)-1);
36-
return $this->url.$this->request;
28+
return $this->url.http_build_query($this->params);
3729
}
3830

3931
public function sendSms($mobile, $message)
4032
{
4133
$this->params['send_to'] = $mobile;
4234
$this->params['msg'] = $message;
4335
$client = new \GuzzleHttp\Client();
44-
$this->response = $client->get($this->getUrl())->getBody()->getContents();
45-
$this->logger->info('Gupshup Response: '.$this->response);
36+
$client = new \GuzzleHttp\Client();
37+
try {
38+
$this->response = $client->get($this->getUrl())->getBody()->getContents();
39+
} catch (\Exception $e) {
40+
$this->response = ['error' => $e->getMessage()];
41+
}
4642
return $this;
4743
}
4844

@@ -51,6 +47,7 @@ public function response()
5147
$success = substr_count($this->response, 'success');
5248
$error = substr_count($this->response, 'error');
5349
return [
50+
'error' => $error,
5451
'status' => [
5552
'success' => $success,
5653
'error' => $error

src/Gateways/InfobipGateway.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
class InfobipGateway implements SmsGatewayInterface
66
{
77
public $config;
8-
public $logger;
98
public $response = '';
109

1110
protected $params = [];
12-
protected $request = '';
1311
protected $url = 'http://api.infobip.com/sms/1/text/query?';
1412

15-
public function __construct($config, $logger)
13+
public function __construct($config)
1614
{
1715
$this->config = $config;
18-
$this->logger = $logger;
1916
$this->params['to'] = '';
2017
$this->params['text'] = '';
2118
$this->params['username'] = $this->config[$this->config['gateway']]['username'];
@@ -24,21 +21,19 @@ public function __construct($config, $logger)
2421

2522
public function getUrl()
2623
{
27-
foreach ($this->params as $key => $val) {
28-
$this->request .= $key . "=" . urlencode($val);
29-
$this->request .= "&";
30-
}
31-
$this->request = substr($this->request, 0, strlen($this->request)-1);
32-
return $this->url.$this->request;
24+
return $this->url.http_build_query($this->params);
3325
}
3426

3527
public function sendSms($mobile, $message)
3628
{
3729
$this->params['to'] = $mobile;
3830
$this->params['text'] = $message;
3931
$client = new \GuzzleHttp\Client(['headers' => ['Accept' => 'application/json']]);
40-
$this->response = $client->get($this->getUrl())->getBody()->getContents();
41-
$this->logger->info('Infobip Response: '.$this->response);
32+
try {
33+
$this->response = $client->get($this->getUrl())->getBody()->getContents();
34+
} catch (\Exception $e) {
35+
$this->response = ['error' => $e->getMessage()];
36+
}
4237
return $this;
4338
}
4439

src/Gateways/ItexmoGateway.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
class ItexmoGateway implements SmsGatewayInterface
66
{
77
public $config;
8-
public $logger;
98
public $response = '';
109

1110
protected $params = [];
12-
protected $request = '';
1311
protected $url = 'https://www.itexmo.com/php_api/api.php';
1412

15-
public function __construct($config, $logger)
13+
public function __construct($config)
1614
{
1715
$this->config = $config;
18-
$this->logger = $logger;
1916
$this->params['3'] = $this->config[$this->config['gateway']]['api_code'];
2017
}
2118

@@ -29,8 +26,11 @@ public function sendSms($mobile, $message)
2926
$this->params['1'] = $mobile;
3027
$this->params['2'] = $message;
3128
$client = new \GuzzleHttp\Client();
32-
$this->response = $client->post($this->getUrl(), ['form_params'=>$this->params])->getBody()->getContents();
33-
$this->logger->info('Itexmo Response: '.$this->response);
29+
try {
30+
$this->response = $client->post($this->getUrl(), ['form_params'=>$this->params])->getBody()->getContents();
31+
} catch (\Exception $e) {
32+
$this->response = ['error' => $e->getMessage()];
33+
}
3434
return $this;
3535
}
3636

0 commit comments

Comments
 (0)