...
|
...
|
@@ -18,7 +18,7 @@ class Yohobuy |
|
|
{
|
|
|
|
|
|
// /* 正式环境 */
|
|
|
// const API_URL = 'http://api2.open.yohobuy.com/';
|
|
|
//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/';
|
...
|
...
|
@@ -27,7 +27,7 @@ class Yohobuy |
|
|
const API_URL = 'http://test2.open.yohobuy.com/';
|
|
|
const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
|
|
|
const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
const API_URL_MYCENTER = 'http://192.168.102.213:8080/api-gateway-web/'; // 我的个人中心接口URL
|
|
|
const API_URL_MYCENTER = 'http://192.168.102.213:8080/yoho-users-web/'; // 我的个人中心接口URL
|
|
|
const API_URL_SHOPINGCART = 'http://192.168.102.213:8080/api-gateway-web/'; // 我的购物车接口URL
|
|
|
const API_URL_PRODUCTDETAIL = 'http://172.16.6.145:8080/'; // 商品详情页
|
|
|
|
...
|
...
|
@@ -61,6 +61,25 @@ class Yohobuy |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取得当前的IP地址
|
|
|
*
|
|
|
* @param bool $int 返回int类型的ip地址,默认是
|
|
|
* @return mixed 当前的IP地址
|
|
|
*/
|
|
|
public static function ip($int = true)
|
|
|
{
|
|
|
if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP']) {
|
|
|
$onlineip = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
|
|
|
$onlineip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
} else {
|
|
|
$onlineip = $_SERVER['REMOTE_ADDR'];
|
|
|
}
|
|
|
|
|
|
return $int ? ip2long($onlineip) : $onlineip;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取得公共的参数
|
|
|
*
|
...
|
...
|
@@ -101,16 +120,16 @@ class Yohobuy |
|
|
return $url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* get方式调用接口
|
|
|
*
|
|
|
* @param string $url 接口URL
|
|
|
* @param array $data 参数列表
|
|
|
* @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
|
|
|
* @param bool $returnJson 控制是否返回json格式数据
|
|
|
* @param int $timeout 超时时间
|
|
|
* @return mixed
|
|
|
*/
|
|
|
/**
|
|
|
* get方式调用接口
|
|
|
*
|
|
|
* @param string $url 接口URL
|
|
|
* @param array $data 参数列表
|
|
|
* @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
|
|
|
* @param bool $returnJson 控制是否返回json格式数据
|
|
|
* @param int $timeout 超时时间
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5)
|
|
|
{
|
|
|
// 销毁私钥参数
|
...
|
...
|
@@ -383,4 +402,53 @@ class Yohobuy |
|
|
\Yar_Concurrent_Client::loop($callback);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 提交json格式数据请求java有关接口
|
|
|
*
|
|
|
* @param string $url 接口URL
|
|
|
* @param array $data 参数列表
|
|
|
* @param bool $returnJson 控制是否返回json格式数据
|
|
|
* @param int $timeout 超时时间
|
|
|
* @param array $cookie
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public static function jsonPost($url, $data = array(), $returnJson = false, $timeout = 5, $cookie = array())
|
|
|
{
|
|
|
$ch = curl_init($url);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
|
|
|
|
if (!empty($cookie)) {
|
|
|
$cookie_str = array();
|
|
|
foreach ($cookie as $key => $val) {
|
|
|
$cookie_str[] = urlencode($key) . '=' . urlencode($val);
|
|
|
}
|
|
|
curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookie_str));
|
|
|
}
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
|
if (!empty($data)) {
|
|
|
$data_string = json_encode($data);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
|
|
// 设置json的Header
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
'Content-Type: application/json',
|
|
|
'Content-Length: ' . strlen($data_string)
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
$result = curl_exec($ch);
|
|
|
if (!$returnJson && !empty($result)) {
|
|
|
$result = json_decode($result, true);
|
|
|
}
|
|
|
curl_close($ch);
|
|
|
$data = array();
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|