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 |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
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 | |||
109 | return $response; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @param string $reciver_number |
||
114 | * @param string $reciver_code |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | public function checkAuthCode($reciver_number, $reciver_code) |
||
119 | { |
||
120 | $params = [ |
||
121 | 'UserName' => $this->user_name, |
||
122 | 'Password' => $this->password, |
||
123 | 'Mobile' => $reciver_number, |
||
124 | 'Code' => $reciver_code, |
||
125 | ]; |
||
126 | |||
127 | $response = $this->client->request('POST', $this->url_check_auth_code, ['form_params' => $params]); |
||
128 | $response = \json_decode((string) $response->getBody(), true); |
||
129 | |||
130 | return $response; |
||
131 | } |
||
132 | } |
||
133 |