hedeqiang/alchemypay

AlchemyPay SDK for PHP

v1.0.0 2022-10-30 13:59 UTC

This package is auto-updated.

Last update: 2024-09-29 05:57:13 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require Tests

环境需求

支持主流框架 LaravelHyperfYii2 快捷使用,具体使用方法请滑到底部

安装

$ composer require hedeqiang/alchemypay -vvv

用法

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.phpcomponents 中添加

'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();

由 JetBrains 支持的项目

非常感谢 JetBrains 好意提供许可证,使我能够为这个和其他开源项目工作。

贡献

您可以通过以下三种方式之一进行贡献

  1. 使用 问题跟踪器 提交错误报告。
  2. 问题跟踪器 上回答问题或修复错误。
  3. 贡献新功能或更新 wiki。

代码贡献过程并不非常正式。您只需确保遵循 PSR-0、PSR-1 和 PSR-2 编码指南。任何新的代码贡献都必须附有适用的单元测试。

许可证

MIT