1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jaby\Sms\Drivers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Http; |
6
|
|
|
use Jaby\Sms\SmsInterface; |
7
|
|
|
|
8
|
|
|
class kavenegar implements SmsInterface |
9
|
|
|
{ |
10
|
|
|
protected $drive = 'kavenegar'; |
11
|
|
|
|
12
|
|
|
protected $method; |
13
|
|
|
|
14
|
|
|
protected $username; |
15
|
|
|
|
16
|
|
|
protected $password; |
17
|
|
|
|
18
|
|
|
protected $from; |
19
|
|
|
|
20
|
|
|
protected $pattern_code; |
21
|
|
|
|
22
|
|
|
protected $to; |
23
|
|
|
|
24
|
|
|
protected $input_data; |
25
|
|
|
|
26
|
|
|
protected $url; |
27
|
|
|
|
28
|
|
|
protected $numbers; |
29
|
|
|
|
30
|
|
|
protected $data; |
31
|
|
|
|
32
|
|
|
protected $text; |
33
|
|
|
|
34
|
|
|
public $token; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* farazsms constructor. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
$this->username = config('sms.drivers.'.$this->drive.'.username'); |
47
|
|
|
$this->password = config('sms.drivers.'.$this->drive.'.password'); |
48
|
|
|
$this->token = config('sms.drivers.'.$this->drive.'.token'); |
49
|
|
|
$this->from = config('sms.drivers.'.$this->drive.'.from'); |
50
|
|
|
$this->url = config('sms.drivers.'.$this->drive.'.urlPattern'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool|mixed|string |
55
|
|
|
*/ |
56
|
|
|
public function send() |
57
|
|
|
{ |
58
|
|
|
if ($this->method == 'pattern') |
59
|
|
|
$res = $this->sendPattern(); |
60
|
|
|
else |
61
|
|
|
$res = $this->message($this->text); |
62
|
|
|
return $res; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $text |
67
|
|
|
* @return $this|mixed |
68
|
|
|
*/ |
69
|
|
|
public function text($text) |
70
|
|
|
{ |
71
|
|
|
$this->text = $text; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param null $pattern_code |
|
|
|
|
78
|
|
|
* @return $this|mixed |
79
|
|
|
*/ |
80
|
|
|
public function pattern($pattern_code = null) |
81
|
|
|
{ |
82
|
|
|
$this->method = 'pattern'; |
83
|
|
|
if ($pattern_code) |
|
|
|
|
84
|
|
|
$this->pattern_code = $pattern_code; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param array $data |
90
|
|
|
* @return $this|mixed |
91
|
|
|
*/ |
92
|
|
|
public function data(array $data) |
93
|
|
|
{ |
94
|
|
|
$this->data = $data; |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $from |
101
|
|
|
* @return $this|mixed |
102
|
|
|
*/ |
103
|
|
|
public function from($from) |
104
|
|
|
{ |
105
|
|
|
$this->from = $from; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param array $numbers |
112
|
|
|
* @return $this|mixed |
113
|
|
|
*/ |
114
|
|
|
public function to(array $numbers) |
115
|
|
|
{ |
116
|
|
|
$this->numbers = $numbers; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return bool|mixed|string |
123
|
|
|
*/ |
124
|
|
|
public function sendPattern() |
125
|
|
|
{ |
126
|
|
|
$token = $this->token ?? $this->password; |
127
|
|
|
$url = $this->url.'/'.$token.'/verify/lookup.json'; |
128
|
|
|
$url .= '?receptor='.$this->numbers[0]; |
129
|
|
|
foreach ($this->data as $patternKey => $patternValue ){ |
130
|
|
|
$url .= '&'.$patternKey.'='.$patternValue; |
131
|
|
|
} |
132
|
|
|
$url .= '&template='.$this->pattern_code; |
133
|
|
|
$response = Http::get($url)->body(); |
134
|
|
|
return $response; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param $text |
139
|
|
|
* @return mixed |
140
|
|
|
*/ |
141
|
|
|
public function message($text) |
142
|
|
|
{ |
143
|
|
|
$token = $this->token ?? $this->password; |
144
|
|
|
$url = $this->url.'/'.$token.'/sms/send.json'; |
145
|
|
|
$url .= '?receptor='.implode(",",$this->numbers); |
146
|
|
|
$url .= '&sender='.$this->from; |
147
|
|
|
$url .= '&message='.$text; |
148
|
|
|
$response = Http::get($url)->body(); |
149
|
|
|
return $response; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|