PHP code example of panyongwei / easysdk-alipay-kernel

1. Go to this page and download the library: Download panyongwei/easysdk-alipay-kernel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

panyongwei / easysdk-alipay-kernel example snippets


namespace EasySDK\AlipayPay;
use EasySDK\AlipayKernel\ServiceContainer;
/**
 * @method static Application Foctory(array $config)
 */
class AlipayPay extends ServiceContainer
{
    public static function make(string $name, array $config)
    {
        // 这里的命名空间是 Application.php 所在的命名空间
        $application = "\\EasySDK\\AlipayPay\\Application";
        return new $application($config);
    }

    public static function __callStatic($name, $arguments)
    {
        return self::make($name, ...$arguments);
    }
}

namespace EasySDK\AlipayPay;
use EasySDK\AlipayKernel\ServiceContainer;
/**
 * @property \EasySDK\AlipayPay\F2fpay\Client $f2fpay 付款码支付
 * @property \EasySDK\AlipayPay\Pc\Client $pc 电脑网站支付
 */
class Application extends ServiceContainer
{
    /**
     * 服务注册
     */
    protected array $providers = [
        \EasySDK\AlipayPay\F2fpay\ServiceProvider::class,
        \EasySDK\AlipayPay\Pc\ServiceProvider::class,
    ];

    /**
     * @param string $name
     * @param array $arguments
     *
     * @return mixed
     */
    public function __call(string $name, array $arguments)
    {
        return call_user_func_array([$this['base'], $name], $arguments);
    }
}

namespace EasySDK\AlipayPay\F2fpay;
use EasySDK\AlipayKernel\Exceptions\InvalidArgumentException;
use EasySDK\AlipayKernel\Exceptions\InvalidSignException;
use EasySDK\AlipayKernel\Exceptions\NetworkException;
use EasySDK\AlipayKernel\BaseClient;

class Client extends BaseClient
{
    /**
     * 面对面付款下单接口功能
     * 统一收单交易支付接口
     * 参数参考:https://opendocs.alipay.com/apis/api_1/alipay.trade.precreate
     * @param array $params
     * @return mixed
     * @throws InvalidArgumentException
     * @throws InvalidSignException
     * @throws NetworkException
     */
    public function precreate(array $params): mixed
    {
        $method = "alipay.trade.precreate";
        return $this->post($method, $params);
    }
}

├── composer.json                   composer.json管理
├── src                             库源码
    ├── AlipayPay.php               入口文件通过这个文件去 Application.php 注册服务和调用
    ├── Application.php             服务提供者文件,负责注册和调用不同模块的服务对象             
    ├── F2fpay                      面对面支付实例
        ├── Client.php              面对面支付api对接代码,开发者都在这里编写业务逻辑
        └── ServiceProvider.php     面对面支付宝服务提供者注册代码
└── vendor