From 6c09a8d67b7f88e2ce3c58a4481414779bcede8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Fri, 4 Sep 2020 00:37:16 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E8=8E=B7=E5=8F=96access=5Ftoken=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 ++++- src/common.php | 2 +- src/service/wechat/WebAppService.php | 33 ++++++++++++++++++---------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a9a50..d212e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## v6.0.107 / 2020-09-03 +## v6.0.109 / 2020-09-04 +- 修复公众号获取access_token问题 + +## v6.0.108 / 2020-09-03 - 修复数组 ## v6.0.107 / 2020-08-15 diff --git a/src/common.php b/src/common.php index 4bd2623..b7dcb04 100644 --- a/src/common.php +++ b/src/common.php @@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService; /** * 定义当前版本 */ -const VERSION = '6.0.108'; +const VERSION = '6.0.109'; if (!function_exists('get_ip_info')) { /** diff --git a/src/service/wechat/WebAppService.php b/src/service/wechat/WebAppService.php index a816d36..049e1d2 100644 --- a/src/service/wechat/WebAppService.php +++ b/src/service/wechat/WebAppService.php @@ -646,10 +646,19 @@ class WebAppService extends Service file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE)); $accessToken = $accessToken_res; } - $judge = HttpService::instance() - ->url("{$this->api_url}cgi-bin/getcallbackip?access_token={$accessToken['access_token']}") - ->toArray(); - if (!isset($judge['ip_list'])) { + if (isset($accessToken['access_token'])) { + $judge = HttpService::instance() + ->url("{$this->api_url}cgi-bin/getcallbackip?access_token={$accessToken['access_token']}") + ->toArray(); + if (!isset($judge['ip_list'])) { + $accessToken_res = HttpService::instance() + ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") + ->toArray(); + $accessToken_res['expires_time'] = time() + 6000; + file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE)); + $accessToken = $accessToken_res; + } + } else { $accessToken_res = HttpService::instance() ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") ->toArray(); @@ -658,7 +667,9 @@ class WebAppService extends Service $accessToken = $accessToken_res; } return $accessToken; - } else if ($this->cache == "mysql") { + } + + if ($this->cache == "mysql") { $access_token = []; // 文件名 $file = "{$this->app_id}_access_token"; @@ -687,9 +698,9 @@ class WebAppService extends Service $access_token['access_token'] = $accessToken_res['access_token']; } return $access_token; - } else { - throw new DtaException("驱动方式错误"); } + + throw new DtaException("驱动方式错误"); } /** @@ -773,10 +784,10 @@ class WebAppService extends Service if ($data) { curl_close($ch); return $data; - } else { - $error = curl_errno($ch); - curl_close($ch); - return "curl error, error code " . $error; } + + $error = curl_errno($ch); + curl_close($ch); + return "curl error, error code " . $error; } } -- GitLab