Swap.php 939 字节
<?php

namespace Lackoxygen\TiktokShop\Supervisor\Session;

use Lackoxygen\TiktokShop\Exception\ClientException;
use Lackoxygen\TiktokShop\Passage\ResultSet;

trait Swap
{
    public function refresh()
    {
        $app = app('tiktok.shop');
        try {
            /**
             * @var ResultSet $result
             */
            $result = $app->authorize->refresh($this->store->getRefreshToken());

            if ($result->isSuccess()) {
                $this->store->setAccessToken($result->get('access_token'));
                $this->store->setRefreshToken($result->get('refresh_token'));
                $this->store->setRefreshNum($this->store->getRefreshNum() + 1);
                $this->store->setCreatedAt(now());
                $this->store->setExpiredAt(now()->addMicroseconds($result->get('expired_in')));
            }
        } catch (ClientException $exception) {
            $this->discard();
        }
    }
}