|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Babel\Submit; |
|
3
|
|
|
|
|
4
|
|
|
use App\Models\SubmissionModel; |
|
5
|
|
|
|
|
6
|
|
|
class Curl |
|
7
|
|
|
{ |
|
8
|
|
|
public function __construct() |
|
9
|
|
|
{ |
|
10
|
|
|
// |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
protected function login($all_data) |
|
14
|
|
|
{ |
|
15
|
|
|
if(isset($all_data["url"])) $url = $all_data["url"]; else throw new Exception("url is not exist in all_data"); |
|
|
|
|
|
|
16
|
|
|
if(isset($all_data["data"])) $data = $all_data["data"]; else throw new Exception("data is not exist in all_data"); |
|
17
|
|
|
if(isset($all_data["oj"])) $oj = $all_data["oj"]; else throw new Exception("oj is not exist in all_data"); |
|
18
|
|
|
if(isset($all_data["ret"])) $ret = $all_data["ret"]; else $ret = 'false'; |
|
19
|
|
|
if(isset($all_data["handle"])) $handle = $all_data["handle"]; else $handle = "default"; |
|
20
|
|
|
|
|
21
|
|
|
$datapost=curl_init(); |
|
22
|
|
|
$headers=array("Expect:"); |
|
23
|
|
|
|
|
24
|
|
|
curl_setopt($datapost, CURLOPT_CAINFO, dirname(__FILE__)."/../Cookies/cacert.pem"); |
|
|
|
|
|
|
25
|
|
|
curl_setopt($datapost, CURLOPT_URL, $url); |
|
26
|
|
|
curl_setopt($datapost, CURLOPT_HEADER, true); // |
|
27
|
|
|
curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); // |
|
28
|
|
|
curl_setopt($datapost, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"); |
|
29
|
|
|
curl_setopt($datapost, CURLOPT_POST, true); |
|
30
|
|
|
|
|
31
|
|
|
curl_setopt($datapost, CURLOPT_RETURNTRANSFER, $ret); |
|
32
|
|
|
curl_setopt($datapost, CURLOPT_FOLLOWLOCATION, true); |
|
33
|
|
|
|
|
34
|
|
|
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); |
|
35
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
|
36
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEJAR, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
|
37
|
|
|
ob_start(); |
|
38
|
|
|
$response=curl_exec($datapost); |
|
|
|
|
|
|
39
|
|
|
if (curl_errno($datapost)) { |
|
|
|
|
|
|
40
|
|
|
die(curl_error($datapost)); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
ob_end_clean(); |
|
43
|
|
|
curl_close($datapost); |
|
|
|
|
|
|
44
|
|
|
unset($datapost); |
|
45
|
|
|
return $response; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function grab_page($all_data) |
|
49
|
|
|
{ |
|
50
|
|
|
if(isset($all_data["site"])) $site = $all_data["site"]; else throw new Exception("site is not exist in all_data"); |
|
51
|
|
|
if(isset($all_data["oj"])) $oj = $all_data["oj"]; else throw new Exception("oj is not exist in all_data"); |
|
52
|
|
|
if(isset($all_data["headers"])) $headers = $all_data["headers"]; else $headers = []; |
|
53
|
|
|
if(isset($all_data["handle"])) $handle = $all_data["handle"]; else $handle = "default"; |
|
54
|
|
|
|
|
55
|
|
|
$ch=curl_init(); |
|
56
|
|
|
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/../Cookies/cacert.pem"); |
|
|
|
|
|
|
57
|
|
|
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
58
|
|
|
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
|
59
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
60
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"); |
|
61
|
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
|
62
|
|
|
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
|
63
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
64
|
|
|
curl_setopt($ch, CURLOPT_URL, $site); |
|
65
|
|
|
ob_start(); |
|
66
|
|
|
$response=curl_exec($ch); |
|
|
|
|
|
|
67
|
|
|
if (curl_errno($ch)) { |
|
|
|
|
|
|
68
|
|
|
die(curl_error($ch)); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
ob_end_clean(); |
|
71
|
|
|
curl_close($ch); |
|
|
|
|
|
|
72
|
|
|
return $response; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function post_data($all_data) |
|
76
|
|
|
{ |
|
77
|
|
|
if(isset($all_data["site"])) $site = $all_data["site"]; else throw new Exception("site is not exist in all_data"); |
|
78
|
|
|
if(isset($all_data["data"])) $data = $all_data["data"]; else throw new Exception("data is not exist in all_data"); |
|
79
|
|
|
if(isset($all_data["oj"])) $oj = $all_data["oj"]; else throw new Exception("oj is not exist in all_data"); |
|
80
|
|
|
if(isset($all_data["ret"])) $ret = $all_data["ret"]; else $ret = false; |
|
81
|
|
|
if(isset($all_data["follow"])) $follow = $all_data["follow"]; else $follow = true; |
|
82
|
|
|
if(isset($all_data["returnHeader"])) $returnHeader = $all_data["returnHeader"]; else $returnHeader = true; |
|
83
|
|
|
if(isset($all_data["postJson"])) $postJson = $all_data["postJson"]; else $postJson = false; |
|
84
|
|
|
if(isset($all_data["extraHeaders"])) $extraHeaders = $all_data["extraHeaders"]; else $extraHeaders = []; |
|
85
|
|
|
if(isset($all_data["handle"])) $handle = $all_data["handle"]; else $handle = "default"; |
|
86
|
|
|
|
|
87
|
|
|
$datapost=curl_init(); |
|
88
|
|
|
$headers=array("Expect:"); |
|
89
|
|
|
if ($postJson) { |
|
90
|
|
|
$data=$data ? json_encode($data) : '{}'; |
|
91
|
|
|
array_push($headers, 'Content-Type: application/json', 'Content-Length: '.strlen($data)); |
|
92
|
|
|
} |
|
93
|
|
|
curl_setopt($datapost, CURLOPT_CAINFO, dirname(__FILE__)."/../Cookies/cacert.pem"); |
|
|
|
|
|
|
94
|
|
|
curl_setopt($datapost, CURLOPT_URL, $site); |
|
95
|
|
|
curl_setopt($datapost, CURLOPT_HEADER, $returnHeader); |
|
96
|
|
|
curl_setopt($datapost, CURLOPT_HTTPHEADER, array_merge($headers, $extraHeaders)); |
|
97
|
|
|
curl_setopt($datapost, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"); |
|
98
|
|
|
curl_setopt($datapost, CURLOPT_POST, true); |
|
99
|
|
|
|
|
100
|
|
|
curl_setopt($datapost, CURLOPT_RETURNTRANSFER, $ret); |
|
101
|
|
|
curl_setopt($datapost, CURLOPT_FOLLOWLOCATION, $follow); |
|
102
|
|
|
|
|
103
|
|
|
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); |
|
104
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
|
105
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEJAR, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
|
106
|
|
|
ob_start(); |
|
107
|
|
|
$response=curl_exec($datapost); |
|
|
|
|
|
|
108
|
|
|
if (curl_errno($datapost)) { |
|
|
|
|
|
|
109
|
|
|
die(curl_error($datapost)); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
ob_end_clean(); |
|
112
|
|
|
curl_close($datapost); |
|
|
|
|
|
|
113
|
|
|
unset($datapost); |
|
114
|
|
|
return $response; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|