From f71c302c16f77f1f45c6f9087b4ae66bfbde0748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 19 Nov 2020 10:18:57 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=E6=B7=98=E5=AE=9D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ src/common.php | 2 +- src/service/taobao/TbkService.php | 34 +++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b4050f..eef2851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v6.0.125 / 2020-11-19 +- 优化淘宝服务协议 + ## v6.0.124 / 2020-11-19 - 小范围测试淘宝官方SDK diff --git a/src/common.php b/src/common.php index f9758f5..be6bc45 100644 --- a/src/common.php +++ b/src/common.php @@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService; /** * 定义当前版本 */ -const VERSION = '6.0.124'; +const VERSION = '6.0.125'; if (!function_exists('get_ip_info')) { /** diff --git a/src/service/taobao/TbkService.php b/src/service/taobao/TbkService.php index 2ba6644..1aa2919 100644 --- a/src/service/taobao/TbkService.php +++ b/src/service/taobao/TbkService.php @@ -80,6 +80,23 @@ class TbkService extends Service */ private $output; + /** + * 安全协议 + * @var string + */ + private $protocol = 'http'; + + /** + * 设置安全协议 + * @param string $protocol + * @return $this + */ + public function setProtocol($protocol = 'http'): self + { + $this->protocol = $protocol; + return $this; + } + /** * 是否为沙箱 * @return $this @@ -927,10 +944,19 @@ class TbkService extends Service $strParam = $this->createStrParam(); $strParam .= 'sign=' . $sign; //访问服务 - if (empty($this->sandbox)) { - $url = 'http://gw.api.taobao.com/router/rest?' . $strParam; - } else { - $url = 'http://gw.api.tbsandbox.com/router/rest?' . $strParam; + if ($this->protocol === 'http') { + if (empty($this->sandbox)) { + $url = 'http://gw.api.taobao.com/router/rest?' . $strParam; + } else { + $url = 'http://gw.api.tbsandbox.com/router/rest?' . $strParam; + } + } + if ($this->protocol === 'https') { + if (empty($this->sandbox)) { + $url = 'https://eco.taobao.com/router/rest?' . $strParam; + } else { + $url = 'https://gw.api.tbsandbox.com/router/rest?' . $strParam; + } } $result = file_get_contents($url); $result = json_decode($result, true);