1 | <?php |
||
5 | abstract class Agent |
||
6 | { |
||
7 | const SUCCESS = 'success'; |
||
8 | const INFO = 'info'; |
||
9 | const CODE = 'code'; |
||
10 | |||
11 | /** |
||
12 | * The configuration information of agent. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $config = []; |
||
17 | |||
18 | /** |
||
19 | * The result data. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $result = [ |
||
24 | self::SUCCESS => false, |
||
25 | self::INFO => null, |
||
26 | self::CODE => 0, |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Constructor. |
||
31 | * |
||
32 | * @param array $config |
||
33 | */ |
||
34 | 30 | public function __construct(array $config = []) |
|
35 | { |
||
36 | 30 | $this->config($config); |
|
37 | 30 | } |
|
38 | |||
39 | /** |
||
40 | * Get or set the configuration information of agent. |
||
41 | * |
||
42 | * @param mixed $key |
||
43 | * @param mixed $value |
||
44 | * @param bool $override |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 30 | public function config($key = null, $value = null, $override = false) |
|
56 | |||
57 | /** |
||
58 | * SMS send process. |
||
59 | * |
||
60 | * @param $to |
||
61 | * @param $content |
||
62 | * @param $tempId |
||
63 | * @param array $tempData |
||
64 | */ |
||
65 | abstract public function sendSms($to, $content, $tempId, array $tempData); |
||
66 | |||
67 | /** |
||
68 | * Content SMS send process. |
||
69 | * |
||
70 | * @param $to |
||
71 | * @param $content |
||
72 | */ |
||
73 | abstract public function sendContentSms($to, $content); |
||
74 | |||
75 | /** |
||
76 | * Template SMS send process. |
||
77 | * |
||
78 | * @param $to |
||
79 | * @param $tempId |
||
80 | * @param array $tempData |
||
81 | */ |
||
82 | abstract public function sendTemplateSms($to, $tempId, array $tempData); |
||
83 | |||
84 | /** |
||
85 | * Voice verify send process. |
||
86 | * |
||
87 | * @param $to |
||
88 | * @param $code |
||
89 | * @param $tempId |
||
90 | * @param array $tempData |
||
91 | */ |
||
92 | abstract public function voiceVerify($to, $code, $tempId, array $tempData); |
||
93 | |||
94 | /** |
||
95 | * Http post request. |
||
96 | * |
||
97 | * @codeCoverageIgnore |
||
98 | * |
||
99 | * @param $url |
||
100 | * @param array $query |
||
101 | * @param $port |
||
102 | * |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public static function sockPost($url, $query, $port = 80) |
||
106 | { |
||
107 | $data = ''; |
||
108 | $info = parse_url($url); |
||
109 | $fp = fsockopen($info['host'], $port, $errno, $errstr, 30); |
||
110 | if (!$fp) { |
||
111 | return $data; |
||
112 | } |
||
113 | $head = 'POST ' . $info['path'] . " HTTP/1.0\r\n"; |
||
114 | $head .= 'Host: ' . $info['host'] . "\r\n"; |
||
115 | $head .= 'Referer: http://' . $info['host'] . $info['path'] . "\r\n"; |
||
116 | $head .= "Content-type: application/x-www-form-urlencoded\r\n"; |
||
117 | $head .= 'Content-Length: ' . strlen(trim($query)) . "\r\n"; |
||
118 | $head .= "\r\n"; |
||
119 | $head .= trim($query); |
||
120 | $write = fwrite($fp, $head); |
||
|
|||
121 | $header = ''; |
||
122 | while ($str = trim(fgets($fp, 4096))) { |
||
123 | $header .= $str; |
||
124 | } |
||
125 | while (!feof($fp)) { |
||
126 | $data .= fgets($fp, 4096); |
||
127 | } |
||
128 | |||
129 | return $data; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * cURl |
||
134 | * |
||
135 | * @codeCoverageIgnore |
||
136 | * |
||
137 | * @param string $url [请求的URL地址] |
||
138 | * @param array $params [请求的参数] |
||
139 | * @param int|bool $isPost [是否采用POST形式] |
||
140 | * |
||
141 | * @return array ['request', 'response'] |
||
142 | * request:是否请求成功 |
||
143 | * response:响应数据 |
||
144 | */ |
||
145 | public static function curl($url, array $params = [], $isPost = false) |
||
171 | |||
172 | /** |
||
173 | * Set/get result data. |
||
174 | * |
||
175 | * @param $name |
||
176 | * @param $value |
||
177 | * |
||
178 | * @return mixed |
||
179 | */ |
||
180 | 36 | public function result($name = null, $value = null) |
|
192 | |||
193 | /** |
||
194 | * Overload object properties. |
||
195 | * |
||
196 | * @param $name |
||
197 | * |
||
198 | * @return mixed |
||
199 | */ |
||
200 | 12 | public function __get($name) |
|
201 | { |
||
202 | 12 | return $this->config($name); |
|
203 | } |
||
204 | |||
205 | /** |
||
206 | * When using isset() or empty() on inaccessible object properties, |
||
207 | * the __isset() overloading method will be called. |
||
208 | * |
||
209 | * @param $name |
||
210 | * |
||
211 | * @return bool |
||
212 | */ |
||
213 | 3 | public function __isset($name) |
|
217 | } |
||
218 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.