jebanany/lvlup

API 客户端 LVL UP

1.0.5 2020-08-07 13:35 UTC

This package is auto-updated.

Last update: 2024-09-07 22:45:09 UTC


README

Biblioteka PHP obsługująca https://api.lvlup.pro/v4 oraz https://api.sandbox.lvlup.pro/v4

有关该库的讨论可在 LVL UP 论坛 上找到。

有关 LVL UP API v4 的更多信息,请参阅 LVL UP 论坛

要求

  • PHP 7+
  • curl (可选)

安装

要安装库,请使用 Composser

composer require jebanany/lvlup

如何使用

实现

use Jebanany\Lvlup\ApiClient;
require_once('vendor/autoload.php');

// Normalne używanie
$lvlup = new ApiClient('apikey');
// bez używania cURL
$lvlup = new ApiClient('apikey', false, false);

// Sandbox
$lvlup = new ApiClient('sandboxapikey', true);
// bez używania cURL
$lvlup = new ApiClient('sandboxapikey', true, false);

示例

1. 使用沙箱

在沙箱中生成新账户,创建支付,检查状态,更改状态,再次检查状态。

use Jebanany\Lvlup\ApiClient;

require_once('vendor/autoload.php');

try {
    // Pobieramy nowe dane do konta sandbox
    // zachowaj te dane do swoich następnych testów; nie generuj ich za każdym razem!
    $lvlupSandbox = new ApiClient(false, true);
    $sanboxUser = $lvlupSandbox->sandboxAccountCreate();

    echo "<pre>";
    echo "Dane dostępowe";
    echo "\n ID: " . $sanboxUser->id;
    echo "\n Username: " . $sanboxUser->username;
    echo "\n Password: " . $sanboxUser->password;
    echo "\n Email: " . $sanboxUser->email;
    echo "\n APIkey: " . $sanboxUser->apiKey;
    // zachowaj te dane do swoich następnych testów; nie generuj ich za każdym razem!

    // Mając dane konta sandbox tworzymy nową instancję klasy, tym razem z APIkey
    $lvlupSandbox = new ApiClient($sanboxUser->apiKey, true);

    // Generujemy nową płatność
    $payment = $lvlupSandbox->paymentsCreate(25.00);

    echo "\nDane o wygenerowanej płatności";
    echo "\n url: " . $payment->url;
    echo "\n id: " . $payment->id;

    // Sprawdzamy status płatności
    $status = $lvlupSandbox->paymentsStatus($payment->id);

    echo "\nStatus płatności przed opłaceniem";
    echo "\n payed: " . ($status->payed ? 'true' : 'false'); // false
    echo "\n amountStr: " . $status->amountStr;
    echo "\n amountInt: " . $status->amountInt;
    echo "\n amountWithFeeStr: " . $status->amountWithFeeStr;
    echo "\n amountWithFeeInt: " . $status->amountWithFeeInt;

    // Zmieniamy status płatności - opłacamy / ustawiamy jako opłacone
    $lvlupSandbox->sandboxPaymentAccept($payment->id);

    // Sprawdzamy status płatności ponownie
    $status = $lvlupSandbox->paymentsStatus($payment->id);
    echo "\nStatus płatności po opłaceniu";
    echo "\n payed: " . ($status->payed ? 'true' : 'false'); // true
    echo "\n amountStr: " . $status->amountStr;
    echo "\n amountInt: " . $status->amountInt;
    echo "\n amountWithFeeStr: " . $status->amountWithFeeStr;
    echo "\n amountWithFeeInt: " . $status->amountWithFeeInt;
    echo "</pre>";

} catch (Exception $e) {
    echo 'Kod błędu: <b>' . $e->getCode() . '</b> treść błędu: <b>' . $e->getMessage() . '</b>';
} catch (TypeError $e) {
    echo 'Kod błędu: <b>' . $e->getCode() . '</b> <br>treść błędu: <b>' . $e->getMessage() . '</b>';
}

2. 使用 try 和 catch 块

