经典案例
  • 福州沐仙生建盏
  • 福建新路旅游文化传播有限公司
  • 宁德好记建材公司


通过淘宝ID获取淘宝商品详情

发布于:2017-11-21 21:29来源:福州网站制作 作者:福州网站建设 点击:
通过淘宝ID获取淘宝商品详情,亲测可用哈!!
print_r(getInfo(556112013525));
function getInfo($iid)
{
 
$murl = "http://hws.m.taobao.com/cache/wdetail/5.0/?id=" . $iid; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $murl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
$file_contents = curl_exec($ch);
curl_close($ch);
if (!$file_contents) {
$file_contents = file_get_contents($murl);
}
$data = getTaobaoShopInfo($file_contents);
$data['num_iid'] = $param['id'];
return $data;
 
}
 
function getTaobaoShopInfo($content)
{
$data = json_decode($content, true);
 
$info = array();
$tmp = json_decode($data['data']['apiStack'][0]['value'], true);
$info['title'] = $data['data']['itemInfoModel']['title'];
$info['volume'] = $tmp['data']['itemInfoModel']['totalSoldQuantity'];
$info['ems'] = $tmp['data']['delivery']['deliveryFees'][0];
$info['coupon_price'] = $tmp['data']['itemInfoModel']['priceUnits'][0]['price'];
if (substr_count($info['coupon_price'], '-')) {
$tmp1 = explode('-', $info['coupon_price']);
$info['coupon_price'] = min($tmp1[0], $tmp1[1]);
}
$info['price'] = $tmp['data']['itemInfoModel']['priceUnits'][1]['price'];
if (substr_count($info['price'], '-')) {
$tmp = explode("-", $info['price']);
$info['price'] = min($tmp[0], $tmp[1]);
}
$info['pic_url'] = $data['data']['itemInfoModel']['picsPath'][0];
$info['pics'] = $data['data']['itemInfoModel']['picsPath'];
$info['pic_url'] = str_replace("_320x320.jpg", "", $info['pic_url']);
$info['sellerId'] = $data['data']['seller']['userNumId'];
$info['nick'] = $data['data']['seller']['nick'];
$info['type'] = $data['data']['seller']['type'];
$info['cu'] = $tmp['data']['itemInfoModel']['priceUnits'][0]['name'];
if (!$info['cu']) {
$info['cu'] = $tmp['data']['itemInfoModel']['priceUnits'][0]['tips'][0]['txt'];
}
$info['feedback'] = $data['data']['rateInfo']['rateDetailList'][0]['feedback'];
$info['nicker'] = $data['data']['rateInfo']['rateDetailList'][0]['nick'];
$info['headPic'] = $data['data']['rateInfo']['rateDetailList'][0]['headPic'];
$info['feedback1'] = $data['data']['rateInfo']['rateDetailList'][1]['feedback'];
$info['nicker1'] = $data['data']['rateInfo']['rateDetailList'][1]['nick'];
$info['headPic1'] = $data['data']['rateInfo']['rateDetailList'][1]['headPic'];
$info['feedback2'] = $data['data']['rateInfo']['rateDetailList'][2]['feedback'];
$info['nicker2'] = $data['data']['rateInfo']['rateDetailList'][2]['nick'];
$info['headPic2'] = $data['data']['rateInfo']['rateDetailList'][2]['headPic'];
$info['feedback3'] = $data['data']['rateInfo']['rateDetailList'][3]['feedback'];
$info['nicker3'] = $data['data']['rateInfo']['rateDetailList'][3]['nick'];
$info['headPic3'] = $data['data']['rateInfo']['rateDetailList'][3]['headPic'];
$info['feedback4'] = $data['data']['rateInfo']['rateDetailList'][4]['feedback'];
$info['nicker4'] = $data['data']['rateInfo']['rateDetailList'][4]['nick'];
$info['headPic4'] = $data['data']['rateInfo']['rateDetailList'][4]['headPic'];
$info['descInfo'] = $data['data']['descInfo']['briefDescUrl'];
         
//$ftxia_https = new ftxia_https();
//$ftxia_https->fetch($info['descInfo']);
//$source = $ftxia_https->results;
//if (!$source) {
//$source = file_get_contents($info['descInfo']);
//}
//$comlist = json_decode($source, true);
//$tm = $comlist['data']['images'];
//$onepic = '<img class="lazy" src=' . $tm[0] . '>';
//$zcitem['desc'] = implode('', $tm);
// foreach ($tm as $sms) {
//if (strpos($zcitem['desc'], $sms)) {
//$imgurl = '<img class="lazy" src=' . $sms . '>';
//$zcitem['desc'] = str_replace($sms, $imgurl, $zcitem['desc']);
//$zcitem['desc'] = str_replace($tm[0], '', $zcitem['desc']);
//}
//}
$info['desc'] = $onepic . '' . $zcitem['desc'];
return $info;
}
tag标签:
------分隔线----------------------------
------分隔线----------------------------