tesseract/crypto-sdk

Tesseract Crypto SDK PHP来自Tesseract Crypto API v2

0.3.0 2020-06-03 20:48 UTC

README

Build Status codecov Total Downloads

如何安装Tesseract Crypto SDK PHP

推荐通过Composer安装Tesseract Crypto SDK PHP。

    # Install Composer
    curl -sS https://getcomposer.org/installer | php
    

接下来,运行Composer命令安装Guzzle的最新稳定版本

    php composer.phar require tesseract/crypto-sdk
    

安装后,您需要包含Composer的自动加载器

    require 'vendor/autoload.php';

配置

<?php

return [
  
  /*
  |--------------------------------------------------------------------------
  | Default Base URL
  |--------------------------------------------------------------------------
  */
  'tesseract.crypto.baseUrl' => 'https://sandbox.tesseract.mx',
  
  /*
  |--------------------------------------------------------------------------
  | Default Access Key ID
  |--------------------------------------------------------------------------
  */
  'tesseract.crypto.access_key_id' => '[your_access_key_id]',
   
  /*
  |--------------------------------------------------------------------------
  | Default Secret Access Key
  |--------------------------------------------------------------------------
  */
  'tesseract.crypto.secret_access_key' => '[your_secret_access_key]',
   
  /*
  |--------------------------------------------------------------------------
  | Default Debug
  |--------------------------------------------------------------------------
  */
  'tesseract.crypto.debug' => false,
   
  /*
  |--------------------------------------------------------------------------
  | Default Timeout
  |--------------------------------------------------------------------------
  */
  'tesseract.crypto.timeout' => 5.000

];

如何使用

<?php

require 'vendor/autoload.php';

use Tesseract\Crypto\SDK\CryptoSDK;
use Tesseract\Crypto\SDK\Http\StatusCode;
use Tesseract\Crypto\SDK\Options\Config;
use Tesseract\Crypto\SDK\Options\HttpClientConfig;

$configs = include('config.php');

$httpClientConfig = new HttpClientConfig($configs[Config::BASE_URL], 
    $configs[Config::ACCESS_KEY_ID], 
    $configs[Config::SECRET_ACCESS_KEY], 
    $configs[Config::DEBUG], 
    $configs[Config::TIMEOUT]);

$sdk = new CryptoSDK($httpClientConfig);

$response = $sdk->auth();

if($response->getStatusCode() == StatusCode::OK)
{
    if($response->getBody()->isReadable())
        echo $response->getBody()->getContents();
}