...
|
...
|
@@ -87,10 +87,11 @@ class Yohobuy |
|
|
*
|
|
|
* @param string $url 接口URL
|
|
|
* @param array $data 参数列表
|
|
|
* @param bool $returnJson 控制是否返回json格式数据
|
|
|
* @param int $timeout 超时时间
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public static function get($url, $data = array(), $timeout = 5)
|
|
|
public static function get($url, $data = array(), $returnJson = false, $timeout = 5)
|
|
|
{
|
|
|
if (isset($data['private_key'])) {
|
|
|
unset($data['private_key']);
|
...
|
...
|
@@ -104,7 +105,7 @@ class Yohobuy |
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
$result = curl_exec($ch);
|
|
|
if (!empty($result)) {
|
|
|
if (!$returnJson && !empty($result)) {
|
|
|
$result = json_decode($result, true);
|
|
|
}
|
|
|
curl_close($ch);
|
...
|
...
|
@@ -118,12 +119,13 @@ class Yohobuy |
|
|
*
|
|
|
* @param string $url 接口URL
|
|
|
* @param array $data 参数列表
|
|
|
* @param bool $returnJson 控制是否返回json格式数据
|
|
|
* @param int $timeout 超时时间
|
|
|
* @param array $header
|
|
|
* @param array $cookie
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public static function post($url, $data = array(), $timeout = 5, $header = array(), $cookie = array())
|
|
|
public static function post($url, $data = array(), $returnJson = false, $timeout = 5, $header = array(), $cookie = array())
|
|
|
{
|
|
|
$ch = curl_init($url);
|
|
|
|
...
|
...
|
@@ -151,7 +153,7 @@ class Yohobuy |
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
}
|
|
|
$result = curl_exec($ch);
|
|
|
if (!empty($result)) {
|
|
|
if (!$returnJson && !empty($result)) {
|
|
|
$result = json_decode($result, true);
|
|
|
}
|
|
|
curl_close($ch);
|
...
|
...
|
@@ -237,5 +239,23 @@ class Yohobuy |
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* rpc调用远程服务(YAR)
|
|
|
*
|
|
|
* @see http://php.net/manual/zh/yar-client.setopt.php
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function yarClient($uri, $method, $data = array(), $timeout = 3000)
|
|
|
{
|
|
|
$client = new \Yar_Client($uri);
|
|
|
$client->SetOpt(YAR_OPT_PACKAGER, 'php');
|
|
|
$client->SetOpt(YAR_OPT_TIMEOUT, $timeout);
|
|
|
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout);
|
|
|
|
|
|
$result = $client->$method($data);
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|