openprovider/rest-client-php

此包的最新版本(v2.0.2-beta)没有可用的许可证信息。

Openprovider API 的 HTTP 客户端

v2.0.2-beta 2024-01-23 09:38 UTC

This package is auto-updated.

Last update: 2024-08-27 16:00:40 UTC


README

Openprovider API 的 PHP 客户端

描述

此软件是一个 PHP 客户端,用于操作 Openprovider API

目前 API 已经足够稳定以供使用,但请注意,在测试阶段我们可能还会做出破坏性的更改。

请使用 v1beta 分支/版本

使用方法

  1. 如果您项目文件夹中没有 composer.json,请使用以下命令创建它
    composer init
  2. 将 composer 的最小稳定性设置为 dev
    composer config minimum-stability dev
  3. 将此包作为任何其他 PHP 库包含进来
    composer require openprovider/rest-client-php:dev-v1beta
  4. 通过 Client 类访问 API
    <?php
    
    // Include autoloader.
    require __DIR__ . '/vendor/autoload.php';
    
    use Openprovider\Api\Rest\Client\Auth\Model\AuthLoginRequest;
    use Openprovider\Api\Rest\Client\Base\Configuration;
    use Openprovider\Api\Rest\Client\Client;
    use GuzzleHttp\Client as HttpClient;
    
    // Create new http client.
    $httpClient = new HttpClient();
    
    // Create new configuration.
    $configuration = new Configuration();
    
    // Build api client for using created client & configuration.
    $client = new Client($httpClient, $configuration);
    
    // Our credentials;
    $username = 'user';
    $password = 'pass';
    
    // Retrieve token for further using.
    $loginResult = $client->getAuthModule()->getAuthApi()->login(
    	new AuthLoginRequest([
    		'username' => $username,
    		'password' => $password,
    	])
    );
    
    // Set token to configuration (it will update the $client).
    $configuration->setAccessToken($loginResult->getData()->getToken());
    
    // Use this client for API calls.
    $result = $client->getTldModule()->getTldServiceApi()->getTld('com');
    
    // Operate with the result.
    print_r($result);
  5. 在 ./examples 目录中查看更多复杂示例。