From 4714f4a45ad2357e3d1de728158627d1cadb8b52 Mon Sep 17 00:00:00 2001 From: jianghanbo Date: Fri, 16 Aug 2024 22:03:11 +0800 Subject: [PATCH] =?UTF-8?q?token=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/app/server/Douyin.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/service/app/server/Douyin.php b/service/app/server/Douyin.php index b4b7e143..b199ecb5 100644 --- a/service/app/server/Douyin.php +++ b/service/app/server/Douyin.php @@ -24,7 +24,7 @@ class Douyin { $this->cookie = $this->_cookie(); $this->id = $this->_id(); - $this->token = $this->_token($os); + $this->token = $this->_token('', $os); Log::info("抖音 token:{$this->token} \n\n"); ; } @@ -251,7 +251,7 @@ class Douyin if (empty($list) || $list->status_code != 0) { $this->_getRetriesLock(); - $list = $this->_curl("/life/trip/fulfilment/v1/query/certificate_list?end_time={$end}&page_index={$page}&page_size=50&start_time={$start}&root_life_account_id=" . $this->_id(), $params, 'POST'); + $list = $this->_curl("/life/trip/fulfilment/v1/query/certificate_list?end_time={$end}&page_index={$page}&page_size=50&start_time={$start}&root_life_account_id=" . $this->_id($osId), $params, 'POST'); if (empty($list) || $list->status_code != 0) { Log::error('===查询时间:' . $start . '--' . $end . '====certificate_list: ' . json_encode($list)); throw new Exception("抖音拉单失败,Err:" . json_encode($list)); @@ -493,16 +493,21 @@ class Douyin public function _id($id = '') { - if ($id) Redis::set('Douyin:id', $id); - return Redis::get('Douyin:id'); + if ($id == 5) { + return '7399206501845403686'; + } else { + // return '7259680722519066679'; + return Redis::get('Douyin:id'); + } } protected $_try = 0; public function _token($token = '', $os = 3) { - if ($token) Redis::set('Douyin:token', $token, 'ex', 3600 * 24 - 50); - $token = Redis::get('Douyin:token'); + $dyKey = sprintf('Douyin:token-%s', $os); + if ($token) Redis::set($dyKey, $token, 'ex', 3600 * 24 - 50); + $token = Redis::get($dyKey); if (empty($token) && $this->_cookie()) { if ($this->_try > 3) { throw new Exception("cookie 失效"); @@ -510,10 +515,10 @@ class Douyin $id = $this->_curl('/life/gate/v1/user/detail', null, 'HEAD'); $this->_try++; if ($id) { - Redis::set('Douyin:token', $id, 'ex', 3600 * 24 - 50); + Redis::set($dyKey, $id, 'ex', 3600 * 24 - 50); } } - return Redis::get('Douyin:token'); + return Redis::get($dyKey); } public function _curl($url, $params, $method = 'GET')