Skip to content

Commit 73451e9

Browse files
committed
add verify method to Log adapter
1 parent a90bb92 commit 73451e9

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"ext-json": "*",
2323
"illuminate/support": ">=5.0.0",
2424
"ghasedak/php":"^1.0",
25-
"kavenegar/php": "^1.2"
25+
"kavenegar/php": "^1.2",
26+
"samuraee/easycurl": "^1.0"
2627
}
2728
}

src/Adapter/Slack.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Tartan\IranianSms\Adapter;
44

5-
use Tartan\IranianSms\Exception;
6-
75
class 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
}

src/Adapter/SmsLog.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ public function send(string $number, string $message)
1414

1515
Log::debug($contents, ['tag' => 'sms']);
1616
}
17+
18+
public function Verify(string $number, int $type, string $template, ...$args)
19+
{
20+
$number = $this->filterNumber($number);
21+
22+
Log::debug("OTP Number: {$number} \n type: {$type} \n template: {$template} \n", $args);
23+
}
1724
}

0 commit comments

Comments
 (0)