nocksapp / bunq
该软件包已被弃用,不再维护。未建议替代软件包。
bunq 的 PHP API 客户端实现
dev-master
2017-08-14 09:49 UTC
Requires
- php: ^7
- beberlei/assert: ^2.7
- guzzlehttp/guzzle: ^6.2
- guzzlehttp/psr7: ^1.3
- moneyphp/money: ^3.0
- monolog/monolog: ^1.22
- ramsey/uuid: ^3.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.1
- mockery/mockery: ^0.9.9
- phpstan/phpstan: ^0.6.4
- phpunit/phpunit: ^6.0
This package is not auto-updated.
Last update: 2018-03-20 17:19:43 UTC
README
此库实现了 bunq API。
通过问题和/或拉取请求提供反馈和测试非常欢迎。
基本用法
以下代码示例做了几件事情,以帮助您尽快开始
- 创建一个 InstallationServer
- 创建一个 DeviceServer
- 从 SessionServer 获取一个会话,以便使用 API
在复制/粘贴此代码之前,请确保您有可用的 API 密钥。当开发和测试 API 时,您可能不想使用用于生产的 API 密钥。相反,您想使用开发 API 密钥。可以通过向 bunq 的支持台询问(使用 bunq 应用)来获得开发 API 密钥。一旦您获得此 API 密钥,您就可以将其填入 $apiKey
变量中。
函数 registerInstallationAndDeviceServer()
只应调用一次。第一次调用后,您可以取消注释此规则。
<?php use Link0\Bunq\Client; use Link0\Bunq\Domain\Keypair; use Link0\Bunq\Domain\Keypair\PublicKey; use Link0\Bunq\Environment\Production; use Link0\Bunq\Environment\Sandbox; use Link0\Bunq\Service\InstallationService; require_once('vendor/autoload.php'); /** * @param $installationService * @param $keypair * @param $apiKey * @return mixed */ function registerInstallationAndDeviceServer(InstallationService $installationService, $keypair, $apiKey) { $installation = $installationService->createInstallation($keypair); $installationToken = $installation[1]; $serverPublicKey = $installation[2]; // Cache the server public key somewhere file_put_contents('server-public-key.txt', $serverPublicKey); // Cache the installation token somehere file_put_contents('installation-token.txt', $installationToken); $installationService->createDeviceServer($installationToken, $apiKey, 'I pasted this from README.md'); } // openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048 // openssl rsa -pubout -in private.pem -out public.pem $keypair = Keypair::fromStrings( file_get_contents('public.pem'), file_get_contents('private.pem') ); // Replace this with what you received from the app $apiKey = 'your-api-key'; $debugMode = true; //$environment = new Production($debugMode); $environment = new Sandbox($debugMode); $client = new Client($environment, $keypair); $installationService = new InstallationService($client); registerInstallationAndDeviceServer($installationService, $keypair, $apiKey); $installationToken = file_get_contents('installation-token.txt'); $sessionServer = $installationService->createSessionServer($installationToken, $apiKey); $sessionServerId = $sessionServer[0]; $sessionToken = $sessionServer[1]; $user = $sessionServer[2]; file_put_contents('session-token.txt', $sessionToken); // After this, you can use the client with all other services as followed $client = new Client( $environment, $keypair, new PublicKey(file_get_contents('server-public-key.txt')), file_get_contents('session-token.txt') );