...
|
...
|
@@ -9,15 +9,20 @@ |
|
|
* @version 1.0 (2015-9-30 16:42:51)
|
|
|
* @author fei.hong <fei.hong@yoho.cn>
|
|
|
*/
|
|
|
namespace Api;
|
|
|
|
|
|
use Plugin\Cache;
|
|
|
namespace Api;
|
|
|
|
|
|
class Yohobuy
|
|
|
{
|
|
|
|
|
|
const API_URL = 'http://api2.open.yohobuy.com/';
|
|
|
const SERVICE_URL = 'http://service.api.yohobuy.com/';
|
|
|
// /* 正式环境 */
|
|
|
// const API_URL = 'http://api2.open.yohobuy.com/';
|
|
|
// const SERVICE_URL = 'http://service.api.yohobuy.com/';
|
|
|
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
|
|
|
/* 测试环境 */
|
|
|
const API_URL = 'http://test2.open.yohobuy.com/';
|
|
|
const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
|
|
|
const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -101,18 +106,6 @@ class Yohobuy |
|
|
*/
|
|
|
public static function get($url, $data = array(), $returnJson = false, $timeout = 5)
|
|
|
{
|
|
|
// // 代表是否开启缓存
|
|
|
// $useCache = $cache && isset($data['client_secret']);
|
|
|
//
|
|
|
// /* 先尝试获取一级缓存(master), 有数据则直接返回 */
|
|
|
// if ($useCache) {
|
|
|
// $key = md5($url . $data['client_secret']);
|
|
|
// $result = Cache::get($key, 'master');
|
|
|
// if (!empty($result)) {
|
|
|
// return $result;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// 销毁私钥参数
|
|
|
if (isset($data['private_key'])) {
|
|
|
unset($data['private_key']);
|
...
|
...
|
@@ -132,18 +125,6 @@ class Yohobuy |
|
|
curl_close($ch);
|
|
|
$data = array();
|
|
|
|
|
|
// /* 设置一级二级缓存 或 获取二级缓存(slave) */
|
|
|
// if ($useCache) {
|
|
|
// // 如果接口异常没数据返回,则获取二级缓存
|
|
|
// if (empty($result)) {
|
|
|
// $result = Cache::get($key, 'slave');
|
|
|
// }
|
|
|
// // 如果接口正常有数据返回,则设置数据缓存
|
|
|
// else {
|
|
|
// Cache::set($key, $result);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -165,8 +146,7 @@ class Yohobuy |
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
if (!empty($header)) {
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
}
|
|
|
else {
|
|
|
} else {
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -242,8 +222,7 @@ class Yohobuy |
|
|
do {
|
|
|
do {
|
|
|
$status = curl_multi_exec($mh, $running);
|
|
|
}
|
|
|
while ($status == CURLM_CALL_MULTI_PERFORM);
|
|
|
} while ($status == CURLM_CALL_MULTI_PERFORM);
|
|
|
|
|
|
if ($status != CURLM_OK) {
|
|
|
break;
|
...
|
...
|
@@ -252,8 +231,7 @@ class Yohobuy |
|
|
if ($running > 0) {
|
|
|
curl_multi_select($mh, 0.5);
|
|
|
}
|
|
|
}
|
|
|
while ($running);
|
|
|
} while ($running);
|
|
|
|
|
|
// 获取API接口响应的结果
|
|
|
foreach ($urlList as $name => $api) {
|
...
|
...
|
@@ -322,6 +300,7 @@ class Yohobuy |
|
|
YAR_OPT_CONNECT_TIMEOUT => $timeout
|
|
|
));
|
|
|
}
|
|
|
|
|
|
public static function yarConcurrentLoop($callback = null)
|
|
|
{
|
|
|
\Yar_Concurrent_Client::loop($callback);
|
...
|
...
|
|