forked from jumper423/yii2-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmsSimple.php
More file actions
76 lines (64 loc) · 1.45 KB
/
SmsSimple.php
File metadata and controls
76 lines (64 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace bongrun\sms;
use bongrun\sms\instances\SmsAccessInstance;
class SmsSimple
{
/** @var Sms */
private $sms;
private $status = false;
private $code;
/**
* SmsApi constructor.
*
* @param SmsAccessInstance[] $services
* @param int $site
*/
public function __construct($services, $site = null)
{
$servicesData = [];
foreach ($services as $service) {
$servicesData[] = [
'class' => $service->getClass(),
'apiKey' => $service->getKey(),
];
}
$this->sms = new Sms($servicesData, $site);
}
public function getNumber()
{
$number = $this->sms->getNumber();
$this->sms->setStatus(Sms::STATUS_READY);
return $number;
}
public function code()
{
list($this->status, $this->code) = $this->sms->getCode();
return $this;
}
public function isResult()
{
return !!$this->status;
}
public function isError()
{
return !$this->status;
}
public function getCode()
{
return $this->code;
}
public function invalid()
{
$this->sms->setStatus(Sms::STATUS_INVALID);
return $this;
}
public function used()
{
$this->sms->setStatus(Sms::STATUS_USED);
return $this;
}
public function getBalance()
{
return $this->sms->getBalance();
}
}