22
33namespace Tartan \IranianSms \Adapter ;
44
5- use Tartan \IranianSms \Exception ;
6-
75class Slack extends AdapterAbstract implements AdapterInterface
86{
97 public $ url ;
@@ -21,19 +19,25 @@ public function send(string $number, string $message)
2119 {
2220 $ number = $ this ->filterNumber ($ number );
2321
24- $ data = json_encode (['text ' => "To: $ number - Message: $ message " ]);
22+ $ jsonData = json_encode (['text ' => "To: $ number - Message: $ message " ]);
2523
26- $ ch = curl_init ($ this ->url );
27- curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "POST " );
28- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ data );
29- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
30- curl_setopt ($ ch , CURLOPT_HEADER , array ('Content-Type: application/json ' ));
31- $ data = curl_exec ($ ch );
24+ $ curl = $ this ->getCurl ();
25+ $ curl ->addHeader ('Content-Type ' , 'application/json ' );
3226
33- if (curl_errno ($ ch )) {
34- throw new Exception (curl_error ($ ch ));
35- }
27+ $ curl ->rawPost ($ this ->url , $ jsonData );
28+ }
29+
30+ public function Verify (string $ number , int $ type , string $ template , ...$ args )
31+ {
32+ $ number = $ this ->filterNumber ($ number );
33+
34+ $ jsonData = json_encode ([
35+ 'text ' => "To: {$ number } - type: {$ type } \n template: {$ template } \n OTP: $ args [0 ]"
36+ ]);
37+
38+ $ curl = $ this ->getCurl ();
39+ $ curl ->addHeader ('Content-Type ' , 'application/json ' );
3640
37- return $ data ;
41+ $ curl -> rawPost ( $ this -> url , $ jsonData ) ;
3842 }
3943}
0 commit comments