在失败的情况下,将生成 ExceptionTypeError (例如,函数所需的参数不是正确的类型,如 string 而不是 int)。在 Exception 错误的情况下,有辅助消息 (getMessage()) 和 HTTP 响应代码 (getCode()) - 如果请求已发出,则 getCode() 返回非零值,如果没有,则 getCode() 返回 0。

use Jebanany\Lvlup\ApiClient;

require_once('vendor/autoload.php');

try {
    // Bez APIkey
    $lvlup = new ApiClient(false);
    $sanboxUser = $lvlup->userMe(); // generuje Exception

} catch (Exception $e) {
    echo 'Kod błędu: <b>' . $e->getCode() . '</b> treść błędu: <b>' . $e->getMessage() . '</b>';
   // 
   // Kod błędu: 401 treść błędu: Unauthorized Error (Probably invalid API key)
   // 
} catch (TypeError $e) {
    echo 'Kod błędu: <b>' . $e->getCode() . '</b> <br>treść błędu: <b>' . $e->getMessage() . '</b>';
}

可用函数

grafanaPing()
grafanaRawQuery(array $rawDataQuery)
grafanaTimeseriesList()
grafanaTablesList()
ordersList(int $limit = null, int $afterId = null, int $beforeId = null)
partnerIpInfo(int $id)
paymentsBalance()
paymentsCreate($amount, string $redirectUrl = '', string $webhookUrl = '')
paymentsList(int $limit = null, int $afterId = null, int $beforeId = null)
paymentsStatus($paymentId)
reportPerformanceCreate($description = '')
sandboxAccountCreate()
sandboxPaymentAccept($paymentId)
servicesAttacksList(int $vpsIds, int $limit = null, int $afterId = null, int $beforeId = null)
servicesList()
servicesProxmoxGenerateCredentials(int $vpsId)
servicesUdpFilterStatus(int $vpsId)
servicesUdpFilterStatusSet(int $vpsId, bool $changeTo)
servicesUdpFilterWhitelist(int $vpsId)
servicesUdpFilterWhitelistRuleAdd(int $vpsId, int $portFrom, int $portTo, string $protocol)
servicesUdpFilterWhitelistRuleDel(int $vpsId, int $ruleId)
servicesVpsStart(int $vpsId)
servicesVpsState(int $vpsId)
servicesVpsStop(int $vpsId)
userMe()
userLogList(int $limit = null, int $afterId = null, int $beforeId = null)
userReferralCreate()
userReferralList()

方法描述

展开方法描述

Grafana

  • grafanaPing() 如果 Grafana 响应,则返回 "OK"

  • grafanaRawQuery(array $rawDataQuery) 与 Grafana 兼容的指标

  • grafanaTimeseriesList() 可用时间序列

  • grafanaTablesList() 可用表

订单

  • ordersList 具有分页的订单列表
// ordersList(int $limit = null, int $afterId = null, int $beforeId = null)
// return object
$lvlup->ordersList(); //return object

合作伙伴

  • partnerIpInfo
// partnerIpInfo($ip)
// return object
$lvlup->partnerIpInfo('203.0.113.24'); 

支付

  • paymentsBalance 在钱包中收集的虚拟资金数量
// paymentsBalance()
// return object
$lvlup->paymentsBalance(); //object
  • paymentsCreate 生成新的支付
// paymentsCreate($amount, string $redirectUrl = '', string $webhookUrl = '')
// return object
$lvlup->paymentsCreate(1.5); 
$lvlup->paymentsCreate(1); 
$lvlup->paymentsCreate(1.62); 
$lvlup->paymentsCreate('1.56'); // string jako kwota również działa
$lvlup->paymentsCreate(17, 'http://example.com/redirect', 'http://example.com/webhook'); 
  • paymentsList 已接受的支付列表
// paymentsList(int $limit = null, int $afterId = null, int $beforeId = null)
// return object
$lvlup->paymentsList(); 
$lvlup->paymentsList(50, 5); 
$lvlup->paymentsList(50, null, 5); 
  • paymentsStatus 现有支付的状态
