...
|
...
|
@@ -14,36 +14,6 @@ namespace Api; |
|
|
use Plugin\Cache;
|
|
|
class Yohobuy
|
|
|
{
|
|
|
/* 正式环境 */
|
|
|
// php API
|
|
|
// const API_URL = 'http://api2.open.yohobuy.com/';
|
|
|
// const API_URL2 = 'http://api.open.yohobuy.com/';
|
|
|
// const SERVICE_URL = 'http://service.api.yohobuy.com/';
|
|
|
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
|
|
|
//java API
|
|
|
// const API_URL = 'http://api.yoho.yohoops.org/';//
|
|
|
// const API_URL2 = 'http://api.yoho.yohoops.org/';//
|
|
|
// const SERVICE_URL = 'http://service.yoho.yohoops.org/';
|
|
|
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
// const API_OLD = 'http://api2.open.yohobuy.com/';
|
|
|
// 支付回调地址
|
|
|
// const SERVICE_NOTIFY = 'http://service.yoho.cn/';
|
|
|
|
|
|
// 测试环境 */
|
|
|
const API_URL = 'http://testapi.yoho.cn:28078/'; // http://testapi.yoho.cn:28078/ http://devapi.yoho.cn:58078/
|
|
|
const SERVICE_URL = 'http://testservice.yoho.cn:28077/'; // http://testservice.yoho.cn:28077/ http://devservice.yoho.cn:58077/
|
|
|
const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
const API_OLD = 'http://test2.open.yohobuy.com/';
|
|
|
// 支付回调地址
|
|
|
const SERVICE_NOTIFY = 'http://testservice.yoho.cn:28077/';
|
|
|
|
|
|
/* 预览环境 */
|
|
|
// const API_URL = 'http://preapi.yoho.cn/';
|
|
|
// const API_URL2 = 'http://preapi.yoho.cn/';
|
|
|
// const SERVICE_URL = 'http://preservice.yoho.cn/';
|
|
|
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
// const API_OLD = 'http://api2.open.yohobuy.com/';
|
|
|
|
|
|
/**
|
|
|
* 登录老接口Api配置
|
...
|
...
|
@@ -64,6 +34,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' => 'app-java-168863769.cn-north-1.elb.amazonaws.com.cn',
|
|
|
'service' => 'service-yoho-579825100.cn-north-1.elb.amazonaws.com.cn'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
/**
|
|
|
* 取得当前的客户端类型
|
...
|
...
|
@@ -167,13 +148,27 @@ class Yohobuy |
|
|
*/
|
|
|
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
|
|
|
{
|
|
|
$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), 有数据则直接返回.
|
...
|
...
|
@@ -182,17 +177,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);
|
...
|
...
|
@@ -229,9 +234,27 @@ class Yohobuy |
|
|
*/
|
|
|
public static function post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
|
|
|
{
|
|
|
$ch = curl_init($url);
|
|
|
$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 {
|
...
|
...
|
@@ -247,6 +270,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']);
|
...
|
...
|
@@ -530,4 +554,40 @@ 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) {
|
|
|
$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 {
|
|
|
$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']. '/';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $url;
|
|
|
}
|
|
|
} |
...
|
...
|
|