Authored by 郝肖肖

server 分流

... ... @@ -64,6 +64,17 @@ class Yohobuy
'h5' => 'fd4ad5fcfa0de589ef238c0e7331b585',
);
//分流服务器接口
public static $interfaceShunt = array(
'tencentServers' => array(
'api' => array('123.206.1.98', '123.206.2.80'),
'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')
)
);
/**
* 取得当前的客户端类型
... ... @@ -167,6 +178,9 @@ class Yohobuy
*/
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
{
$url = self::_getUrl($url, $data);
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
... ... @@ -229,8 +243,9 @@ class Yohobuy
*/
public static function post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
{
$ch = curl_init($url);
$url = self::_getUrl($url, $data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
... ... @@ -530,4 +545,38 @@ class Yohobuy
}
return $isMobile;
}
/**
*根据配置决定请求Java接口的地址
*/
private static function _getUrl($url, $param)
{
if (USE_INTER_FACE_SHUNT === false) {
return $url;
}
$uid = 0;
$mod = 0;
if (isset($param['uid'])) {
$uid = $param['uid'];
$mod = $param['uid'] % 1024;
}
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']);
}
} else {
if (strpos('://api.', $url)) {
$url = array_rand(self::$interfaceShunt['tencentServers']['api']);
} else if (strpos('://service.', $url)) {
$url = array_rand(self::$interfaceShunt['tencentServers']['service']);
}
}
return $url;
}
}
... ...
... ... @@ -11,6 +11,8 @@ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
define('EXHIBITION_TICKET', 51335912);//展览票skn
define('USE_INTER_FACE_SHUNT', false);//分流开关
#test环境
define('API_URL', 'http://testapi.yoho.cn:28078/');
define('SERVICE_URL', 'http://testservice.yoho.cn:28077/');
... ...
... ... @@ -12,6 +12,8 @@ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');
define('EXHIBITION_TICKET', 51335912);//展览票skn
define('USE_INTER_FACE_SHUNT', false);//分流开关
define('API_URL', 'http://api.yoho.yohoops.org/');
define('SERVICE_URL', 'http://service.yoho.yohoops.org/');
define('YOHOBUY_URL', 'http://www.yohobuy.com/');
... ...
... ... @@ -12,6 +12,8 @@ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'preview');
define('EXHIBITION_TICKET', 51335912);//展览票skn
define('USE_INTER_FACE_SHUNT', false);//分流开关
define('API_URL', 'http://api.yoho.yohoops.org/');
define('SERVICE_URL', 'http://service.yoho.yohoops.org/');
define('YOHOBUY_URL', 'http://www.yohobuy.com/');
... ...
... ... @@ -12,6 +12,8 @@ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing');
define('EXHIBITION_TICKET', 51335912);//展览票skn
define('USE_INTER_FACE_SHUNT', false);//分流开关
define('API_URL', 'http://testapi.yoho.cn:28078/');
define('SERVICE_URL', 'http://testservice.yoho.cn:28077/');
define('YOHOBUY_URL', 'http://www.yohobuy.com/');
... ...
... ... @@ -12,6 +12,8 @@ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');
define('EXHIBITION_TICKET', 51335912);//展览票skn
define('USE_INTER_FACE_SHUNT', false);//分流开关
define('API_URL', 'http://api.yoho.yohoops.org/');
define('SERVICE_URL', 'http://service.yoho.yohoops.org/');
define('YOHOBUY_URL', 'http://www.yohobuy.com/');
... ...