// paymentsStatus($paymentId)
// return object
$lvlup->paymentsStatus('paymentId'); 

报告

  • reportPerformanceCreate 发送关于服务异常行为报告
// reportPerformanceCreate($description = '')
// return NULL
$lvlup->reportPerformanceCreate('Problems with MC server. TPS: 9/20'); 
$lvlup->reportPerformanceCreate('TS packetloss: 24%'); 

沙箱

  • sandboxAccountCreate 创建新的沙箱账户
// sandboxAccountCreate()
// return object
$lvlup->sandboxAccountCreate(); 
  • sandboxPaymentAccept 将支付状态更改为已支付
// sandboxPaymentAccept($paymentId)
// return NULL
$lvlup->sandboxPaymentAccept('paymentId'); 

服务

  • servicesAttacksList 攻击列表
// servicesAttacksList(int $vpsIds, int $limit = null, int $afterId = null, int $beforeId = null)
// return object
$lvlup->servicesAttacksList(123); 
$lvlup->servicesAttacksList(123, 50); 
// etc
  • servicesList 服务列表
// servicesList()
// return object
$lvlup->servicesList();
  • servicesProxmoxGenerateCredentials 生成 Proxmox 控制面板的访问数据
// servicesProxmoxGenerateCredentials($vpsId)
// return object
$lvlup->servicesProxmoxGenerateCredentials(123);
  • servicesUdpFilterStatus UDP 过滤当前状态
// servicesUdpFilterStatus($vpsId)
// return object
$lvlup->servicesUdpFilterStatus(123);
  • servicesUdpFilterStatusSet 设置 UDP 过滤当前状态
// servicesUdpFilterStatusSet(int $vpsId, bool $changeTo)
// return object
$lvlup->servicesUdpFilterStatusSet(123, true); //true - on; false - off
  • servicesUdpFilterWhitelist UDP 过滤例外
// servicesUdpFilterWhitelist(int $vpsId)
// return object
$lvlup->servicesUdpFilterWhitelist(123);
  • servicesUdpFilterWhitelistRuleAdd 添加新的 UDP 过滤例外
// servicesUdpFilterWhitelistRuleAdd(int $vpsId, int $portFrom, int $portTo, string $protocol)
// $allowedProtocols = ['arkSurvivalEvolved', 'arma', 'gtaMultiTheftAutoSanAndreas', 'gtaSanAndreasMultiplayerMod', 'hl2Source', 'minecraftPocketEdition', 'minecraftQuery', 'mumble', 'rust', 'teamspeak2', 'teamspeak3', 'trackmaniaShootmania', 'other'];
// return object
$lvlup->servicesUdpFilterWhitelistRuleAdd(123, 9987, 9987, 'teamspeak3');
$lvlup->servicesUdpFilterWhitelistRuleAdd(123, 9526, 10465, 'other');
  • servicesUdpFilterWhitelistRuleDel 删除 UDP 过滤例外
// servicesUdpFilterWhitelistRuleDel(int $vpsId, int $ruleId)
// return object
$lvlup->servicesUdpFilterWhitelistRuleDel(123, 456);
  • servicesVpsStart 启动 VPS
// servicesVpsStart(int $vpsId)
// return object
$lvlup->servicesVpsStart(123);
  • servicesVpsState VPS 当前状态
// servicesVpsState(int $vpsId)
// return object
$lvlup->servicesVpsState(123);
  • servicesVpsStop 停止 VPS
// servicesVpsStop(int $vpsId)
// return object
$lvlup->servicesVpsStop(123);

用户

  • userMe APIkey 的当前用户信息
// userMe()
// return object
$lvlup->userMe();
  • userLogList
// userLogList(int $limit = null, int $afterId = null, int $beforeId = null)
// return object
$lvlup->userLogList();
$lvlup->userLogList(50);
// etc
  • userReferralCreate 生成新的推荐代码
// userReferralCreate()
// return object
$lvlup->userReferralCreate();
  • userReferralList 推荐代码列表
// userReferralList()
// return object
$lvlup->userReferralList();