|
<?php
$cookie_file = dirname(__FILE__)."/jd.cookie";
//专题首页url
$indexurl = 'http://sale.**j*d.com/act/BOxFsKPGNZwpet4.html';
//获取专题页到产品详情的地址
$indexstr = get($indexurl);
//var_dump($indexstr);exit;
preg_match_all('/
$tmp = pathinfo($data[1][0]);
$pinfo['id'] = $tmp['filename'];
$pinfo['url'] = $data[1][0];
unset($tmp,$data);
$pinfo = getPrice($pinfo['id']);
if($pinfo['mainproduct']['price'] == 1799){
addcar();
}else{
echo "还没有开始抢购";
}
function get($url,$flag=true){
global $cookie_file;
$headerArray = array(
"content-type: application/x-www-form-urlencoded;charset=UTF-8",
);
//echo $cookie_file;exit;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERAGENT,'"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"');
curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);//设置头信息
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
$return = curl_exec($ch);
curl_close($ch);
if($flag)$return = gzdecode($return);
return $return;
}
function getPrice($id){
$priceUrl = "http://rs.***jd.com/accessorie/newServiceWhite.jsonp?sku=".$id;
$data = json_decode(get($priceUrl,false),true);
return $data;
}
function addcar(){
global $pinfo;
$addurl = "http://gate.j***d.com/InitCart.aspx?pid=".$pinfo['mainproduct']['sku']."&pcount=1&ptype=1";
echo get($addurl,false);
}
|