实现原理:
创新互联专注于邹平企业网站建设,成都响应式网站建设公司,成都做商城网站。邹平网站建设公司,为邹平等地区提供建站服务。全流程专业公司,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
通过curl工具模拟登录,然后调用相关接口发送数据进行各种操作。
需要掌握知识点:
代码示范
curl的GET操作
private function projectCollections(): array
{
$ts = microtime(true) * 1000;
$api = "http://www.****.com/json/projectCollections?status=1&username={$this->userName}&limit=1&projectID={$this->projectID}&ts=" . $ts; //API地址
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_HEADER, 0);//是否显示头信息
curl_setopt($curl, CURLOPT_COOKIEJAR, $this->cookie); //设置Cookie信息保存在指定的文件中
curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie); //发送cookie信息
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, "http://www.***.com/details/v5?id={$this->projectID}&isView=true");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36");
$json = curl_exec($curl);
curl_close($curl);
\Log::error(var_export($json, true));
return json_decode($json, true);
//{"meta":{"total":"0","start":"1","size":"0"},"data":[]}
}
//收藏
private function addCollection()
{
$api = "http://www.****.com/sjc/api/project/collection/add";
$postData = [
'id' => (string)$this->projectID,
];
$data = json_encode($postData);
$length = strlen($data);
$headers = [
//'Origin:http://www.ilab-x.com',
//'Host:www.ilab-x.com',
"Content-type: application/json",
'Content-Length: ' . $length,
];
\Log::error(var_export($postData, true));
\Log::error(var_export($data, true));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_HEADER, 0);//是否显示头信息
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_COOKIEJAR, $this->cookie); //设置Cookie信息保存在指定的文件中
curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie); //发送cookie信息
curl_setopt($curl, CURLOPT_POST, 1);//post方式提交
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);//注意,这里提交json格式
curl_setopt($curl, CURLOPT_REFERER, "http://www.****.com/details/v5?id={$this->projectID}&isView=true");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36");
curl_setopt($curl, CURLOPT_ENCODING, 'deflate');
$json = curl_exec($curl);
curl_close($curl);
\Log::error(var_export($headers, true));
\Log::error(var_export($json, true));
return json_decode($json, true);
}
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。