Zozo.class.php 1.05 KB
<?php
/**
 * http://zozo.jp/
 *
 */
class Util_Product_Api_Zozo extends Util_Product_Api
{
	public function getData($url)
	{
		$data = '';
		$i = 0;
		while(empty($data) && $i<5)
		{
			$data = Util_Product_ApiConnect::get(urldecode($url), array(CURLOPT_TIMEOUT => 10));
			$i++;
		}
	 	phpQuery::$defaultCharset = 'Shift_JIS';
		if(!empty($data))
		{
			@phpQuery::newDocument($data);
			$doc = pq('.infoBlock');
			self::$product->name =  $doc->find('h2')->text();
			self::$product->price = trim(str_replace(array(',','¥'), '', $doc->find('.price')->text()));
			self::$product->unit = 'JPY';
			$picDoc = pq('#photoThimb');
			$imgs = array();
			$length = $picDoc->find('li')->length();
			if($length>10)
			{
				$length = 10;
			}
			for($i = 0;$i<$length; $i++)
			{
				$imgs[] = str_replace('_35','_500', $picDoc->find('#goodsdiv_'.$i)->find('img')->attr('src'));
			}
			self::$product->imgs = array_values(array_unique($imgs));
			self::$product->img = $imgs[0];
		}
		else
		{
			throw new Util_Product_ApiException('请输入正确的商品地址!');
		}
	}
}