Yohobuy.class.php 1.12 KB
<?php
class Util_Product_Api_Yohobuy extends Util_Product_Api
{
	private static $open_key = 'af7dac22';
	private static $api = 'http://v5.open.yohobuy.com?';
	
    public function getData($url)
    {
    	$build_query = array ('open_key' => self::$open_key, 'method' => 'yh.product.getByUrl', 'product_url' => $url );
    	$build_query = http_build_query($build_query);
    	$product = json_decode ( Util_Product_ApiConnect::get(self::$api.$build_query), true);
    	if(is_array($product) && !empty($product['data']))
    	{
    		$product = $product['data'];
    		self::$product->name = $product['product_name'];
    		self::$product->price = $product['price'];
    		self::$product->img = $product['image']['600x1000'];
    		for($i = 0; $i<count($product['skc_list']); $i++)
    		{
    			for($j = 0; $j<count($product['skc_list'][$i]['images']); $j++)
    				self::$product->imgs[] = ($product['skc_list'][$i]['images'][$j]['600x1000']);
    		}
    		self::$product->imgs = array_values(array_unique(self::$product->imgs));
    	}
    	else
    	{
    		throw new Util_Product_ApiException('请输入正确的商品地址!');
    	}
    }
}