pifeifei / easy-api
easy api client.
v0.1.7
2024-03-15 14:57 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- ext-openssl: *
- ext-simplexml: *
- composer/ca-bundle: ^1.2
- guzzlehttp/guzzle: ^6.5|^7.3
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- symfony/cache: ^4.3|^5.0|^6.0|^7.0
- symfony/polyfill: ^1.26
- symfony/serializer: ^4.3|^5.0|^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.9
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^3.4|^4.0|^5.0|^6.0|^7.0
- vlucas/phpdotenv: ^4.2|^5.0
README
一个容易上手的 api 客户端工具
Requirement
- PHP >= 7.4
- Composer
- openssl 拓展(建议)
- fileinfo 拓展(建议)
Installation
composer require "pifeifei/easy-api"
Usage
$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();
把上面代码封装一下会更好用,可以参考 tests/Feature/Clients/WechatClient
test
phpunit # phpunit --list-groups # 微信开放平台测试 #php -S 0.0.0.0:8080 -t ./tests/stubs/wechat #phpunit --group wechat