Authored by whb

添加PC的api gzip

@@ -152,9 +152,11 @@ class Yohobuy @@ -152,9 +152,11 @@ class Yohobuy
152 * @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存 152 * @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
153 * @param bool $returnJson 控制是否返回json格式数据 153 * @param bool $returnJson 控制是否返回json格式数据
154 * @param int $timeout 超时时间 154 * @param int $timeout 超时时间
  155 + * @param null $userAgent
  156 + * @param bool $useGzip 是否启用Gzip
155 * @return mixed 157 * @return mixed
156 */ 158 */
157 - public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null) 159 + public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
158 { 160 {
159 // 销毁私钥参数 161 // 销毁私钥参数
160 if (isset($data['private_key'])) { 162 if (isset($data['private_key'])) {
@@ -175,6 +177,9 @@ class Yohobuy @@ -175,6 +177,9 @@ class Yohobuy
175 curl_setopt($ch, CURLOPT_HEADER, 0); 177 curl_setopt($ch, CURLOPT_HEADER, 0);
176 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 178 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
177 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 179 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  180 + if ($useGzip) {
  181 + curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
  182 + }
178 if (!empty($userAgent)) { 183 if (!empty($userAgent)) {
179 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); 184 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
180 } 185 }