PHP code example of mantoufan / yzhangateway

1. Go to this page and download the library: Download mantoufan/yzhangateway library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mantoufan / yzhangateway example snippets


$yzhanGateway = new YZhanGateway('Common');
$res = $yzhanGateway->request(array(
  'method' => 'GET',
  'url' => 'https://animechan.vercel.app/api/random'
));

$yzhanGateway = new YZhanGateway('Common');
$res = $yzhanGateway->cache()->request(array(
  'method' => 'GET',
  'url' => 'https://animechan.vercel.app/api/random',
  'cache' => array(
    'maxAge' => 86400
  )
));

$yzhanGateway = new YZhanGateway('Common');
$params = array(
  'method' => 'GET',
  'url' => 'https://animechan.vercel.app/api/random',
  'cache' => array(
    'maxAge' => 86400
  )
);
$res = $yzhanGateway->cache()->request($params);
if ($res === null) { // If results is bad, using getCache to get the yzhanCache instance
  $yzhanGateway->getCache()->delete($yzhanGateway->getKey($params)); // Delete, set by the key
}

$yzhanGateway = new YZhanGateway('BaiduCloud', array(
  'accessKey' => $_ENV['BAIDUCLOUD_ACCESSKEY'],
  'secretKey' => $_ENV['BAIDUCLOUD_SECRETKEY']
));
$res = $yzhanGateway->request(array(
  'method' => 'POST',
  'url' => 'http://cdn.baidubce.com/v2/cache/purge',
  'postFields' => array(
    'tasks' => array(
      array('url' => $_ENV['BAIDUCLOUD_TEST_URL'])
    )
  )
));

$yzhanGateway = new YZhanGateway('Cloudflare', array(
  'apiToken' => $_ENV['CLOUDFLARE_APITOKEN']
));
$res = $yzhanGateway->request(array(
  'method' => 'POST',
  'url' => 'https://api.cloudflare.com/client/v4/zones/' . $_ENV['CLOUDFLARE_REGION_ID'] . '/purge_cache',
  'postFields' => array(
    'files' => array($_ENV['CLOUDFLARE_TEST_URL'])
  )
));

$yzhanGateway = new YZhanGateway('Github', array(
  'accessToken' => $_ENV['GITHUB_ACCESS_TOKEN'],
  'userAgent' => $_ENV['GITHUB_USER_NAME']
));
$res = $yzhanGateway->request(array(
  'method' => 'GET',
  'url' => 'https://api.github.com/users/' . $_ENV['GITHUB_USER_NAME'] . '/events'
));

$yzhanGateway = new YZhanGateway('OpenAI', array(
  'apiKey' => $_ENV['OPENAI_APIKEY'],
  // 'organization' => $_ENV['OPENAI_ORGANIZATION'] // Optional
));
$res = $yzhanGateway->request(array(
  'method' => 'POST',
  'url' => 'https://api.openai.com/v1/completions',
  'postFields' => array(
    'model' => 'text-davinci-003',
    'prompt' => 'Hello',
    'temperature'=> 0 // Optional, 0 means the most certain results
  )
));

$yzhanGateway = new YZhanGateway('TencentCloud', array(
  'secretId' => $_ENV['TENCENTCLOUD_SECRET_ID'],
  'secretKey' => $_ENV['TENCENTCLOUD_SECRET_KEY']
));
$res = $yzhanGateway->request(array(
  'method' => 'POST',
  'url' => 'https://cvm.tencentcloudapi.com',
  'action' => 'DescribeInstances',
  'version' => '2017-03-12',
  'region' => 'ap-guangzhou',
  'postFields' => array(
    'Limit' => 1,
    'Filters' => array(
      array('Values' => array('未命名'), 'Name' => 'instance-name')
    ),
  )
));