|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Babel\Judger; |
|
3
|
|
|
|
|
4
|
|
|
use App\Models\SubmissionModel; |
|
5
|
|
|
|
|
6
|
|
|
class Curl |
|
7
|
|
|
{ |
|
8
|
|
|
public function __construct() |
|
9
|
|
|
{ |
|
10
|
|
|
// |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
protected function login($url, $data, $oj, $ret='false', $handle="default") |
|
14
|
|
|
{ |
|
15
|
|
|
$datapost=curl_init(); |
|
16
|
|
|
$headers=array("Expect:"); |
|
17
|
|
|
|
|
18
|
|
|
curl_setopt($datapost, CURLOPT_CAINFO, dirname(__FILE__)."/cookie/cacert.pem"); |
|
|
|
|
|
|
19
|
|
|
curl_setopt($datapost, CURLOPT_URL, $url); |
|
20
|
|
|
curl_setopt($datapost, CURLOPT_HEADER, true); // |
|
21
|
|
|
curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); // |
|
22
|
|
|
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"); |
|
23
|
|
|
curl_setopt($datapost, CURLOPT_POST, true); |
|
24
|
|
|
|
|
25
|
|
|
curl_setopt($datapost, CURLOPT_RETURNTRANSFER, $ret); |
|
26
|
|
|
curl_setopt($datapost, CURLOPT_FOLLOWLOCATION, true); |
|
27
|
|
|
|
|
28
|
|
|
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); |
|
29
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__)."/cookie/{$oj}_{$handle}_cookie.txt"); |
|
30
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEJAR, dirname(__FILE__)."/cookie/{$oj}_{$handle}_cookie.txt"); |
|
31
|
|
|
ob_start(); |
|
32
|
|
|
$response=curl_exec($datapost); |
|
|
|
|
|
|
33
|
|
|
if (curl_errno($datapost)) { |
|
|
|
|
|
|
34
|
|
|
die(curl_error($datapost)); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
ob_end_clean(); |
|
37
|
|
|
curl_close($datapost); |
|
|
|
|
|
|
38
|
|
|
unset($datapost); |
|
39
|
|
|
return $response; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function grab_page($site, $oj, $headers=[], $handle="default") |
|
43
|
|
|
{ |
|
44
|
|
|
$ch=curl_init(); |
|
45
|
|
|
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cookie/cacert.pem"); |
|
|
|
|
|
|
46
|
|
|
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
47
|
|
|
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
|
48
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
49
|
|
|
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"); |
|
50
|
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/cookie/{$oj}_{$handle}_cookie.txt"); |
|
51
|
|
|
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/cookie/{$oj}_{$handle}_cookie.txt"); |
|
52
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
53
|
|
|
curl_setopt($ch, CURLOPT_URL, $site); |
|
54
|
|
|
ob_start(); |
|
55
|
|
|
$response=curl_exec($ch); |
|
|
|
|
|
|
56
|
|
|
if (curl_errno($ch)) { |
|
|
|
|
|
|
57
|
|
|
die(curl_error($ch)); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
ob_end_clean(); |
|
60
|
|
|
curl_close($ch); |
|
|
|
|
|
|
61
|
|
|
return $response; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function post_data($site, $data, $oj, $ret=false, $follow=true, $returnHeader=true, $postJson=false, $extraHeaders=[], $handle="default") |
|
65
|
|
|
{ |
|
66
|
|
|
$datapost=curl_init(); |
|
67
|
|
|
$headers=array("Expect:"); |
|
68
|
|
|
if ($postJson) { |
|
69
|
|
|
$data=$data ? json_encode($data) : '{}'; |
|
70
|
|
|
array_push($headers, 'Content-Type: application/json', 'Content-Length: '.strlen($data)); |
|
71
|
|
|
} |
|
72
|
|
|
curl_setopt($datapost, CURLOPT_CAINFO, dirname(__FILE__)."/cookie/cacert.pem"); |
|
|
|
|
|
|
73
|
|
|
curl_setopt($datapost, CURLOPT_URL, $site); |
|
74
|
|
|
curl_setopt($datapost, CURLOPT_HEADER, $returnHeader); |
|
75
|
|
|
curl_setopt($datapost, CURLOPT_HTTPHEADER, array_merge($headers, $extraHeaders)); |
|
76
|
|
|
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"); |
|
77
|
|
|
curl_setopt($datapost, CURLOPT_POST, true); |
|
78
|
|
|
|
|
79
|
|
|
curl_setopt($datapost, CURLOPT_RETURNTRANSFER, $ret); |
|
80
|
|
|
curl_setopt($datapost, CURLOPT_FOLLOWLOCATION, $follow); |
|
81
|
|
|
|
|
82
|
|
|
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); |
|
83
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__)."/cookie/{$oj}_{$handle}_cookie.txt"); |
|
84
|
|
|
curl_setopt($datapost, CURLOPT_COOKIEJAR, dirname(__FILE__)."/cookie/{$oj}_{$handle}_cookie.txt"); |
|
85
|
|
|
ob_start(); |
|
86
|
|
|
$response=curl_exec($datapost); |
|
|
|
|
|
|
87
|
|
|
if (curl_errno($datapost)) { |
|
|
|
|
|
|
88
|
|
|
die(curl_error($datapost)); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
ob_end_clean(); |
|
91
|
|
|
curl_close($datapost); |
|
|
|
|
|
|
92
|
|
|
unset($datapost); |
|
93
|
|
|
return $response; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|