Authored by 郝肖肖

分流url

... ... @@ -71,8 +71,8 @@ class Yohobuy
'service' => array('123.206.1.98', '123.206.2.80')
),
'awsServers' => array(
'api' => array('app-java-168863769.cn-north-1.elb.amazonaws.com.cn'),
'service' => array('service-yoho-579825100.cn-north-1.elb.amazonaws.com.cn')
'api' => 'app-java-168863769.cn-north-1.elb.amazonaws.com.cn',
'service' => 'service-yoho-579825100.cn-north-1.elb.amazonaws.com.cn'
)
);
... ... @@ -178,16 +178,27 @@ class Yohobuy
*/
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
{
$url = self::_getUrl($url, $data);
$isApi = false;
$isService = false;
if (USE_INTER_FACE_SHUNT) {
if (strpos($url, 'api.')) {
$isApi = true;
} else if (strpos($url, 'service.')) {
$isService = true;
}
$url = self::_getUrl($url, $data);
}
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
}
if (!empty($data)) {
$url = self::httpBuildQuery($url, $data);
} //echo $url;
/* 开启缓存的情况 */
if ($cache && USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
... ... @@ -196,17 +207,27 @@ class Yohobuy
return $result;
}
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($isApi) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: api.yoho.cn'));
} else if ($isService) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: service.yoho.cn'));
}
if ($useGzip) {
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
}
if (!empty($userAgent)) {
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
}
$result = curl_exec($ch);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
... ... @@ -243,10 +264,27 @@ class Yohobuy
*/
public static function post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
{
$url = self::_getUrl($url, $data);
$isApi = false;
$isService = false;
if (USE_INTER_FACE_SHUNT) {
if (strpos($url, 'api.')) {
$isApi = true;
} else if (strpos($url, 'service.')) {
$isService = true;
}
$url = self::_getUrl($url, $data);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if ($isApi) {
array_push($header, 'Host: api.yoho.cn');
} else if ($isService) {
array_push($header, 'Host: service.yoho.cn');
}
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} else {
... ... @@ -262,6 +300,7 @@ class Yohobuy
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
... ... @@ -564,16 +603,18 @@ class Yohobuy
}
if ($mod > 128 || $uid === 0) {
if (strpos('://api.', $url)) {
$url = array_rand(self::$interfaceShunt['awsServers']['api']);
} else if (strpos('://service.', $url)) {
$url = array_rand(self::$interfaceShunt['awsServers']['service']);
$paseUrl = parse_url($url);
if (strpos($url, 'api.')) {
$url = 'http://' . self::$interfaceShunt['awsServers']['api'] . $paseUrl['path']. '/';
} else if (strpos($url, 'service.')) {
$url = 'http://' . self::$interfaceShunt['awsServers']['service'] . $paseUrl['path']. '/';
}
} else {
if (strpos('://api.', $url)) {
$url = array_rand(self::$interfaceShunt['tencentServers']['api']);
} else if (strpos('://service.', $url)) {
$url = array_rand(self::$interfaceShunt['tencentServers']['service']);
$paseUrl = parse_url($url);
if (strpos($url, 'api.')) {
$url = 'http://' . array_rand(self::$interfaceShunt['tencentServers']['api']) . $paseUrl['path'] . '/';
} else if (strpos($url, 'service.')) {
$url = 'http://' . array_rand(self::$interfaceShunt['tencentServers']['service']) . $paseUrl['path']. '/';
}
}
... ...