360buy.class.php 1.15 KB
<?php
/**
 * http://www.360buy.com
 * 京东
 */
class Util_Product_Api_360buy extends Util_Product_Api
{
    public function getData($url)
    {
        phpQuery::$defaultCharset = 'gb2312';
        $data = Util_Product_ApiConnect::get($url);
        if(!empty($data))
        {
            @phpQuery::newDocument($data);
            $doc = pq("#preview");
            self::$product->name = $doc->find('img[data-img="1"]')->attr('alt');
            $img = $doc->find('img[data-img="1"]')->attr('src');
            if(empty($img))
            {
                $img = preg_replace('@/n\d/@','/n0/', $doc->find('img[data-img="1"]')->attr('src'));
            }
            self::$product->img = $img;
            $length = $doc->find('img[data-img="1"]')->length();
            for($i = 0; $i<$length; $i++)
            {
            	self::$product->imgs[] = str_replace('/n5/','/n1/', $doc->find('img[data-img="1"]')->eq($i)->attr('src'));
            }
            self::$product->imgs = array_values(array_unique(self::$product->imgs));
        }
        else 
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }
}