gamemoney / gamemoney-sdk
gamemoney
v4.1.0
2024-02-27 10:27 UTC
Requires
- php: >=7.0
- ext-json: *
- ext-openssl: *
- guzzlehttp/guzzle: >=6.5.5
- symfony/validator: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- php-mock/php-mock-phpunit: >=2.6.0
- phpunit/php-code-coverage: *
- phpunit/phpunit: >=6.5.14
README
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
composer require gamemoney/gamemoney-sdk
或者
"gamemoney/gamemoney-sdk": "*"
将以下内容添加到您的 composer.json
文件的 require 部分。
使用
<?php require_once __DIR__ . '/../vendor/autoload.php'; $project = 123456; $hmacKey = 'test'; try { $config = new \Gamemoney\Config($project, $hmacKey); $gateway = new \Gamemoney\Gateway($config); $requestFactory = new \Gamemoney\Request\RequestFactory; $request = $requestFactory->getInvoiceStatus(1); $response = $gateway->send($request); var_dump($response); } catch (\Gamemoney\Exception\RequestValidationException $e) { var_dump($e->getMessage(), $e->getErrors()); } catch (\Gamemoney\Exception\GamemoneyExceptionInterface $e) { var_dump($e->getMessage()); }
配置示例
使用存储在文件中的密钥
使用 file_get_contents
从文件获取密钥
<?php $pathToPrivateKeyFile = '/keys/gamemoney/project1/priv.key'; $project = 123456; $hmacKey = 'test'; $privateKey = file_get_contents($pathToPrivateKeyFile); $privateKeyPass = 'password'; $config = new \Gamemoney\Config($project, $hmacKey, $privateKey, $privateKeyPass);
使用格式为 file://
的路径
/keys/gamemoney/project1/priv.key
-- 密钥的完整路径
<?php $project = 123456; $hmacKey = 'test'; $pathToPrivateKeyFile = 'file:///keys/gamemoney/project1/priv.key'; $privateKeyPass = 'password'; $config = new \Gamemoney\Config($project, $hmacKey, $pathToPrivateKeyFile, $privateKeyPass);
使用字符串形式的密钥
<?php $project = 123456; $hmacKey = 'test'; $privateKey = '-----BEGIN ENCRYPTED PRIVATE KEY----- ... -----END ENCRYPTED PRIVATE KEY-----'; $privateKeyPass = 'password'; $config = new \Gamemoney\Config($project, $hmacKey);