function selects($code){
//目标url
$url = 'https://smartprogram.baidu.com/mappconsole/api/invitecode';
$fields = 'code='.$code;
$cookie_file = __DIR__ . "/".'cookies.txt';
// $cookie_file = realpath($cookie_file);
$curl = curl_init();
//模拟浏览器参数
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"accept: application/json, text/plain, */*",
"accept-encoding: gzip, deflate, br",
"accept-language: zh-CN,zh;q=0.9,en;q=0.8",
"Connection: keep-alive",
"Content-Length: 11",
"content-type: application/x-www-form-urlencoded",
"Host: smartprogram.baidu.com",
"Origin: https://smartprogram.baidu.com",
"Referer: https://smartprogram.baidu.com/mappconsole/main/invite",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
),
));
//带上cookie值,也可以存到文件中去
curl_setopt($curl,CURLOPT_COOKIE,'BAIDUID=C8DF0B1CE2243E94FAD5DE121479B385:FG=1; PSTM=1532744722; BIDUPSID=883DD84EA4138FF8F68DF45B6C6CA2B1; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; BDRCVFR[7WSJNEW_4S_]=aeXf-1x8UdYcs; H_PS_PSSID=; PSINO=6; BDSFRCVID=rE0sJeCCxG37Jyc7VYFHfWyUNlsVGLHJR2sY3J; H_BDCLCKID_SF=tR3eWRj-bPJKDn34-tF_-4_tbh_X5-RLf5r4oPOF5lOTJh0RjU6B-T-ZWtj7Kqb8QmoQQMQTBpnkVCoRWjbke4tX-NFHqT_DJU5; FP_UID=0ab8fc2da85a49cd8eb83a3c954d4a35; BDUSS=ZNQ2tZfnVFTGNMekg0TkVsOTV6WFBlclBQUEhzSGZiMmh2Qn5-bFpnRW9nWWRiQVFBQUFBJCQAAAAAAAAAAAEAAABDn~8UeDU2ODU1NDQyOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACj0X1so9F9bQV');
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HEADER, 1); //返回头信息
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($curl);
$err = curl_error($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
return $response;
}