Skip to content

Commit 7b96104

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents e226b19 + 9a3dbfb commit 7b96104

File tree

11 files changed

+161
-116
lines changed

11 files changed

+161
-116
lines changed

config/sms.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414

1515
'drivers' => [
1616
'ippanel' => [
17-
'key' => '',
17+
'key' => '',
1818
'originator' => '+9890000',
19-
// 'patterns' => [
20-
// 'verify' => [
21-
// 'pattern_code' => '',
22-
// ],
23-
// ],
19+
// 'patterns' => [
20+
// 'verify' => [
21+
// 'pattern_code' => '',
22+
// ],
23+
// ],
2424
'SEND_MESSAGE_API' => 'http://rest.ippanel.com/v1/messages',
2525
'SEND_PATTERN_API' => 'http://rest.ippanel.com/v1/messages/patterns/send',
2626
],
2727
],
2828

2929
'map' => [
30-
'ippanel' => \Metti\LaravelSms\Drivers\Ippanel\Ippanel::class
30+
'ippanel' => \Metti\LaravelSms\Drivers\Ippanel\Ippanel::class,
3131
],
32-
];
32+
];

src/Abstracts/Driver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Metti\LaravelSms\Abstracts;
34

45
use Metti\LaravelSms\Contracts\DriverInterface;
@@ -23,11 +24,11 @@ abstract class Driver implements DriverInterface
2324
*/
2425
public $message;
2526

26-
abstract public function __construct($message,$settings);
27+
abstract public function __construct($message, $settings);
2728

2829
/**
2930
* @return mixed
3031
* @description send message action
3132
*/
3233
abstract public function sendMessage();
33-
}
34+
}

src/Contracts/DriverInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
namespace Metti\LaravelSms\Contracts;
34

4-
interface DriverInterface {
5+
interface DriverInterface
6+
{
57
/**
68
* @return mixed
79
* @description send message action
810
*/
911
public function sendMessage();
10-
}
12+
}

src/Drivers/Ippanel/Ippanel.php

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
2+
23
namespace Metti\LaravelSms\Drivers\Ippanel;
34

45
use GuzzleHttp\Client;
56
use Metti\LaravelSms\Abstracts\Driver;
67
use Metti\LaravelSms\Exceptions\DriverException;
78
use Metti\LaravelSms\Exceptions\ResponseErrorException;
89

