alldebrid / alldebrid-php
PHP中Alldebrid API v4的简单包装器
Requires
- php: >=7.1
- ext-json: *
Requires (Dev)
- atoum/atoum: ^3.4
- atoum/reports-extension: ^3.0
This package is auto-updated.
Last update: 2024-09-19 01:21:00 UTC
README
PHP中Alldebrid API v4的简单抽象包装器。
需要PHP 7.1或更高版本。
文档
有关Alldebrid API的文档,请参阅此处。
PHP库文档可在本README中找到。还提供了一个示例文件夹,以展示库的使用方法。
安装
您可以通过两种方式安装alldebrid-php
,使用composer或下载并包含独立文件。
通过Composer
alldebrid-php
作为alldebrid/alldebrid-php
包在Packagist上可用
composer require alldebrid/alldebrid
然后添加自动加载器到您的应用程序中,使用以下行:require("vendor/autoload.php")
通过include
提供了此库的独立版本,只需下载并手动包含即可
include './alldebrid.standalone.php';
快速入门
身份验证
Alldebrid API需要代理和apikey来进行请求认证。代理是您的应用程序/库名称(文档)。
您可以在您的Alldebrid Apikey仪表板中查看、创建和管理您的API密钥,或者通过PIN流程(文档 / 示例)远程(带有用户操作)生成它们。
$agent = 'myAppName'; // Your project name $apikey = 'YYYYYY'; // Apikey $alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);
使用和错误处理
默认情况下,此库使用Go风格的错误处理,但您可以选择配置为使用Exception。
$agent = 'myAppName'; // Your project name $apikey = 'YYYYYY'; // Apikey $alldebrid = new \Alldebrid\Alldebrid($agent, $apikey); // Go-style, always return an array [ $response, $error ] [ $user, $error ] = $alldebrid->user(); if($error) { // Api call failed or returned an error $errorMessage = $user; die("Could not get user informations, error " . $error . " : " . $errorMessage . "\n"); } // No error, you can consume the response echo "Hello, " . $user['username'] . "\n";
使用异常使用库
$agent = 'myAppName'; // Your project name $apikey = 'YYYYYY'; // Apikey $alldebrid = new \Alldebrid\Alldebrid($agent, $apikey); $alldebrid->setErrorMode('exception'); try { $user = $alldebrid->user(); } catch(Exception $e) { die("Exception " . $e->getMessage() . "\n"); } // No error, you can consume the response echo "Hello, " . $user['username'] . "\n";
高级和低级使用
一旦设置了代理和apikey,此库提供多种方式使用Alldebrid API。
最低级别的使用是调用带有期望端点和参数的api()函数
$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey); $myLink = 'https://example.com/example'; [ $response, $error ] = $alldebrid->api('link/infos', ['link' => [ $myLink ] ]);
每个API端点都有自己的包装函数,您可以使用它,它处理适当的参数命名和一些响应检查
$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey); $myLink = 'https://example.com/example'; [ $response, $error ] = $alldebrid->linkInfos($myLink);
最后,对于链接、磁铁和PIN认证,提供了辅助对象以轻松与之交互
$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey); $myLink = 'https://example.com/example'; $link = $alldebrid->link($myLink); [ $response, $error ] = $link->infos(); // you can then call $link->unlock() if there is no error
此库的所有调用都在示例文件夹中进行了文档记录。
配置
某些选项可以调整此库的行为。包装器有一个公开的options数组属性,您可以更新它。
$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey); // By default retry=true and maxRetries=2, the library will retry failed request 2 times $alldebrid->options['retry'] = false; // Disable retry $alldebrid->options['maxRetries'] = 5; // Raise max retries // By default autoInit=false, the library wont make any api call you didn't request explicitly $alldebrid->options['autoInit'] = true; // Get user and hosts informations on wrapper creation // By default autoUnlockBestStreamQuality=false $alldebrid->options['autoUnlockBestStreamQuality'] = true; // On link with multiple stream options, the library will automatically unlock the highest quality source // By default ignoreRedirector=true $alldebrid->options['ignoreRedirector'] = true; // Flag to make the library handle redirectors // By default exceptions=false $alldebrid->options['exceptions'] = true; // Use Exception for error handling. Can also use $alldebrid->setErrorMode('exception');
获取帮助
如果您需要安装或使用库的帮助,请首先查阅Api文档,检查示例代码,然后如果您找不到问题的答案,请联系我们联系。
如果您在库中发现了错误或者希望添加新功能,请继续在此仓库中打开问题或拉取请求!