Skip to content

Commit 0308b57

Browse files
committed
Rename MehrAfzar to MarhAfraz and correct code style based on PSR
1 parent adca131 commit 0308b57

File tree

15 files changed

+160
-166
lines changed

15 files changed

+160
-166
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Laravel SMS Component
2-
Laravel Package for dealing with Iranian SMS prodivers working with Laravel 5 & 6
2+
Laravel Package for dealing with Iranian SMS prodivers working with Laravel 5 & 6
33

44
## Installation
55

@@ -18,7 +18,7 @@ composer require tartan/laravel-iranian-sms
1818
'IranianSms' => Tartan\IranianSms\Facades\IranianSms::class
1919
```
2020

21-
4.Publish the config file
21+
4.Publish the config file
2222
```bash
2323
php artisan vendor:publish --provider="Tartan\IranianSms\SmsServiceProvider" --tag=config
2424
```
@@ -42,7 +42,7 @@ php artisan vendor:publish --provider="Tartan\IranianSms\SmsServiceProvider" --t
4242
### available adapters
4343
* log (no charge adapter for development purposes)
4444
* slack (no charge adapter for development and staging environment)
45-
* mehrafzar مهر افزار
45+
* mehrafraz مهر افراز
4646
* kavenegar کاوه نگار
4747
* smsir اسمس آی آر
4848
* ghasedak قاصدک
@@ -56,11 +56,11 @@ php artisan vendor:publish --provider="Tartan\IranianSms\SmsServiceProvider" --t
5656

5757
return [
5858
//Default SMS gateway
59-
'default' => env('IRANIANSMS_DEFAULT','mehrafzar'),
60-
'mehrafzar' => [
61-
'gateway' => env('IRANIANSMS_MEHRAFZAR_GATEWAY','http://mehrafraz.com/webservice/Service.asmx?WSDL'),
62-
'username' => env('IRANIANSMS_MEHRAFZAR_USERNAME','test'),
63-
'password' => env('IRANIANSMS_MEHRAFZAR_PASSWORD','test'),
59+
'default' => env('IRANIANSMS_DEFAULT','mehrafraz'),
60+
'mehrafraz' => [
61+
'gateway' => env('IRANIANSMS_MEHRAFRAZ_GATEWAY','http://mehrafraz.com/webservice/Service.asmx?WSDL'),
62+
'username' => env('IRANIANSMS_MEHRAFRAZ_USERNAME','test'),
63+
'password' => env('IRANIANSMS_MEHRAFRAZ_PASSWORD','test'),
6464
],
6565
'kavenegar' => [
6666
'gateway' => env('IRANIANSMS_KAVENEGAR_GATEWAY','http://api.kavenegar.com/v1/%s/%s/%s.json/'),

config/iranian_sms.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,38 @@
33
return [
44
//Default SMS gateway
55
'default' => env('IRANIANSMS_DEFAULT', 'log'), // laravel built in log
6-
'mehrafzar' => [
7-
'gateway' => env('IRANIANSMS_MEHRAFZAR_GATEWAY', 'http://mehrafraz.com/webservice/Service.asmx?WSDL'),
8-
'username' => env('IRANIANSMS_MEHRAFZAR_USERNAME', 'test'),
9-
'password' => env('IRANIANSMS_MEHRAFZAR_PASSWORD', 'test'),
6+
7+
'mehrafraz' => [
8+
'gateway' => env('IRANIANSMS_MEHRAFRAZ_GATEWAY', 'http://mehrafraz.com/webservice/Service.asmx?WSDL'),
9+
'username' => env('IRANIANSMS_MEHRAFRAZ_USERNAME', 'test'),
10+
'password' => env('IRANIANSMS_MEHRAFRAZ_PASSWORD', 'test'),
1011
],
12+
1113
'kavenegar' => [
1214
'gateway' => env('IRANIANSMS_KAVENEGAR_GATEWAY', 'http://api.kavenegar.com/v1/%s/%s/%s.json/'),
1315
'api_key' => env('IRANIANSMS_KAVENEGAR_APIKEY', 'test'),
1416
'sender' => env('IRANIANSMS_KAVENEGAR_SENDER', 'test'),
1517
],
18+
1619
'smsir' => [
1720
'gateway' => env('IRANIANSMS_SMSIR_GATEWAY', 'http://ip.sms.ir/SendMessage.ashx'),
1821
'user' => env('IRANIANSMS_SMSIR_USER', 'test'),
1922
'pass' => env('IRANIANSMS_SMSIR_PASS', 'test'),
2023
'line_no' => env('IRANIANSMS_SMSIR_LINENO', 'test'),
2124
],
25+
2226
'ghasedak'=> [
2327
'api_key' => env('IRANIANSMS_GHASEDAK_APIKEY', 'test'),
2428
'sender' => env('IRANIANSMS_GHASEDAK_SENDER', 'test'),
2529
],
30+
2631
'slack' => [
2732
'url' => env('IRANIANSMS_SLACK_URL')
2833
],
34+
2935
'parsasms' => [
3036
'gateway' => env('IRANIANSMS_PARSASMS_GATEWAY','http://api.parsasms.com/v2/sms/send/simple'),
3137
'api_key' => env('IRANIANSMS_PARSASMS_APIKEY','test'),
3238
'sender' => env('IRANIANSMS_PARSASMS_SENDER','test')
3339
]
34-
];
40+
];

src/Adapters/AbstractAdapter.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
use Exception;
66

7-
abstract class AdapterAbstract {
8-
9-
public function filterNumber(String $number) {
10-
11-
$numberCheck = substr($number, -10);
12-
if (!preg_match('/9\d{9}$/', $numberCheck)) {
13-
throw new Exception('Number format is incorrect');
14-
}
15-
16-
return $number;
17-
18-
}
19-
20-
}
7+
abstract class AdapterAbstract
8+
{
9+
public function filterNumber(String $number) {
10+
$numberCheck = substr($number, -10);
11+
if (!preg_match('/9\d{9}$/', $numberCheck)) {
12+
throw new Exception('Number format is incorrect');
13+
}
14+
15+
return $number;
16+
17+
}
18+
}

src/Adapters/AdapterInterface.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Tartan\IranianSms\Adapter;
44

5-
6-
interface AdapterInterface {
7-
8-
public function send(String $number,String $text);
9-
10-
}
5+
interface AdapterInterface
6+
{
7+
public function send(String $number,String $text);
8+
}

src/Adapters/Exception.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
43
namespace Tartan\IranianSms\Adapters;
4+
55
use Tartan\IranianSms\Exception as RootException;
66

77
class Exception extends RootException
88
{
9-
9+
//
1010
}

src/Adapters/Ghasedak.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class Ghasedak extends AdapterAbstract implements AdapterInterface
88
{
9-
109
private $credential = [
1110
'api_key' => '',
1211
'sender' => ''
@@ -20,7 +19,6 @@ public function __construct()
2019

2120
public function send(String $number, String $message)
2221
{
23-
2422
$number = $this->filterNumber($number);
2523

2624
$api = new GhasedakApi($this->credential['api_key']);
@@ -30,6 +28,5 @@ public function send(String $number, String $message)
3028
$message,
3129
$this->credential['sender']
3230
);
33-
3431
}
35-
}
32+
}

src/Adapters/KaveNegar.php

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,45 @@
66
use Kavenegar\Exceptions\ApiException;
77
use Kavenegar\Exceptions\HttpException;
88

9-
class KaveNegar extends AdapterAbstract implements AdapterInterface {
10-
11-
private $credential = [
12-
'api_key' => '',
13-
];
14-
public $sender;
15-
public $api;
16-
17-
public static $status_real = [
18-
1 => 'SENDING',
19-
2 => 'SENDING',
20-
4 => 'SERVICE_DELIVERED',
21-
5 => 'BTS_SENT',
22-
6 => 'FAILED',
23-
10 => 'DELIVERED',
24-
11 => 'NOT_SENT_OPERATOR',
25-
13 => 'CANCELED',
26-
14 => 'BLACKLIST',
27-
100 => 'UNKNOWN_DESTINATION',
28-
];
29-
30-
public function __construct() {
31-
$this->credential['api_key'] = config('iranian_sms.kavenegar.api_key');
32-
$this->sender = config('iranian_sms.kavenegar.sender');
33-
$this->api = new KavenegarApi($this->credential['api_key']);
34-
}
35-
36-
public function send(String $number, String $message) {
37-
$number = $this->filterNumber($number);
9+
class KaveNegar extends AdapterAbstract implements AdapterInterface
10+
{
11+
private $credential = [
12+
'api_key' => '',
13+
];
14+
15+
public $sender;
16+
17+
public $api;
18+
19+
public static $status_real = [
20+
1 => 'SENDING',
21+
2 => 'SENDING',
22+
4 => 'SERVICE_DELIVERED',
23+
5 => 'BTS_SENT',
24+
6 => 'FAILED',
25+
10 => 'DELIVERED',
26+
11 => 'NOT_SENT_OPERATOR',
27+
13 => 'CANCELED',
28+
14 => 'BLACKLIST',
29+
100 => 'UNKNOWN_DESTINATION',
30+
];
31+
32+
public function __construct()
33+
{
34+
$this->credential['api_key'] = config('iranian_sms.kavenegar.api_key');
35+
$this->sender = config('iranian_sms.kavenegar.sender');
36+
$this->api = new KavenegarApi($this->credential['api_key']);
37+
}
38+
39+
public function send(String $number, String $message)
40+
{
41+
$number = $this->filterNumber($number);
3842

3943
$api = $this->api;
4044
$result = $api->Send($this->sender,$number,$message);
4145

4246
return $result[0]->messageid;
43-
}
47+
}
4448

4549
public function verifyLookup(String $number, String $token, String $template)
4650
{
@@ -50,5 +54,5 @@ public function verifyLookup(String $number, String $token, String $template)
5054
$result = $api->VerifyLookup($number,$token,$token2 = '',$token3 = '',$template,$type = null);
5155

5256
return $result[0]->messageid;
53-
}
54-
}
57+
}
58+
}

src/Adapters/MehrAfraz.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Tartan\IranianSms\Adapter;
4+
5+
class MehrAfraz extends AdapterAbstract implements AdapterInterface {
6+
7+
public $gateway_url;
8+
9+
private $credential = [
10+
'username' => '',
11+
'password' => '',
12+
];
13+
14+
public static $status_real = [
15+
0 => 'SENDING',
16+
1 => 'SERVICE_DELIVERED',
17+
2 => 'DELIVERED',
18+
3 => 'FAILED',
19+
4 => 'BLACKLIST',
20+
5 => 'NOT_EXPERT',
21+
6 => 'CANCELED',
22+
7 => 'UNKNOWN_DESTINATION',
23+
8 => 'BTS_SENT',
24+
12 => 'NOT_SENT_OPERATOR',
25+
16 => 'BTS_ERROR',
26+
];
27+
28+
public function __construct() {
29+
$this->gateway_url = config('iranian_sms.mehrafraz.gateway');
30+
$this->credential['username'] = config('iranian_sms.mehrafraz.username');
31+
$this->credential['password'] = config('iranian_sms.mehrafraz.password');
32+
}
33+
34+
public function send(String $number,String $message) {
35+
36+
$number = $this->filterNumber($number);
37+
38+
$parameters = [
39+
'cUserName' => $this->credential['username'],
40+
'cPassword' => $this->credential['password'],
41+
'cBody' => $message,
42+
'cSmsnumber' => $number,
43+
'cGetid' => time(),
44+
'nCMessage' => '1',
45+
'nTypeSent' => '1',
46+
'm_SchedulDate' => '',
47+
'cDomainname' => $this->credential['username'],
48+
'nSpeedsms' => '0',
49+
'nPeriodmin' => '0',
50+
'cstarttime' => '',
51+
'cEndTime' => '',
52+
];
53+
54+
try {
55+
$soapParams = [];
56+
$soapParams['xml_encoding'] = "UTF-8";
57+
$soapParams['soap_defencoding'] = "UTF-8";
58+
$soapParams['decode_utf8'] = false;
59+
$soapParams['exceptions'] = 1;
60+
$soapClient = @new \SoapClient($this->gateway_url, $soapParams);
61+
$result = $soapClient->SendSms($parameters);
62+
} catch (SoapFault $client) {
63+
//
64+
} catch (Exception $e) {
65+
//
66+
}
67+
68+
69+
if (($result->SendSmsResult && $result->SendSmsResult > 1000)) {
70+
return $result->SendSmsResult;
71+
}
72+
73+
throw new \Exception("SMS cannot be send!");
74+
}
75+
76+
}

0 commit comments

Comments
 (0)