hedeqiang / alchemypay
AlchemyPay SDK for PHP
v1.0.0
2022-10-30 13:59 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.3|^7.4
- symfony/psr-http-message-bridge: ^1.0|^2.1
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- friendsofphp/php-cs-fixer: ^3.0
- jetbrains/phpstorm-attributes: ^1.0
- mockery/mockery: ^1.2
- phpunit/phpunit: ^6.0|^7.0|^8.0|^9.0
- vimeo/psalm: ^4.10
README
环境需求
- PHP >= 7.1
- Composer >= 2.0
支持主流框架 Laravel
、Hyperf
、Yii2
快捷使用,具体使用方法请滑到底部
Installing
$ composer require hedeqiang/alchemypay -vvv
Usage
require __DIR__ .'/vendor/autoload.php'; use Hedeqiang\AlchemyPay\Pay; $app = new Pay([ 'endpoint' => 'xxx', 'merchantCode' => 'xxx', 'privateKey' => 'xxx', ]);
创建订单
$uri = 'openApi/createOrder'; $params = [ "amount" => "10.0", "fiatType" => "CNY", "callbackUrl" => "http://147.243.170.11:9091/transnotify", "merchantOrderNum" => "testqwe1234567891035", "payMent" => "w1", "email" => "123456@qq.com", ]; $response = $app->request($uri,$params);
回调通知
$result = $app->handleNotify(); // TODO return 'SUCCESS' ; // retuen 'Fail';
在 Laravel 中使用
发布配置文件
php artisan vendor:publish --tag=alchemy or php artisan vendor:publish --provider="Hedeqiang\AlchemyPay\ServiceProvider"
编写 .env 文件
ALCHEMY_PAY_ENDPOINT=
ALCHEMY_PAY_MERCHANT_CODE=
ALCHEMY_PAY_PRIVATE_KEY=
使用
服务名访问
public function index() { return app('pay')->request($uri,$params); }
Facades 门面使用(可以提示)
use Hedeqiang\AlchemyPay\Facades\Pay; public function index() { return Pay::pay()->request($uri,$params) } public function notify(Request $request) { $result = Pay::pay()->handleNotify(); }
在 Hyperf 中使用
发布配置文件
php bin/hyperf.php vendor:publish hedeqiang/alchemypay
编写 .env 文件
ALCHEMY_PAY_ENDPOINT=
ALCHEMY_PAY_MERCHANT_CODE=
ALCHEMY_PAY_PRIVATE_KEY=
使用
<?php use Hedeqiang\AlchemyPay\Pay; use Hyperf\Utils\ApplicationContext; // 请求 response = ApplicationContext::getContainer()->get(Pay::class)->request($uri,$parmas); // 回调 $response = ApplicationContext::getContainer()->get(Pay::class)->handleNotify();
在 Yii2 中使用
配置
在 Yii2
配置文件 config/main.php
的 components
中添加:
'components' => [ // ... 'pay' => [ 'class' => 'Hedeqiang\AlchemyPay\YiiPay', 'options' => [ 'endpoint' => 'xxx', 'merchantCode' => 'xxx', 'privateKey' => 'xxx', ], ], // ... ]
使用
Yii::$app->response->format = Response::FORMAT_JSON; // 请求 $results = Yii::$app->pay->getPay()->request($uri,$params); // 回调 $results = Yii::$app->pay->getPay()->handleNotify();
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
Contributing
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
- Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
License
MIT