You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
<?php
|
|
|
|
namespace app\base\logic\platform;
|
|
|
|
use app\base\model\platform\PlatformZixishi;
|
|
|
|
class Zixishi extends Base
|
|
{
|
|
|
|
/**
|
|
* 获取token
|
|
* @date 2022-11-21
|
|
*/
|
|
public function getAccessToken()
|
|
{
|
|
$zixishi_platform = get_zixishi_config();
|
|
|
|
$zixishi_model = new PlatformZixishi();
|
|
$token_model = new \zixishi\Token($zixishi_platform);
|
|
|
|
// 获取数据库token
|
|
$token = $zixishi_model->getAccessToken();
|
|
|
|
// 没有token 或 token即将过期 获取token并存库
|
|
if (empty($token['access_token']) || $token['access_token_time'] < time() - 120) {
|
|
|
|
// 获取access_token接口
|
|
$result = $token_model->getRAccessToken();
|
|
|
|
// 获取token失败
|
|
if (!isset($result['data']['token'])) {
|
|
return $result;
|
|
}
|
|
|
|
// token
|
|
$access_token = $result['data']['token'];
|
|
|
|
// 保存token
|
|
$res = $zixishi_model->updateAccessToken($access_token, $result['data']['expires_in']);
|
|
if (!$res) {
|
|
return sendErrorArray(3001, '保存token失败');
|
|
}
|
|
} else {
|
|
$access_token = $token['access_token'];
|
|
}
|
|
return $access_token;
|
|
}
|
|
}
|