From e3f2a69a002a34b1cd1b41e3a2be1f4fba80c9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Thu, 1 Mar 2018 17:57:25 +0800 Subject: [PATCH] init --- .gitignore | 2 + composer.json | 8 + composer.lock | 1194 +++++++++++++++++ src/Client.php | 61 + src/Middleware/InternalApi.php | 65 + .../InternalApiServiceProvider.php | 27 + 6 files changed, 1357 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 src/Client.php create mode 100644 src/Middleware/InternalApi.php create mode 100644 src/ServiceProvider/InternalApiServiceProvider.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f33dd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor/ +.idea/ \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8bc629e --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "name": "pd_arch/inner_api", + "type": "library", + "require": { + "guzzlehttp/guzzle": "^6.3", + "illuminate/http": "^5.6" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..9ce6f6c --- /dev/null +++ b/composer.lock @@ -0,0 +1,1194 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "39f37c2acb3bdfa2071a04dec1c50df6", + "packages": [ + { + "name": "doctrine/inflector", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/doctrine/inflector/5527a48b7313d15261292c149e55e26eae771b0a.zip", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2018-01-09T20:05:19+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "6.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/guzzle/guzzle/f4db5a78a5ea468d4831de7f0bf9d9415e348699.zip", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0 || ^5.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2017-06-22T18:50:49+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/guzzle/promises/a59da6cf61d80060647ff4d3eb2c03a2bc694646.zip", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/guzzle/psr7/f5b8a8512e2b58b0071a7280e39f14f72e05d87c.zip", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, + { + "name": "illuminate/contracts", + "version": "v5.6.5", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "00a8296c63b6429eb8705d2700c2436ea193c553" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/illuminate/contracts/00a8296c63b6429eb8705d2700c2436ea193c553.zip", + "reference": "00a8296c63b6429eb8705d2700c2436ea193c553", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/container": "~1.0", + "psr/simple-cache": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.6-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Contracts package.", + "homepage": "https://laravel.com", + "time": "2018-02-20T16:46:51+00:00" + }, + { + "name": "illuminate/filesystem", + "version": "v5.6.5", + "source": { + "type": "git", + "url": "https://github.com/illuminate/filesystem.git", + "reference": "be0efd11a676ce0fd25f6ccb0bfb4cc522b73ca2" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/illuminate/filesystem/be0efd11a676ce0fd25f6ccb0bfb4cc522b73ca2.zip", + "reference": "be0efd11a676ce0fd25f6ccb0bfb4cc522b73ca2", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.6.*", + "illuminate/support": "5.6.*", + "php": "^7.1.3", + "symfony/finder": "~4.0" + }, + "suggest": { + "league/flysystem": "Required to use the Flysystem local and FTP drivers (~1.0).", + "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).", + "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.6-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Filesystem\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Filesystem package.", + "homepage": "https://laravel.com", + "time": "2018-02-07T00:04:16+00:00" + }, + { + "name": "illuminate/http", + "version": "v5.6.5", + "source": { + "type": "git", + "url": "https://github.com/illuminate/http.git", + "reference": "649b67a33ce99a4a83d7124e2c3ca9efe7f34093" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/illuminate/http/649b67a33ce99a4a83d7124e2c3ca9efe7f34093.zip", + "reference": "649b67a33ce99a4a83d7124e2c3ca9efe7f34093", + "shasum": "" + }, + "require": { + "illuminate/session": "5.6.*", + "illuminate/support": "5.6.*", + "php": "^7.1.3", + "symfony/http-foundation": "~4.0", + "symfony/http-kernel": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.6-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Http\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Http package.", + "homepage": "https://laravel.com", + "time": "2018-02-20T21:40:53+00:00" + }, + { + "name": "illuminate/session", + "version": "v5.6.5", + "source": { + "type": "git", + "url": "https://github.com/illuminate/session.git", + "reference": "97e5c38b26fa6d0fd4d5496080fe0ef43c8f4c2d" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/illuminate/session/97e5c38b26fa6d0fd4d5496080fe0ef43c8f4c2d.zip", + "reference": "97e5c38b26fa6d0fd4d5496080fe0ef43c8f4c2d", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.6.*", + "illuminate/filesystem": "5.6.*", + "illuminate/support": "5.6.*", + "php": "^7.1.3", + "symfony/finder": "~4.0", + "symfony/http-foundation": "~4.0" + }, + "suggest": { + "illuminate/console": "Required to use the session:table command (5.6.*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.6-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Session\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Session package.", + "homepage": "https://laravel.com", + "time": "2018-01-29T14:08:55+00:00" + }, + { + "name": "illuminate/support", + "version": "v5.6.5", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "ada40fd5fba4f51e456d38d8b17c826c519b33c7" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/illuminate/support/ada40fd5fba4f51e456d38d8b17c826c519b33c7.zip", + "reference": "ada40fd5fba4f51e456d38d8b17c826c519b33c7", + "shasum": "" + }, + "require": { + "doctrine/inflector": "~1.1", + "ext-mbstring": "*", + "illuminate/contracts": "5.6.*", + "nesbot/carbon": "^1.20", + "php": "^7.1.3" + }, + "replace": { + "tightenco/collect": "<5.5.33" + }, + "suggest": { + "illuminate/filesystem": "Required to use the composer class (5.2.*).", + "symfony/process": "Required to use the composer class (~4.0).", + "symfony/var-dumper": "Required to use the dd function (~4.0)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.6-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Support package.", + "homepage": "https://laravel.com", + "time": "2018-02-22T15:02:07+00:00" + }, + { + "name": "nesbot/carbon", + "version": "1.22.1", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/briannesbitt/Carbon/7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc.zip", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "symfony/translation": "~2.6 || ~3.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2", + "phpunit/phpunit": "~4.0 || ~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.23-dev" + } + }, + "autoload": { + "psr-4": { + "Carbon\\": "src/Carbon/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2017-01-16T07:55:07+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/php-fig/container/b7ce3b176482dbbc1245ebf52b181af44c2cf55f.zip", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/php-fig/http-message/f6561bf28d520154e4b0ec72be95418abe6d9363.zip", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/php-fig/log/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d.zip", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/php-fig/simple-cache/753fa598e8f3b9966c886fe13f370baa45ef0e24.zip", + "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-01-02T13:31:39+00:00" + }, + { + "name": "symfony/debug", + "version": "v4.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "c77bb31d0f6310a2ac11e657475d396a92e5dc54" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/debug/c77bb31d0f6310a2ac11e657475d396a92e5dc54.zip", + "reference": "c77bb31d0f6310a2ac11e657475d396a92e5dc54", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2018-01-18T22:19:33+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v4.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "74d33aac36208c4d6757807d9f598f0133a3a4eb" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/event-dispatcher/74d33aac36208c4d6757807d9f598f0133a3a4eb.zip", + "reference": "74d33aac36208c4d6757807d9f598f0133a3a4eb", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "conflict": { + "symfony/dependency-injection": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2018-01-03T07:38:00+00:00" + }, + { + "name": "symfony/finder", + "version": "v4.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "8b08180f2b7ccb41062366b9ad91fbc4f1af8601" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/finder/8b08180f2b7ccb41062366b9ad91fbc4f1af8601.zip", + "reference": "8b08180f2b7ccb41062366b9ad91fbc4f1af8601", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2018-01-03T07:38:00+00:00" + }, + { + "name": "symfony/http-foundation", + "version": "v4.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-foundation.git", + "reference": "82a3ee2c6662d08ca1adf99e1ef2e31ab48196d4" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/http-foundation/82a3ee2c6662d08ca1adf99e1ef2e31ab48196d4.zip", + "reference": "82a3ee2c6662d08ca1adf99e1ef2e31ab48196d4", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-mbstring": "~1.1" + }, + "require-dev": { + "symfony/expression-language": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpFoundation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony HttpFoundation Component", + "homepage": "https://symfony.com", + "time": "2018-01-29T09:06:29+00:00" + }, + { + "name": "symfony/http-kernel", + "version": "v4.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-kernel.git", + "reference": "194bd224ec27952eac6d4fea6264b22990834eca" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/http-kernel/194bd224ec27952eac6d4fea6264b22990834eca.zip", + "reference": "194bd224ec27952eac6d4fea6264b22990834eca", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/log": "~1.0", + "symfony/debug": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/http-foundation": "~3.4.4|~4.0.4" + }, + "conflict": { + "symfony/config": "<3.4", + "symfony/dependency-injection": "<3.4", + "symfony/var-dumper": "<3.4", + "twig/twig": "<1.34|<2.4,>=2" + }, + "provide": { + "psr/log-implementation": "1.0" + }, + "require-dev": { + "psr/cache": "~1.0", + "symfony/browser-kit": "~3.4|~4.0", + "symfony/config": "~3.4|~4.0", + "symfony/console": "~3.4|~4.0", + "symfony/css-selector": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/dom-crawler": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/finder": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0", + "symfony/routing": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0", + "symfony/templating": "~3.4|~4.0", + "symfony/translation": "~3.4|~4.0", + "symfony/var-dumper": "~3.4|~4.0" + }, + "suggest": { + "symfony/browser-kit": "", + "symfony/config": "", + "symfony/console": "", + "symfony/dependency-injection": "", + "symfony/var-dumper": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpKernel\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony HttpKernel Component", + "homepage": "https://symfony.com", + "time": "2018-01-29T13:27:08+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/polyfill-mbstring/78be803ce01e55d3491c1397cf1c64beb9c1b63b.zip", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2018-01-30T19:27:44+00:00" + }, + { + "name": "symfony/translation", + "version": "v3.4.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "10b32cf0eae28b9b39fe26c456c42b19854c4b84" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/symfony/translation/10b32cf0eae28b9b39fe26c456c42b19854c4b84.zip", + "reference": "10b32cf0eae28b9b39fe26c456c42b19854c4b84", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.8", + "symfony/dependency-injection": "<3.4", + "symfony/yaml": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/finder": "~2.8|~3.0|~4.0", + "symfony/intl": "^2.8.18|^3.2.5|~4.0", + "symfony/yaml": "~3.4|~4.0" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2018-01-18T22:16:57+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/Client.php b/src/Client.php new file mode 100644 index 0000000..0833ba3 --- /dev/null +++ b/src/Client.php @@ -0,0 +1,61 @@ +config = $config; + } + + /** + * @param $app + * @return $this + */ + public function app($app) + { + if (isset($this->config[$app])) + $this->currentApp = $app; + return $this; + } + + /** + * 调用api,如果状态码不为200则抛出异常 + * @param $uri + * @param $params + * @return mixed + * @throws \Exception + */ + public function call($uri, $params) + { + $config = array_merge(['timeout' => 1], + $this->config[$this->currentApp]); + unset($config['secret']); + $client = new \GuzzleHttp\Client($config); + $params['appid'] = $this->currentApp; + $params['timestamp'] = time(); + $params['sign'] = $this->sign($params); + $resp = $client->post($uri, ['form_params' => $params]); + if ($resp->getStatusCode() == 200) { + return \GuzzleHttp\json_decode($resp->getBody(), true); + } else { + throw new \Exception('request failed'); + } + } + + protected function sign($params) + { + $key = $this->config[$this->currentApp]['secret']; + + unset($params['sign']); + ksort($params); + $str = http_build_query($params, null, '&'); + return md5($str . $key); + } + +} \ No newline at end of file diff --git a/src/Middleware/InternalApi.php b/src/Middleware/InternalApi.php new file mode 100644 index 0000000..41f340a --- /dev/null +++ b/src/Middleware/InternalApi.php @@ -0,0 +1,65 @@ +getClientIp(); + + if (!Str::startsWith($ip, [ + '127.0.0.', '192.168.', '10.0.' + ])) { + return new JsonResponse('', 404); + } + + $params = $request->all(); + + if (empty($params['appid'])) { + $data = ['error' => '参数错误',]; + return new JsonResponse($data, 403); + } + + if (empty($params['timestamp'])) { + $data = ['error' => '签名已过有效期',]; + return new JsonResponse($data, 403); + } elseif (intval($params['timestamp']) + 60 < time()) { + $data = ['error' => '签名已过有效期',]; + return new JsonResponse($data, 403); + } + + $sign = $this->sign($params); + if ($sign != $params['sign']) { + $data = [ + 'error' => '签名错误', + ]; + return new JsonResponse($data, 403); + } + + return $next($request); + } + + protected function sign($params) + { + $app = $params['appid']; + $key = config('internal_api.server.' . $app); + unset($params['sign']); + ksort($params); + $str = http_build_query($params, null, '&'); + return md5($str . $key); + } + +} diff --git a/src/ServiceProvider/InternalApiServiceProvider.php b/src/ServiceProvider/InternalApiServiceProvider.php new file mode 100644 index 0000000..4bc89bd --- /dev/null +++ b/src/ServiceProvider/InternalApiServiceProvider.php @@ -0,0 +1,27 @@ +app->configure('internal_api'); + $this->app->singleton('internal.api', function () { + return new Client(config('internal_api.client')); + }); + foreach (config('internal_api.client') as $appid => $config) { + $this->app->singleton('internal.api.' . $appid, function () use ($appid) { + return $this->app['internal.api']->app($appid); + }); + } + + } +} \ No newline at end of file