PHP code example of pifeifei / easy-api
1. Go to this page and download the library: Download pifeifei/easy-api 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/ */
pifeifei / easy-api example snippets
$config = [
'config' => [
'app_key' => 'app key string',
'app_secret' => 'app secret string'
],
'request' => [
"uri" => 'https://httpbin.org/anything',
"sandbox_uri" => 'https://httpbin.org/anything/sandbox',
"method" => Pff\EasyApi\API::METHOD_JSON, // 默认请求方式,可选:GET, POST, JSON
"sign" => [
"position" => Pff\EasyApi\API::SIGN_POSITION_HEAD,
"key" => "sign",
"appends" => [
"sign_type" => 'MD5'
],
],
"signature" => Pff\EasyApi\Signature\MD5Signature::class, // 继承 \Pff\EasyApi\Signature\SignatureInterface::class
"formatter" => Pff\EasyApi\Format\HttpBinFormatter::class,
"cache" => Pff\EasyApi\Cache\Cache::class, // auth 获取 access_token 等数据后,保存数据时会用到
"format" => Pff\EasyApi\API::RESPONSE_FORMAT_JSON, // 响应信息格式化
]
];
$client = new Client($config);
$response = $client->request();
// get
$response = $client->method(Pff\EasyApi\API::METHOD_GET)
->path("any/path/to")
->setData(['a'=>'foo', 'b'=>'bar'])
->request();
// json post
$response = $client->path("any/path/to")
->setData(['a'=>'foo', 'b'=>'bar'])
->request();