9-
class Ippanel extends Driver {
10+
class Ippanel extends Driver
11+
{
1012
/**
1113
* Guzzle Client.
1214
*
@@ -15,94 +17,100 @@ class Ippanel extends Driver {
1517
protected $client;
1618

1719
/**
18-
* Driver config settings
20+
* Driver config settings.
1921
*
2022
* @var object
2123
*/
2224
protected $settings;
2325

2426
public $message;
2527

26-
public function __construct($message,$settings){
28+
public function __construct($message, $settings)
29+
{
2730
$this->client = new Client();
2831
$this->message = $message;
29-
$this->settings = (array)$settings;
32+
$this->settings = (array) $settings;
3033
}
3134

32-
public function sendMessage(){
33-
if($this->message->type == 'text'){
35+
public function sendMessage()
36+
{
37+
if ($this->message->type == 'text') {
3438
$res = $this->sendTextMessage();
35-
}elseif ($this->message->type == 'pattern') {
39+
} elseif ($this->message->type == 'pattern') {
3640
$res = $this->sendPatternMessage();
37-
}else {
41+
} else {
3842
throw new DriverException('این نوع پیام توسط آیپی پنل پشتیبانی نمیشود');
3943
}
4044

41-
$body = (array)@json_decode($res->getBody()->getContents(), true);
45+
$body = (array) @json_decode($res->getBody()->getContents(), true);
4246

4347
$this->message->response = $body;
4448

4549
// validate response
46-
if (@$body['status'] !== 'OK'){
50+
if (@$body['status'] !== 'OK') {
4751
throw new ResponseErrorException([
48-
'message' => $this->getStatusCodeMessage(@$body['code']),
52+
'message' => $this->getStatusCodeMessage(@$body['code']),
4953
'response' => $body,
5054
]);
5155
$this->message->is_sent = false;
52-
}else {
56+
} else {
5357
$this->message->is_sent = true;
5458
}
5559

5660
return $this->message;
5761
}
5862

59-
private function sendPatternMessage(){
60-
if (count($this->message->recipients) > 1){
63+
private function sendPatternMessage()
64+
{
65+
if (count($this->message->recipients) > 1) {
6166
throw new DriverException('امکان ارسال پترن بطور همزمان به چندین شماره در آیپی پنل پشتیبانی نمیشود');
6267
}
68+
6369
return $this->client->request('POST', $this->settings['SEND_PATTERN_API'], [
6470
'json' => [
65-
'originator' => $this->message->originator,
66-
'recipient' => $this->message->recipients[0],
71+
'originator' => $this->message->originator,
72+
'recipient' => $this->message->recipients[0],
6773
'pattern_code' => @$this->settings['patterns'][@$this->message->data['pattern_id']]['pattern_code'],
68-
'values' => array_merge((array)@$this->settings['patterns'][@$this->message->data['pattern_id']]['values'],(array)@$this->message->data['values']),
74+
'values' => array_merge((array) @$this->settings['patterns'][@$this->message->data['pattern_id']]['values'], (array) @$this->message->data['values']),
6975
],
7076
'headers' => [
71-
"Accept" => "application/json",
77+
'Accept' => 'application/json',
7278
'Authorization' => "AccessKey {$this->settings['key']}",
7379
],
74-
"http_errors" => false,
80+
'http_errors' => false,
7581
]);
7682
}
7783

78-
private function sendTextMessage(){
84+
private function sendTextMessage()
85+
{
7986
return $this->client->request('POST', $this->settings['SEND_MESSAGE_API'], [
8087
'json' => [
8188
'originator' => $this->message->originator,
8289
'recipients' => $this->message->recipients,
83-
'message' => $this->message->data['text'],
90+
'message' => $this->message->data['text'],
8491
],
8592
'headers' => [
86-
"Accept" => "application/json",
93+
'Accept' => 'application/json',
8794
'Authorization' => "AccessKey {$this->settings['key']}",
8895
],
89-
"http_errors" => false,
96+
'http_errors' => false,
9097
]);
9198
}
9299

93-
private function getStatusCodeMessage($statusCode){
100+
private function getStatusCodeMessage($statusCode)
101+
{
94102
$translations = [
95-
400 => 'خطایی رخ داد',
96-
401 => 'احراز هویت با شکست مواجه شد',
97-
422 => 'برخی از ورودی ها صحیح نیست',
103+
400 => 'خطایی رخ داد',
104+
401 => 'احراز هویت با شکست مواجه شد',
105+
422 => 'برخی از ورودی ها صحیح نیست',
98106
10023 => 'شماره ارسال کننده یافت نشد',
99107
10004 => 'شماره ارسال کننده متعلق به شما نیست',
100108
10015 => 'پارامتر های پترن صحیح نیست',
101109
];
102-
if (in_array($statusCode, array_keys($translations))){
110+
if (in_array($statusCode, array_keys($translations))) {
103111
return $translations[$statusCode];
104-
}else {
112+
} else {
105113
return 'خطای ناشناخته';
106114
}
107115
}
108-
}
116+
}

src/Exceptions/DriverException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ class DriverException extends \Exception
66
{
77
public function __construct($message, $code = 0, \Exception $previous = null)
88
{
9-
if (is_null($message)){
9+
if (is_null($message)) {
1010
$message = 'unknown error happened';
1111
}
12-
if (is_array($message)){
12+
if (is_array($message)) {
1313
$text = '';
14-
foreach ($message as $key => $value){
15-
if (!empty($text)){
14+
foreach ($message as $key => $value) {
15+
if (!empty($text)) {
1616
$text .= ' | ';
1717
}
1818
if (is_array($value)) {
1919
$text .= json_encode($value);
20-
}else {
20+
} else {
2121
$text .= $value;
2222
}
2323
}
2424
$message = $text;
2525
}
2626
parent::__construct($message, $code, $previous);
2727
}
28-
}
28+
}

src/Exceptions/MessageException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ class MessageException extends \Exception
66
{
77
public function __construct($message, $code = 0, \Exception $previous = null)
88
{
9-
if (is_null($message)){
9+
if (is_null($message)) {
1010
$message = 'unknown error happened';
1111
}
12-
if (is_array($message)){
12+
if (is_array($message)) {
1313
$text = '';
14-
foreach ($message as $key => $value){
15-
if (!empty($text)){
14+
foreach ($message as $key => $value) {
15+
if (!empty($text)) {
1616
$text .= ' | ';
1717
}
1818
if (is_array($value)) {
1919
$text .= json_encode($value);
20-
}else {
20+
} else {
2121
$text .= $value;
2222
}
2323
}
2424
$message = $text;
2525
}
2626
parent::__construct($message, $code, $previous);
2727
}
28-
}
28+
}

src/Exceptions/ResponseErrorException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ class ResponseErrorException extends \Exception
66
{
77
public function __construct($message, $code = 0, \Exception $previous = null)
88
{
9-
if (is_null($message)){
9+
if (is_null($message)) {
1010
$message = 'unknown error happened';
1111
}
12-
if (is_array($message)){
12+
if (is_array($message)) {
1313
$text = '';
14-
foreach ($message as $key => $value){
15-
if (!empty($text)){
14+
foreach ($message as $key => $value) {
15+
if (!empty($text)) {
1616
$text .= ' | ';
1717
}
1818
if (is_array($value)) {
1919
$text .= json_encode($value);
20-
}else {
20+
} else {
2121
$text .= $value;
2222
}
2323
}
2424
$message = $text;
2525
}
2626
parent::__construct($message, $code, $previous);
2727
}
28-
}
28+
}

src/Facade/SendSMS.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8-
* Class SendSMS
9-
*
10-
* @package Metti\LaravelSms\Facade
8+
* Class SendSMS.
119
*/
1210
class SendSMS extends Facade
1311
{

src/LaravelSMSServiceProvider.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Metti\LaravelSms;
34

45
use Illuminate\Support\ServiceProvider;
@@ -9,7 +10,8 @@ class LaravelSMSServiceProvider extends ServiceProvider
910
* @return void
1011
* @description publish configurations
1112
*/
12-
public function boot(){
13+
public function boot()
14+
{
1315
$this->publishes(
1416
[
1517
SendSMS::getDefaultConfigPath() => config_path('sms.php'),
@@ -18,7 +20,8 @@ public function boot(){
1820
);
1921
}
2022

21-
public function register(){
23+
public function register()
24+
{
2225
//
2326
}
24-
}
27+
}

0 commit comments

Comments
 (0)