1. Go to this page and download the library: Download feihu/allinpay-tppay 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/ */
// 在你的项目中创建,不要放在 vendor 目录下
// 示例:app/Extension/MyCustomExtension.php
namespace App\Extension;
use AllinPay\Sdk\Extension\BaseExtension;
class MyCustomExtension extends BaseExtension
{
/**
* 获取扩展名称(唯一标识)
*/
public function getName(): string
{
return 'my_custom';
}
/**
* 自定义方法:查询账单
*/
public function queryBill(string $date): array
{
$params = [
'date' => $date,
];
return $this->request('/bill/queryBill', $params);
}
/**
* 自定义方法:转账
*/
public function transfer(array $params): array
{
return $this->request('/transfer/transferApply', $params);
}
}
use AllinPay\Sdk\TqPay;
use App\Extension\MyCustomExtension;
// 方式1:初始化时注册
$tqPay = new TqPay($config, [
new MyCustomExtension(),
]);
// 方式2:动态添加
$tqPay = new TqPay($config);
$tqPay->addExtension(new MyCustomExtension());
// 方式3:通过类名添加(自动实例化)
$tqPay->addExtension(MyCustomExtension::class);