123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\service\byte_dance;
- use think\Cache;
- class ByteDanceAccessToken implements ByteDanceInterface {
- protected $appId;
- protected $appSecret;
- protected $cacheName='cache_bytedance_access_token';
- public function get()
- {
- $token=Cache::get($this->cacheName);
- if(!$token){
- $request=ByteDance::httpPost('https://developer.toutiao.com/api/apps/v2/token',[
- 'appid'=>ByteDance::appId(),
- 'secret'=>ByteDance::appSecret(),
- 'grant_type'=>'client_credential',
- ]);
- $token=$request['access_token'];
- Cache::set($this->cacheName,$token,$request['expires_in']-10);
- }
- return $token;
- }
- public function getWangKa()
- {
- $token=Cache::get($this->cacheName);
- if(!$token){
- $request=ByteDance::httpPost('https://developer.toutiao.com/api/apps/v2/token',[
- 'appid'=>ByteDance::appIdTwo(),
- 'secret'=>ByteDance::appSecretTwo(),
- 'grant_type'=>'client_credential',
- ]);
- $token=$request['access_token'];
- Cache::set($this->cacheName,$token,$request['expires_in']-10);
- }
- return $token;
- }
- /**
- * @param mixed $appId
- */
- public function setAppId($appId)
- {
- $this->appId = $appId;
- return $this;
- }
- /**
- * @param mixed $appSecret
- */
- public function setAppSecret($appSecret)
- {
- $this->appSecret = $appSecret;
- return $this;
- }
- }
|