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 => '', |
||
26 | self::CODE => 0, |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Constructor. |
||
31 | * |
||
32 | * @param array $config |
||
33 | */ |
||
34 | 27 | public function __construct(array $config = []) |
|
35 | { |
||
36 | 27 | $this->config = $config; |
|
37 | 27 | } |
|
38 | |||
39 | /** |
||
40 | * SMS send process. |
||
41 | * |
||
42 | * @param $tempId |
||
43 | * @param $to |
||
44 | * @param array $tempData |
||
45 | * @param $content |
||
46 | */ |
||
47 | abstract public function sendSms($tempId, $to, array $tempData, $content); |
||
48 | |||
49 | /** |
||
50 | * Content SMS send process. |
||
51 | * |
||
52 | * @param $to |
||
53 | * @param $content |
||
54 | */ |
||
55 | abstract public function sendContentSms($to, $content); |
||
56 | |||
57 | /** |
||
58 | * Template SMS send process. |
||
59 | * |
||
60 | * @param $tempId |
||
61 | * @param $to |
||
62 | * @param array $tempData |
||
63 | */ |
||
64 | abstract public function sendTemplateSms($tempId, $to, array $tempData); |
||
65 | |||
66 | /** |
||
67 | * Voice verify send process. |
||
68 | * |
||
69 | * @param $to |
||
70 | * @param $code |
||
71 | */ |
||
72 | abstract public function voiceVerify($to, $code); |
||
73 | |||
74 | /** |
||
75 | * Http post request. |
||
76 | * |
||
77 | * @codeCoverageIgnore |
||
78 | * |
||
79 | * @param $url |
||
80 | * @param array $query |
||
81 | * @param $port |
||
82 | * |
||
83 | * @return mixed |
||
84 | */ |
||
85 | public static function sockPost($url, $query, $port = 80) |
||
86 | { |
||
87 | $data = ''; |
||
88 | $info = parse_url($url); |
||
89 | $fp = fsockopen($info['host'], $port, $errno, $errstr, 30); |
||
90 | if (!$fp) { |
||
91 | return $data; |
||
92 | } |
||
93 | $head = 'POST ' . $info['path'] . " HTTP/1.0\r\n"; |
||
94 | $head .= 'Host: ' . $info['host'] . "\r\n"; |
||
95 | $head .= 'Referer: http://' . $info['host'] . $info['path'] . "\r\n"; |
||
96 | $head .= "Content-type: application/x-www-form-urlencoded\r\n"; |
||
97 | $head .= 'Content-Length: ' . strlen(trim($query)) . "\r\n"; |
||
98 | $head .= "\r\n"; |
||
99 | $head .= trim($query); |
||
100 | $write = fwrite($fp, $head); |
||
|
|||
101 | $header = ''; |
||
102 | while ($str = trim(fgets($fp, 4096))) { |
||
103 | $header .= $str; |
||
104 | } |
||
105 | while (!feof($fp)) { |
||
106 | $data .= fgets($fp, 4096); |
||
107 | } |
||
108 | |||
109 | return $data; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * cURl |
||
114 | * |
||
115 | * @codeCoverageIgnore |
||
116 | * |
||
117 | * @param string $url [请求的URL地址] |
||
118 | * @param array $params [请求的参数] |
||
119 | * @param int|bool $isPost [是否采用POST形式] |
||
120 | * |
||
121 | * @return array ['request', 'response'] |
||
122 | * request:是否请求成功 |
||
123 | * response:响应数据 |
||
124 | */ |
||
125 | public static function curl($url, array $params = [], $isPost = false) |
||
151 | |||
152 | /** |
||
153 | * Set/get result data. |
||
154 | * |
||
155 | * @param $name |
||
156 | * @param $value |
||
157 | * |
||
158 | * @return mixed |
||
159 | */ |
||
160 | 36 | public function result($name = null, $value = null) |
|
172 | |||
173 | /** |
||
174 | * Overload object properties. |
||
175 | * |
||
176 | * @param $name |
||
177 | * |
||
178 | * @return mixed |
||
179 | */ |
||
180 | 9 | public function __get($name) |
|
186 | |||
187 | /** |
||
188 | * When using isset() or empty() on inaccessible object properties, |
||
189 | * the __isset() overloading method will be called. |
||
190 | * |
||
191 | * @param $name |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | 3 | public function __isset($name) |
|
199 | } |
||
200 |
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.