作者 lackoxygen

add all

/vendor/
.idea
composer.lock
\ No newline at end of file
... ...
{
"name": "lackoxygen/tiktok_open_sdk",
"type": "library",
"description": "抖音开放平台-sdk",
"autoload": {
"psr-4": {
"Lackoxygen\\TiktokOpen\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Lackoxygen\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "lackoxygen",
"email": "jingze666@gmail.com"
}
],
"require": {
"pimple/pimple": "^3.5",
"guzzlehttp/guzzle": "^7.4",
"illuminate/support": "^8 || ^9",
"ext-openssl": "*"
}
}
... ...
<?php
return [
//小程序
'mini' => [
'appid' => '',
'secret' => '',
],
'wap' => [
'app_key' => '',
'app_secret' => ''
],
];
... ...
<?php
namespace Lackoxygen\TiktokOpen;
use Lackoxygen\TiktokOpen\Base\Config;
use Lackoxygen\TiktokOpen\Mini\MiniProvider;
use Lackoxygen\TiktokOpen\Wap\WapProvider;
use Pimple\Container;
/**
* @method WapProvider wap()
* @method MiniProvider mini()
*/
class Application extends Container
{
/**
* @var array|string[]
*/
private array $providers = [
'wap' => WapProvider::class,
'mini' => MiniProvider::class
];
/**
* @param Config $config
*/
public function __construct(Config $config)
{
parent::__construct();
$this['config'] = $config;
$this[__CLASS__] = new \SplFixedArray(2);
}
/**
* @param $name
* @param $provider
* @return void
*/
protected function makeProvider($name, $provider)
{
if ($this->offsetExists($name)) {
return;
}
parent::register(new $provider($name));
}
/**
* @param $name
* @param array $arguments
* @return $this|mixed
*/
public function __call($name, array $arguments = [])
{
[$provider, $service] = $this[__CLASS__];
if ($provider && $service) {
if ($service === $name) {
return $this[$provider . '.' . $service];
}
goto rebuild;
} elseif (!$provider) {
$providerName = $this->providers[$name];
$this->makeProvider($name, $providerName);
$provider = $name;
$this[__CLASS__][0] = $provider;
return $this;
} else {
rebuild:
$service = $name;
$this[__CLASS__][1] = $service;
return $this[$provider . '.' . $service];
}
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base;
use Lackoxygen\TiktokOpen\Application;
use GuzzleHttp\Client;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
abstract class AbstractProvider implements ServiceProviderInterface
{
/**
* @var string $alias
*/
protected string $alias;
/**
* @var array
*/
private array $preServices = [];
/**
* @var array
*/
protected array $services = [];
/**
* @var Container $application
*/
protected Container $application;
/**
* @param string $alias
*/
public function __construct(string $alias)
{
$this->alias = $alias;
$this->addPreService('guzzleHttp', function (Application $app) {
return new Client(
[
'base_uri' => $app['config']->getUrl(),
'timeout' => $app['config']->getTimeout()
]
);
});
}
/**
* @param Container $pimple
* @return void
*/
public function register(Container $pimple)
{
$this->application = $pimple;
$this->registerServices($this->preServices, function (string $key) {
return $key;
});
$this->registerServices($this->services, function (string $key) {
return $this->alias . '.' . $key;
});
$this->application[$this->alias] = $this;
}
/**
* @return array
*/
protected function getServices(): array
{
return array_merge(
$this->preServices,
$this->services
);
}
protected function addPreService($name, $service)
{
$this->preServices[$name] = $service;
}
/**
* @param $services
* @param \Closure $callback
* @return void
*/
protected function registerServices($services, \Closure $callback)
{
foreach ($services as $key => $value) {
if ($value instanceof \Closure) {
$service = call_user_func($value, $this->application);
} else {
$service = new $value($this->application);
}
$this->application[$callback($key)] = $service;
}
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base;
use Illuminate\Support\Facades\Cache as LaravelCache;
class Cache
{
protected const PREFIX = 'tiktok.open.';
public static function put(string $key, $value, $ttl): bool
{
return LaravelCache::put(self::PREFIX . $key, $value, $ttl);
}
public static function get(string $key)
{
return LaravelCache::get(self::PREFIX . $key);
}
public static function has(string $key): bool
{
return LaravelCache::has(self::PREFIX . $key);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Client;
use Lackoxygen\TiktokOpen\Application;
use Lackoxygen\TiktokOpen\Base\Event\Fail;
use Lackoxygen\TiktokOpen\Base\Event\Request;
use Lackoxygen\TiktokOpen\Base\Event\Response;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
use Lackoxygen\TiktokOpen\Base\Traits\BaseClient;
use Lackoxygen\TiktokOpen\Wap\Listener;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Event;
class Client extends ServiceManager
{
use BaseClient;
private string $requestOption = '';
private bool $withSession = false;
public function __construct(Application $app)
{
parent::__construct($app);
$this->listen();
}
protected function listen()
{
Event::listen(Request::class, [Listener::class, 'request']);
Event::listen(Response::class, [Listener::class, 'response']);
Event::listen(Fail::class, [Listener::class, 'fail']);
}
public function asForm(): Client
{
$this->requestOption = RequestOptions::FORM_PARAMS;
return $this;
}
public function asJson(): Client
{
$this->requestOption = RequestOptions::JSON;
return $this;
}
public function asMultipart(): Client
{
$this->requestOption = RequestOptions::MULTIPART;
return $this;
}
public function withSession(): Client
{
$this->withSession = true;
return $this;
}
public function refresh()
{
$this->requestOption = '';
$this->withSession = false;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Client;
use GuzzleHttp\RequestOptions;
class Request
{
protected string $method;
protected string $format;
protected string $path;
protected array $data = [];
protected array $headers = [];
protected bool $withSession;
public function __construct(
string $method,
string $format,
string $path,
array $data,
bool $withSession
)
{
$this->setMethod($method);
$this->format = $format;
$this->path = $path;
$this->data = $data;
$this->withSession = $withSession;
}
/**
* @param string $format
*/
public function setFormat(string $format): void
{
$this->format = $format;
}
/**
* @param string $method
*/
public function setMethod(string $method): void
{
$this->method = strtoupper($method);
}
/**
* @param string $path
*/
public function setPath(string $path): void
{
$this->path = $path;
}
/**
* @param array $data
*/
public function setData(array $data): void
{
$this->data = $data;
}
/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}
/**
* @return string
*/
public function getPath(): string
{
return $this->path;
}
/**
* @return array
*/
public function getData(): array
{
return $this->data;
}
/**
* @return string
*/
public function getFormat(): string
{
return $this->format;
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->headers;
}
/**
* @return bool
*/
public function isWithSession(): bool
{
return $this->withSession;
}
protected function defaultFormat(): string
{
if ('GET' === $this->method) {
return RequestOptions::QUERY;
} else {
return RequestOptions::FORM_PARAMS;
}
}
public function toArray(): array
{
$format = $this->format ?: $this->defaultFormat();
return [
RequestOptions::HEADERS => $this->headers,
$format => $this->data,
];
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base;
class Config
{
private string $url = '';
private string $appKey = '';
private string $appSecret = '';
protected float $timeout = 5.0;
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url): void
{
$this->url = $url;
}
/**
* @return string
*/
public function getAppKey(): string
{
return $this->appKey;
}
/**
* @param string $appKey
*/
public function setAppKey(string $appKey): void
{
$this->appKey = $appKey;
}
/**
* @return string
*/
public function getAppSecret(): string
{
return $this->appSecret;
}
/**
* @param string $appSecret
*/
public function setAppSecret(string $appSecret): void
{
$this->appSecret = $appSecret;
}
/**
* @return float
*/
public function getTimeout(): float
{
return $this->timeout;
}
/**
* @param float $timeout
*/
public function setTimeout(float $timeout): void
{
$this->timeout = $timeout;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Event;
use Illuminate\Foundation\Events\Dispatchable;
class Fail
{
use Dispatchable;
public \Throwable $exception;
public function __construct($exception)
{
$this->exception = $exception;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Event;
use Lackoxygen\TiktokOpen\Application;
use Illuminate\Foundation\Events\Dispatchable;
class Request
{
use Dispatchable;
public \App\Pkgs\TiktokOpen\Base\Client\Request $request;
public Application $application;
public function __construct(Application $application, \App\Pkgs\TiktokOpen\Base\Client\Request $request)
{
$this->application = $application;
$this->request = $request;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Event;
use Illuminate\Foundation\Events\Dispatchable;
use Psr\Http\Message\ResponseInterface;
class Response
{
use Dispatchable;
public ResponseInterface $response;
public function __construct(ResponseInterface $response)
{
$this->response = $response;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Exception;
class AnswerException extends Exception
{
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Exception;
class Exception extends \Exception
{
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base;
use Lackoxygen\TiktokOpen\Application;
class ServiceManager
{
protected Application $app;
/**
* @param Application $app
*/
public function __construct(Application $app)
{
$this->app = $app;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Traits;
use Lackoxygen\TiktokOpen\Base\Client\Request;
use Lackoxygen\TiktokOpen\Base\Event\Fail as FailEvent;
use Lackoxygen\TiktokOpen\Base\Event\Request as RequestEvent;
use Lackoxygen\TiktokOpen\Base\Event\Response as ResponseEvent;
use Lackoxygen\TiktokOpen\Base\Utils\Json;
use GuzzleHttp\Exception\ClientException;
trait BaseClient
{
public function get($url, $params = [])
{
return $this->request('GET', $url, $params);
}
public function post($url, $params = [])
{
return $this->request('POST', $url, $params);
}
public function put($url, $params = [])
{
return $this->request('PUT', $url, $params);
}
public function delete($url, $params = [])
{
return $this->request('DELETE', $url, $params);
}
public function request(string $method, string $path, array $data = [])
{
$request = new Request(
$method,
$this->requestOption,
$path,
$data,
$this->withSession
);
RequestEvent::dispatch($this->app, $request);
try {
$response = $this->app['guzzleHttp']->request(
$method,
$path,
$request->toArray()
);
ResponseEvent::dispatch($response);
$response->getBody()->rewind();
return Json::unmarshal($response->getBody()->getContents());
} catch (ClientException $exception) {
FailEvent::dispatch($exception);
} finally {
$this->refresh();
}
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Base\Utils;
class Json
{
public static function marshal(array $array, $flags = JSON_UNESCAPED_UNICODE)
{
return \json_encode($array, $flags);
}
public static function unmarshal(string $value)
{
return \json_decode($value, true);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Mini;
use Lackoxygen\TiktokOpen\Base\AbstractProvider;
use Lackoxygen\TiktokOpen\Base\Client\Client;
use Lackoxygen\TiktokOpen\Mini\OAuth\OAuth;
/**
* @method OAuth oauth()
*/
class MiniProvider extends AbstractProvider
{
protected string $alias = 'mini';
protected array $services = [
'oauth' => OAuth::class,
];
public function __construct(string $alias)
{
parent::__construct($alias);
$this->addPreService('client', Client::class);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Mini\OAuth;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class OAuth extends ServiceManager
{
public function jsCode(string $code = '', string $anonymousCode = '')
{
return $this->app['client']->asJson()
->post(
'api/apps/v2/jscode2session',
[
'appid' => $this->app['config']->getAppKey(),
'secret' => $this->app['config']->getAppSecret(),
'code' => $code,
'anonymous_code' => $anonymousCode,
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen;
use Illuminate\Support\ServiceProvider;
use Lackoxygen\TiktokOpen\Base\Config;
class TiktokOpenServiceProvider extends ServiceProvider
{
protected array $provides = ['mini', 'wap'];
/**
* @return void
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$configPath = __DIR__ . '/../publish/tiktok.open.php';
$this->publishes([
$configPath => config_path('tiktok.open.php')
], 'lackoxygen-tiktok-open');
}
}
/**
* @return void
*/
public function register()
{
foreach ($this->provides as $provide) {
$alias = sprintf('tiktok.%s', $provide);
$this->app->singleton($alias, function () use ($alias) {
$provideConfig = \config($alias);
$config = new Config();
$config->setAppKey($provideConfig['app_key']);
$config->setAppSecret($provideConfig['app_secret']);
$config->setUrl('https://open.douyin.com');
return (new Application($config))->wap();
});
}
}
/**
* @return string[]
*/
public function provides(): array
{
return $this->provides;
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Data\Content;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class Fans extends ServiceManager
{
public function data(string $openid, string $accessToken)
{
return $this->app['client']
->get(
'/fans/data/',
[
'open_id' => $openid,
'access_token' => $accessToken,
]
);
}
public function source(string $openid, string $accessToken)
{
return $this->app['client']
->get(
'/data/extern/fans/source/',
[
'open_id' => $openid,
'access_token' => $accessToken,
]
);
}
public function favourite(string $openid, string $accessToken)
{
return $this->app['client']
->get(
'/data/extern/fans/favourite/',
[
'open_id' => $openid,
'access_token' => $accessToken,
]
);
}
public function comment(string $openid, string $accessToken)
{
return $this->app['client']
->get(
'/data/extern/fans/comment/',
[
'open_id' => $openid,
'access_token' => $accessToken,
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Data\Content;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class HotSearch extends ServiceManager
{
public function sentences(string $accessToken)
{
return $this->app['client']
->get(
'/hotsearch/sentences/',
[
'access_token' => $accessToken,
]
);
}
public function trendingSentences(string $accessToken, int $cursor, int $count)
{
return $this->app['client']
->get(
'/hotsearch/trending/sentences/',
[
'access_token' => $accessToken,
'cursor' => $cursor,
'count' => $count
]
);
}
public function videos(string $accessToken, string $hotSentence)
{
return $this->app['client']
->get(
'/hotsearch/videos/',
[
'access_token' => $accessToken,
'hot_sentence' => $hotSentence,
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Data\Content;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class Star extends ServiceManager
{
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Data\Content;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class User extends ServiceManager
{
public function item(string $openid, string $accessToken, int $dateType)
{
return $this->app['client']
->get(
'/data/external/user/item/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'date_type' => $dateType
]
);
}
public function fans(string $openid, string $accessToken, int $dateType)
{
return $this->app['client']
->get(
'/data/external/user/fans/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'date_type' => $dateType
]
);
}
public function like(string $openid, string $accessToken, int $dateType)
{
return $this->app['client']
->get(
'/data/external/user/like/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'date_type' => $dateType
]
);
}
public function comment(string $openid, string $accessToken, int $dateType)
{
return $this->app['client']
->get(
'/data/external/user/comment/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'date_type' => $dateType
]
);
}
public function share(string $openid, string $accessToken, int $dateType)
{
return $this->app['client']
->get(
'/data/external/user/share/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'date_type' => $dateType
]
);
}
public function profile(string $openid, string $accessToken, int $dateType)
{
return $this->app['client']
->get(
'/data/external/user/profile/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'date_type' => $dateType
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Data\Content;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class Video extends ServiceManager
{
public function base(string $openid, string $accessToken, string $itemId)
{
return $this->app['client']
->get(
'/data/external/item/base/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'item_id' => $itemId
]
);
}
public function like(string $openid, string $accessToken, string $itemId, int $dateType)
{
return $this->app['client']
->get(
'/data/external/item/base/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'item_id' => $itemId,
'date_type' => $dateType
]
);
}
public function comment(string $openid, string $accessToken, string $itemId, int $dateType)
{
return $this->app['client']
->get(
'/data/external/item/comment/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'item_id' => $itemId,
'date_type' => $dateType
]
);
}
public function play(string $openid, string $accessToken, string $itemId, int $dateType)
{
return $this->app['client']
->get(
'/data/external/item/play/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'item_id' => $itemId,
'date_type' => $dateType
]
);
}
public function share(string $openid, string $accessToken, string $itemId, int $dateType)
{
return $this->app['client']
->get(
'/data/external/item/share/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'item_id' => $itemId,
'date_type' => $dateType
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Data;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
use Lackoxygen\TiktokOpen\Wap\Data\Content\Fans;
use Lackoxygen\TiktokOpen\Wap\Data\Content\HotSearch;
use Lackoxygen\TiktokOpen\Wap\Data\Content\Star;
use Lackoxygen\TiktokOpen\Wap\Data\Content\User;
use Lackoxygen\TiktokOpen\Wap\Data\Content\Video;
/**
* @method User user()
* @method Video video()
* @method Fans fans()
* @method HotSearch hotSearch()
* @method Star star()
*/
class Data extends ServiceManager
{
protected array $services = [
'user' => User::class,
'video' => Video::class,
'fans' => Fans::class,
'hotSearch' => HotSearch::class,
'star' => Star::class
];
public function __call($name, $arguments)
{
$service = $this->services[$name];
return new $service($this->app);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Js;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class Js extends ServiceManager
{
public function ticket()
{
return $this->app['client']->withSession()->get(
'/js/getticket'
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap;
use Lackoxygen\TiktokOpen\Base\Event\Request;
use Lackoxygen\TiktokOpen\Base\Event\Response;
use Lackoxygen\TiktokOpen\Base\Event\Fail;
class Listener
{
public function request(Request $event)
{
if ($event->request->isWithSession()) {
$event->request->setData(
array_merge(
$event->request->getData(),
[
'access_token' => $event->application['wap.session']->accessToken
]
)
);
}
}
public function response(Response $event)
{
}
public function fail(Fail $event)
{
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\OAuth;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class OAuth extends ServiceManager
{
public function accessToken(string $code)
{
return $this->app['client']->asForm()->post('/oauth/access_token/', [
'grant_type' => 'authorization_code',
'client_key' => $this->app['config']->getAppKey(),
'client_secret' => $this->app['config']->getAppSecret(),
'code' => $code
]);
}
public function connect(string $scope, string $redirectUri, string $optionalScope = '', string $state = '')
{
return $this->app['client']->get(
'/platform/oauth/connect/', [
'client_key' => $this->app['config']->getAppKey(),
'response_type' => 'code',
'scope' => $scope,
'optionalScope' => $optionalScope,
'redirect_uri' => $redirectUri,
'state' => $state
]
);
}
public function renewRefreshToken(string $refreshToken)
{
return $this->app['client']->asForm()->post(
'/oauth/renew_refresh_token/',
[
'client_key' => $this->app['config']->getAppKey(),
'refresh_token' => $refreshToken
]
);
}
public function clientToken()
{
return $this->app['client']->asForm()->post(
'/oauth/client_token/',
[
'client_key' => $this->app['config']->getAppKey(),
'client_secret' => $this->app['config']->getAppSecret(),
'grant_type' => 'client_credential'
]
);
}
public function refreshToken(string $refreshToken)
{
return $this->app['client']->asForm()->post(
'/oauth/refresh_token/',
[
'client_key' => $this->app['config']->getAppKey(),
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken
]
);
}
public function authorizeV2($scope, $redirectUri, $state)
{
return $this->app['client']->get(
'/oauth/authorize/v2/',
[
'client_key' => $this->app['config']->getAppKey(),
'response_type' => 'code',
'scope' => $scope,
'redirect_uri' => $redirectUri,
'state' => $state
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap;
use Lackoxygen\TiktokOpen\Base\Cache;
use Lackoxygen\TiktokOpen\Base\Exception\AnswerException;
use Lackoxygen\TiktokOpen\Base\Exception\Exception;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
/**
* @property string $accessToken
* @property int $issueTime
* @property int $expiresIn
*/
class Session extends ServiceManager
{
/**
* @var string $name
*/
protected string $name = 'wap.session';
/**
* @throws Exception
*/
private function generateToken()
{
$response = $this->app['wap.oauth']->clientToken();
try {
$this->storeResponse($response);
} catch (AnswerException $e) {
throw new Exception(
sprintf('Token creation exception, %s', $e->getMessage())
);
}
}
/**
* @throws AnswerException
*/
private function storeResponse(array $response): void
{
$data = Arr::get($response, 'data', []);
if (0 !== Arr::get($data, 'error_code')) {
throw new AnswerException(Arr::get($response, 'message'));
}
$expiresIn = (int)Arr::get($data, 'expires_in');
$payload = [
'access_token' => $data['access_token'],
'issue_time' => time(),
'expires_in' => $expiresIn,
];
Cache::put(
$this->name,
$payload,
$expiresIn - 30
);
}
protected function get(string $key)
{
if (!Cache::has($this->name)) {
$this->generateToken();
}
$payload = Cache::get($this->name);
return $payload[$key];
}
public function __get($name)
{
$key = Str::snake($name);
return $this->get($key);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\User;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class User extends ServiceManager
{
public function info(string $openid, string $accessToken)
{
return $this->app['client']->get(
'/oauth/userinfo/',
[
'open_id' => $openid,
'access_token' => $accessToken
]
);
}
public function fansList(string $openid, int $cursor, int $count, string $accessToken)
{
return $this->app['client']->get(
'/fans/list/',
[
'open_id' => $openid,
'cursor' => $cursor,
'count' => $count,
'access_token' => $accessToken,
]
);
}
public function followList(string $openid, int $cursor, int $count, string $accessToken)
{
return $this->app['client']->get(
'/following/list/',
[
'open_id' => $openid,
'cursor' => $cursor,
'count' => $count,
'access_token' => $accessToken
]
);
}
public function fansCheck(string $openid, string $followerOpenId, string $accessToken)
{
return $this->app['client']->get(
'/fans/check/',
[
'open_id' => $openid,
'follower_open_id' => $followerOpenId,
'access_token' => $accessToken
]
);
}
public function decryptMobile($encryptedMobile)
{
$iv = substr($this->app['config']->getAppSecret(), 0, 16);
return \openssl_decrypt($encryptedMobile,
'aes-256-cbc',
$this->app['config']->getAppSecret(),
0,
$iv);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap\Video;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
class Video extends ServiceManager
{
public function videoList(string $openid, string $accessToken, int $cursor, int $count)
{
return $this->app['client']
->get(
'/video/list/',
[
'open_id' => $openid,
'access_token' => $accessToken,
'cursor' => $cursor,
'count' => $count,
]
);
}
public function videoData(string $openid, string $accessToken)
{
return $this->app['client']->asJson()->post(
'/video/data/',
[
'open_id' => $openid,
'access_token' => $accessToken,
]
);
}
public function shareId(bool $needCallback, string $sourceStyleId, string $defaultHashtag, string $linkParam)
{
return $this->app['client']->withSession()->get(
'/share-id/',
[
'need_callback' => $needCallback,
'source_style_id' => $sourceStyleId,
'default_hashtag' => $defaultHashtag,
'link_param' => $linkParam,
]
);
}
public function poiSearchKeyword($accessToken, int $cursor, int $count, string $keyword, string $city)
{
return $this->app['client']->get(
'/poi/search/keyword/',
[
'access_token' => $accessToken,
'cursor' => $cursor,
'count' => $count,
'keyword' => $keyword,
'city' => $city,
]
);
}
public function videoSource(string $openid, string $accessToken)
{
return $this->app['client']->asJson()->post(
'/video/source/',
[
'open_id' => $openid,
'access_token' => $accessToken,
]
);
}
}
... ...
<?php
namespace Lackoxygen\TiktokOpen\Wap;
use Lackoxygen\TiktokOpen\Base\AbstractProvider;
use Lackoxygen\TiktokOpen\Base\Client\Client;
use Lackoxygen\TiktokOpen\Wap\{Data\Data, Js\Js, OAuth\OAuth, User\User, Video\Video};
/**
* @method OAuth oauth()
* @method Js js()
* @method User user()
* @method Video video()
* @method Data data()
* @method Session session()
*/
class WapProvider extends AbstractProvider
{
protected string $alias = 'wap';
protected array $services = [
'oauth' => OAuth::class,
'js' => Js::class,
'user' => User::class,
'video' => Video::class,
'data' => Data::class,
'session' => Session::class
];
public function __construct(string $alias)
{
parent::__construct($alias);
$this->addPreService('client', Client::class);
}
}
... ...