|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Trez\RayganSms; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as HttpClient; |
|
6
|
|
|
|
|
7
|
|
|
class Sms |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var HttpClient */ |
|
10
|
|
|
protected $client; |
|
11
|
|
|
|
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
protected $url_send_message; |
|
14
|
|
|
|
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
protected $url_send_auto_auth_code; |
|
17
|
|
|
|
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
protected $url_check_auth_code; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
protected $url_send_auth_code; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
protected $user_name; |
|
26
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
protected $password; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
protected $phone_number; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Sms constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $user_name |
|
37
|
|
|
* @param string $password |
|
38
|
|
|
* @param string $phone_number |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct($user_name, $password, $phone_number) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->user_name = $user_name; |
|
43
|
|
|
$this->password = $password; |
|
44
|
|
|
$this->phone_number = $phone_number; |
|
45
|
|
|
$this->url_send_message = 'https://RayganSMS.com/SendMessageWithPost.ashx'; |
|
46
|
|
|
$this->url_send_auto_auth_code = 'https://smspanel.Trez.ir/AutoSendCode.ashx'; |
|
47
|
|
|
$this->url_check_auth_code = 'https://smspanel.Trez.ir/CheckSendCode.ashx'; |
|
48
|
|
|
$this->url_send_auth_code = 'https://smspanel.Trez.ir/SendMessageWithCode.ashx'; |
|
49
|
|
|
|
|
50
|
|
|
$this->client = new HttpClient([ |
|
51
|
|
|
'timeout' => 10, |
|
52
|
|
|
'connect_timeout' => 10, |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $reciver_number |
|
58
|
|
|
* @param string $text_message |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function sendMessage($reciver_number, $text_message) |
|
63
|
|
|
{ |
|
64
|
|
|
$params = [ |
|
65
|
|
|
'UserName' => $this->user_name, |
|
66
|
|
|
'Password' => $this->password, |
|
67
|
|
|
'PhoneNumber' => $this->phone_number, |
|
68
|
|
|
'Smsclass' => '1', |
|
69
|
|
|
'RecNumber' => $reciver_number, |
|
70
|
|
|
'MessageBody' => $text_message, |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
$response = $this->client->request('POST', $this->url_send_message, ['form_params' => $params]); |
|
74
|
|
|
$response = \json_decode((string) $response->getBody(), true); |
|
75
|
|
|
|
|
76
|
|
|
return $response; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param $reciver_number |
|
81
|
|
|
* @param null $text_message |
|
|
|
|
|
|
82
|
|
|
* @param bool $autoGenerateCode |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function sendAuthCode($reciver_number, $text_message = null, $autoGenerateCode = true) |
|
87
|
|
|
{ |
|
88
|
|
|
if ($autoGenerateCode) { |
|
89
|
|
|
$params = [ |
|
90
|
|
|
'UserName' => $this->user_name, |
|
91
|
|
|
'Password' => $this->password, |
|
92
|
|
|
'Mobile' => $reciver_number, |
|
93
|
|
|
'Footer' => $text_message, |
|
94
|
|
|
]; |
|
95
|
|
|
$response = $this->client->request('POST', $this->url_send_auto_auth_code, ['form_params' => $params]); |
|
96
|
|
|
} else { |
|
97
|
|
|
$params = [ |
|
98
|
|
|
'UserName' => $this->user_name, |
|
99
|
|
|
'Password' => $this->password, |
|
100
|
|
|
'Mobile' => $reciver_number, |
|
101
|
|
|
'Message' => $text_message, |
|
102
|
|
|
]; |
|
103
|
|
|
|
|
104
|
|
|
$response = $this->client->request('GET', $this->url_send_auth_code, ['query' => $params]); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$response = \json_decode((string) $response->getBody(), true); |
|
108
|
|
|
return $response; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param string $reciver_number |
|
113
|
|
|
* @param string $reciver_code |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function checkAuthCode($reciver_number, $reciver_code) |
|
118
|
|
|
{ |
|
119
|
|
|
$params = [ |
|
120
|
|
|
'UserName' => $this->user_name, |
|
121
|
|
|
'Password' => $this->password, |
|
122
|
|
|
'Mobile' => $reciver_number, |
|
123
|
|
|
'Code' => $reciver_code, |
|
124
|
|
|
]; |
|
125
|
|
|
|
|
126
|
|
|
$response = $this->client->request('POST', $this->url_check_auth_code, ['form_params' => $params]); |
|
127
|
|
|
$response = \json_decode((string) $response->getBody(), true); |
|
128
|
|
|
|
|
129
|
|
|
return $response; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|