Conditions | 4 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 19 |
Lines | 27 |
Ratio | 96.43 % |
Changes | 0 |
1 | <?php |
||
30 | View Code Duplication | public function curl_post($url, $data, $header, $post = 1) |
|
|
|||
31 | { |
||
32 | //初始化curl |
||
33 | $ch = curl_init(); |
||
34 | //参数设置 |
||
35 | $res = curl_setopt($ch, CURLOPT_URL, $url); |
||
36 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
||
37 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
38 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
39 | curl_setopt($ch, CURLOPT_POST, $post); |
||
40 | if ($post) { |
||
41 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||
42 | } |
||
43 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
44 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
||
45 | $result = curl_exec($ch); |
||
46 | //连接失败 |
||
47 | if ($result === false) { |
||
48 | if ($this->BodyType === 'json') { |
||
49 | $result = '{"statusCode":"172001","statusMsg":"网络错误"}'; |
||
50 | } else { |
||
51 | $result = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Response><statusCode>172001</statusCode><statusMsg>网络错误</statusMsg></Response>'; |
||
52 | } |
||
53 | } |
||
54 | curl_close($ch); |
||
55 | |||
56 | return $result; |
||
57 | } |
||
58 | } |
||
59 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.