Passed
Push — master ( aac310...ebc440 )
by Farhad
08:07
created

Sms::sendAutoAuthCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 13
rs 10
c 0
b 0
f 0
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_auth_code;
17
18
    /** @var string */
19
    protected $url_check_auth_code;
20
21
    /** @var string */
22
    protected $url_send_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_auth_code = 'https://smspanel.Trez.ir/AutoSendCode.ashx';
47
        $this->url_check_auth_code = 'https://smspanel.Trez.ir/CheckSendCode.ashx';
48
        $this->url_send_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|string $sender_texts
82
     *
83
     * @return string
84
     */
85
    public function sendAutoAuthCode($reciver_number, $sender_text = null)
86
    {
87
        $params = [
88
            'UserName' => $this->user_name,
89
            'Password' => $this->password,
90
            'Mobile'   => $reciver_number,
91
            'Footer'   => $sender_text,
92
        ];
93
94
        $response = $this->client->request('POST', $this->url_send_auth_code, ['form_params' => $params]);
95
        $response = \json_decode((string) $response->getBody(), true);
96
97
        return $response;
98
    }
99
100
    /**
101
     * @param string $reciver_number
102
     * @param string $reciver_code
103
     *
104
     * @return string
105
     */
106
    public function checkAutoAuthCode($reciver_number, $reciver_code)
107
    {
108
        $params = [
109
            'UserName' => $this->user_name,
110
            'Password' => $this->password,
111
            'Mobile'   => $reciver_number,
112
            'Code'     => $reciver_code,
113
        ];
114
115
        $response = $this->client->request('POST', $this->url_check_auth_code, ['form_params' => $params]);
116
        $response = \json_decode((string) $response->getBody(), true);
117
118
        return $response;
119
    }
120
121
    /**
122
     * @param $reciver_number
123
     * @param $text_message
124
     * @return string
125
     */
126
    public function sendAuthCode($reciver_number, $text_message)
127
    {
128
        $params = [
129
            'UserName' => $this->user_name,
130
            'Password' => $this->password,
131
            'Mobile'   => $reciver_number,
132
            'Message'  => $text_message,
133
        ];
134
        $response = $this->client->request('GET', $this->url_send_code, ['query' => $params]);
135
        $response = \json_decode((string) $response->getBody(), true);
136
137
        return $response;
138
    }
139
}
140