From 2a8d1aaf6b470f0b4f9304e6eb11d6a48189de09 Mon Sep 17 00:00:00 2001
From: Rock Zhang <iamgtskk@gmail.com>
Date: Wed, 13 Apr 2016 10:21:46 +0800
Subject: [PATCH] 添加调用接口时的Gzip配置项

Code Review By Rock Zhang
---
 library/Api/Yohobuy.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/library/Api/Yohobuy.php b/library/Api/Yohobuy.php
index 4debdb2..555d946 100644
--- a/library/Api/Yohobuy.php
+++ b/library/Api/Yohobuy.php
@@ -165,12 +165,14 @@ class Yohobuy
      *
      * @param string $url 接口URL
      * @param array $data 参数列表
-     * @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
+     * @param bool $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
      * @param bool $returnJson 控制是否返回json格式数据
      * @param int $timeout 超时时间
+     * @param null $userAgent
+     * @param bool $useGzip 是否启用Gzip
      * @return mixed
      */
-    public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null)
+    public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
     {
         // 销毁私钥参数
         if (isset($data['private_key'])) {
@@ -191,6 +193,10 @@ class Yohobuy
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        if ($useGzip) {
+            curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
+        }
+
         if (!empty($userAgent)) {
             curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
         }
--
libgit2 0.24.0