11<?php
2+
23namespace Metti \LaravelSms \Drivers \Ippanel ;
34
45use GuzzleHttp \Client ;
56use Metti \LaravelSms \Abstracts \Driver ;
67use Metti \LaravelSms \Exceptions \DriverException ;
78use 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+ }
0 commit comments