token获取

This commit is contained in:
jianghanbo 2024-08-16 22:03:11 +08:00
parent ad81522f1e
commit 4714f4a45a
1 changed files with 13 additions and 8 deletions

View File

@ -24,7 +24,7 @@ class Douyin
{ {
$this->cookie = $this->_cookie(); $this->cookie = $this->_cookie();
$this->id = $this->_id(); $this->id = $this->_id();
$this->token = $this->_token($os); $this->token = $this->_token('', $os);
Log::info("抖音 token{$this->token} \n\n"); ; Log::info("抖音 token{$this->token} \n\n"); ;
} }
@ -251,7 +251,7 @@ class Douyin
if (empty($list) || $list->status_code != 0) { if (empty($list) || $list->status_code != 0) {
$this->_getRetriesLock(); $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) { if (empty($list) || $list->status_code != 0) {
Log::error('===查询时间:' . $start . '--' . $end . '====certificate_list: ' . json_encode($list)); Log::error('===查询时间:' . $start . '--' . $end . '====certificate_list: ' . json_encode($list));
throw new Exception("抖音拉单失败,Err:" . json_encode($list)); throw new Exception("抖音拉单失败,Err:" . json_encode($list));
@ -493,16 +493,21 @@ class Douyin
public function _id($id = '') public function _id($id = '')
{ {
if ($id) Redis::set('Douyin:id', $id); if ($id == 5) {
return Redis::get('Douyin:id'); return '7399206501845403686';
} else {
// return '7259680722519066679';
return Redis::get('Douyin:id');
}
} }
protected $_try = 0; protected $_try = 0;
public function _token($token = '', $os = 3) public function _token($token = '', $os = 3)
{ {
if ($token) Redis::set('Douyin:token', $token, 'ex', 3600 * 24 - 50); $dyKey = sprintf('Douyin:token-%s', $os);
$token = Redis::get('Douyin:token'); if ($token) Redis::set($dyKey, $token, 'ex', 3600 * 24 - 50);
$token = Redis::get($dyKey);
if (empty($token) && $this->_cookie()) { if (empty($token) && $this->_cookie()) {
if ($this->_try > 3) { if ($this->_try > 3) {
throw new Exception("cookie 失效"); throw new Exception("cookie 失效");
@ -510,10 +515,10 @@ class Douyin
$id = $this->_curl('/life/gate/v1/user/detail', null, 'HEAD'); $id = $this->_curl('/life/gate/v1/user/detail', null, 'HEAD');
$this->_try++; $this->_try++;
if ($id) { 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') public function _curl($url, $params, $method = 'GET')