'345d65ddcd3df70d', '_token' => '6965268557309513', 'type' => '60', ); // 快乐论文左侧导航“开放平台”添加请求IP白名单8.154.43.224 // 设置要访问的URL curl_setopt($ch, CURLOPT_URL, "http://{$domain}/get_turnitin_account"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 设置CURLOPT_RESOLVE参数 // 格式:域名:端口:IP地址 //curl_setopt($ch, CURLOPT_RESOLVE, ["{$domain}:443:{$ip}"]); curl_setopt($ch, CURLOPT_RESOLVE, ["{$domain}:80:{$ip}"]); // HTTPS相关设置 //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 正常验证主机名 // 传get参数 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); // 如果需要设置SNI(服务器名称指示) curl_setopt($ch, CURLOPT_SSLKEY, "{$domain}"); // 执行请求 $response = curl_exec($ch); print_r($response); if (curl_errno($ch)) { //echo 'cURL错误: ' . curl_error($ch); return false; } else { // $info = curl_getinfo($ch); // echo "实际连接IP: " . $info['primary_ip'] . "\n"; // echo "HTTP状态码: " . $info['http_code'] . "\n"; $res = json_decode($response, true); if (!$res['status']) return false; $list = $res['data']; return $list; } curl_close($ch); } /** * 检查crosscheck账号cookie是否有效 * @return bool */ public function islogin() { $curl_headers = [ 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'accept-language: zh-CN,zh;q=0.9,ar;q=0.8', 'cache-control: max-age=0', 'priority: u=0, i', 'sec-ch-ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"', 'sec-ch-ua-mobile: ?0', 'sec-ch-ua-platform: "Windows"', 'sec-fetch-dest: document', 'sec-fetch-mode: navigate', 'sec-fetch-site: none', 'sec-fetch-user: ?1', 'upgrade-insecure-requests: 1', 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36' ]; $url = 'https://external-production.au.turnitin.com/sms-namespace/sms/sms-serviceName/admin-console-server/sessions'; $jsonres = $this->requestUrlGet($url,[],$curl_headers); // {"success":false,"status":401,"reason":"Failed to provide authorization token","message":"AdminException.AdminException"} // {"success":true} //var_dump($jsonres); $res = json_decode($jsonres, true); //print_r($res); if ($res['success'] != true) return false; return true; } /** * curl GET 请求 * @param string $url * @param array $data * @param array $headers * @param number $timeout */ private function requestUrlGet($url, $data=array(), $headers=array(), $timeout=100) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, false); $ssl = substr($url, 0, 8) == 'https://' ? true : false; if ($ssl) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_HEADER, false); if(!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); $result = curl_exec($ch); curl_close($ch); if ($result !== false) return $result; return false; } /** * curl POST请求 * @param string $url * @param array $data * @param array $headers * @param number $timeout */ private function requestUrlPost($url, $data, $headers=array(), $timeout=300) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $ssl = substr($url, 0, 8) == 'https://' ? true : false; if ($ssl) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 } //if($this->part_cookie) curl_setopt($ch, CURLOPT_COOKIE, $this->part_cookie); if ($this->cookie_path) { curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path); } curl_setopt($ch, CURLOPT_HEADER, true); if(!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_NOBODY, false); $result = curl_exec($ch); curl_close($ch); if (file_exists($this->cookie_path)) { chown($this->cookie_path, 'nobody'); chgrp($this->cookie_path, 'nobody'); } if ($result !== false) return $result; return false; } }