Authored by hf

do call may like product api

# 接口示例
## 你可能喜欢
URL:
---------------
http://api2.open.yohobuy.com/
?app_version=3.6
&client_secret=b36cbdaf79c70765c96665f151dccea0
&client_type=android
&gender=1%2C3
&limit=50
&method=app.search.last7day
&os_version=android4.4.4%3AASUS_X002
&page=1
&screen_size=720x1280
&v=6
&yh_channel=1
DATA:
---------------
{"code":200,"message":"Last Search List.","data":{"product_list":[{"brand_id":144,"market_price":590,"vip_price":0,"sales_price":590,"vip_discount_type":1,"product_id":"150783","max_sort_id":3,"storage_num":38,"product_name":"VANS M JT CARGO\t ","cn_alphabet":"VANSMJTCARGOVN02NJCMA","product_skn":51088175,"brand_name":"VANS","is_new":"Y","is_discount":"N","is_advance":"N","is_soon_sold_out":"N","is_limited":"N","is_yohood":"N","sales_phrase":"","goods_list":[{"goods_id":"207531","color_name":"\u7eff\u8272","color_id":"6","color_code":"#47ba17","color_value":"","images_url":"http:\/\/img13.static.yhbimg.com\/goodsimg\/2015\/09\/25\/10\/02b2ed1aad22f35ed07f7d98a9de5d6ebf.jpg?imageMogr2\/thumbnail\/{width}x{height}\/extent\/{width}x{height}\/background\/d2hpdGU=\/position\/center\/quality\/90","product_skc":"202881","is_default":"N"}],"tags":[],"default_images":"http:\/\/img13.static.yhbimg.com\/goodsimg\/2015\/09\/25\/10\/02b2ed1aad22f35ed07f7d98a9de5d6ebf.jpg?imageMogr2\/thumbnail\/{width}x{height}\/extent\/{width}x{height}\/background\/d2hpdGU=\/position\/center\/quality\/90"},{"brand_id":144,"market_price":490,"vip_price":0,"sales_price":490,"vip_discount_type":1,"product_id":"150781","max_sort_id":3,"storage_num":3,"product_name":"VANS M WARRICK\t ","cn_alphabet":"VANSMWARRICKVN02NIBHH","product_skn":51088174,"brand_name":"VANS","is_new":"Y","is_discount":"N","is_advance":"N","is_soon_sold_out":"N","is_limited":"N","is_yohood":"N","sales_phrase":"","goods_list":[{"goods_id":"207529","color_name":"\u9ed1\u8272","color_id":"2","color_code":"#333333","color_value":"","images_url":"http:\/\/img13.static.yhbimg.com\/goodsimg\/2015\/09\/25\/10\/02f401305cc7af370a894d7a094bd6f64c.jpg?imageMogr2\/thumbnail\/{width}x{height}\/extent\/{width}x{height}\/background\/d2hpdGU=\/position\/center\/quality\/90","product_skc":"202880","is_default":"N"}],"tags":[],"default_images":"http:\/\/img13.static.yhbimg.com\/goodsimg\/2015\/09\/25\/10\/02f401305cc7af370a894d7a094bd6f64c.jpg?imageMogr2\/thumbnail\/{width}x{height}\/extent\/{width}x{height}\/background\/d2hpdGU=\/position\/center\/quality\/90"}],"page_total":2,"total":52,"page":1,"content_code":""},"md5":"b66258633f505562a520e0fccf0b8803"}
... ...
... ... @@ -15,7 +15,7 @@ namespace Api;
class Yohobuy
{
const API_URL = 'http://api.open.yohobuy.com/';
const API_URL = 'http://api2.open.yohobuy.com/';
const SERVICE_URL = 'http://service.api.yohobuy.com/';
/**
... ... @@ -23,38 +23,84 @@ class Yohobuy
*
* @var array
*/
public static $privateKeyList = array(
private static $privateKeyList = array(
'android' => 'fd4ad5fcfa0de589ef238c0e7331b585',
'iphone' => 'a85bb0674e08986c6b115d5e3a4884fa',
'ipad' => 'ad9fcda2e679cf9229e37feae2cdcf80',
);
/**
* 取得当前的客户端类型
*/
public static function clientType()
{
// 苹果设备
if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) {
return 'iphone';
}
// 苹果IPAD
elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
return 'ipad';
}
// 其它
else {
return 'android';
}
}
/**
* 取得公共的参数
*
* @return array
*/
public static function param()
{
$clientType = self::clientType();
$param = array(
'client_type' => '',
'app_version' => '',
'os_version' => '',
'screen_size' => '',
'v' => '',
'app_version' => '3.6',
'client_type' => $clientType,
'os_version' => 'yohobuy:h5',
'private_key' => self::$privateKeyList[$clientType],
'screen_size' => '720x1280',
'v' => '6',
);
return $param;
}
/**
* 构建URL
*
* @param string $url
* @param array $data
* @return string
*/
public static function httpBuildQuery($url, $data)
{
if (strstr($url, '?') !== false) {
$url .= '&' . http_build_query($data, null, '&');
} else {
$url .= '?' . http_build_query($data, null, '&');
}
return $url;
}
/**
* get方式调用接口
*
* @param string $url 接口URL
* @param array $data 参数列表
* @param int $timeout 超时时间
* @return mixed
*/
public static function get($url, $timeout = 5)
public static function get($url, $data = array(), $timeout = 5)
{
if (isset($data['private_key'])) {
unset($data['private_key']);
}
if (!empty($data)) {
$url .= self::httpBuildQuery($url, $data);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
... ... @@ -64,17 +110,17 @@ class Yohobuy
$result = json_decode($result, true);
}
curl_close($ch);
$data = array();
return $result;
}
/**
* post提交数据
*
* @param string $url 接口URL
* @param array $data
* @param int $timeout
* @param array $data 参数列表
* @param int $timeout 超时时间
* @param array $header
* @param array $cookie
* @return mixed
... ... @@ -82,11 +128,12 @@ class Yohobuy
public static function post($url, $data = array(), $timeout = 5, $header = array(), $cookie = array())
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} else {
curl_setopt($ch, CURLOPT_HEADER, 0);
}
if (!empty($cookie)) {
... ... @@ -99,6 +146,9 @@ class Yohobuy
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if (isset($data['private_key'])) {
unset($data['private_key']);
}
if (!empty($data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
... ... @@ -107,6 +157,7 @@ class Yohobuy
$result = json_decode($result, true);
}
curl_close($ch);
$data = array();
return $result;
}
... ... @@ -186,7 +237,7 @@ class Yohobuy
}
curl_multi_close($mh);
return $data;
return $result;
}
}
... ...
<?php
namespace LibModels\Wap\Product;
use Api\Sign;
use Api\Yohobuy;
/**
* 商品推荐相关的数据模型
*
* @name RecomModel
* @package LibModels/Wap/Product
* @copyright yoho.inc
* @version 1.0 (2015-10-8 11:51:32)
* @author fei.hong <fei.hong@yoho.cn>
*/
class RecomModel
{
/**
* 你可能喜欢的商品列表
*
* @param string $gender "1,3"表示男, "2,3"表示女
* @param string $channel 1表示男, 2表示女
* @param int $page 分页第几页, 默认第1页
* @param int $limit 查询返回的最大限制数, 默认为50
* @return array
*/
public static function mayLike($gender, $channel, $page = 1, $limit = 50)
{
$param = Yohobuy::param();
$param['method'] = 'app.search.last7day';
$param['gender'] = $gender;
$param['page'] = $page;
$param['limit'] = $limit;
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::makeSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...