PHP code example of gaooooge / easyhuifu

1. Go to this page and download the library: Download gaooooge/easyhuifu 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/ */

    

gaooooge / easyhuifu example snippets


use EasyHuifu\Application;

$huifu = new Application([
    'sys_id' => '666600010000001',
    'product_id' => '1234567890',
    'rsa_private_key' => 'your-private-key',
    'rsa_public_key' => 'huifu-public-key',
    'upper_huifu_id' => '666600010000001',
    'notify_url' => 'https://your-domain.com/payment/huifu/notify',
    'prod_mode' => true,
]);

$huifu->pay();
$huifu->payout();
$huifu->refund();
$huifu->split();
$huifu->entry();
$huifu->bankBranches();
$huifu->regions();

$pay = $huifu->pay()->miniApp([
    'amount' => 0.01, // 支付金额(元)
    'goods_desc' => '订单支付', // 商品描述
    'order_no' => 'M202603120001', // 业务订单号
    'notify_url' => 'https://your-domain.com/payment/huifu/notify', // 支付回调地址
    'sub_appid' => 'wx1234567890abcdef', // 微信子应用 appid
    'sub_openid' => 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o', // 用户 openid
]);

$huifu->pay()->create([...]);
$huifu->pay()->jsPay([...]);
$huifu->pay()->app([...]); // 微信 APP 或 APP 拉起支付宝
$huifu->pay()->alipay([...]); // 支付宝 JS 支付
$huifu->pay()->alipayNative([...]); // 支付宝正扫
$huifu->pay()->alipayApp([...]); // APP 拉起支付宝,别名同 alipayNative()

$pay = $huifu->pay()->app([
    'amount' => 0.01,
    'goods_desc' => '订单支付',
    'order_no' => 'M202603120002',
    'notify_url' => 'https://your-domain.com/payment/huifu/notify',
    'sub_appid' => 'wx1234567890abcdef',
]);

$pay = $huifu->pay()->alipayApp([
    'amount' => 0.01,
    'goods_desc' => '订单支付',
    'order_no' => 'M202603120003',
    'notify_url' => 'https://your-domain.com/payment/huifu/notify',
    'subject' => '订单支付',
]);

[
    'req_seq_id' => 'rQ20260312123000123456789012345678',
    'req_date' => '20260312',
    'huifu_id' => '666600010000001',
    'resp_code' => '00000100',
    'resp_desc' => '成功',
    'trade_type' => 'T_MINIAPP',
    'pay_info' => [
        'package' => 'prepay_id=wx...',
        'timeStamp' => '1710211200',
        'nonceStr' => 'abc123',
        'signType' => 'RSA',
        'paySign' => 'xxxx',
    ],
    'qr_code' => null,
    'response' => [...],
]

$pay = $huifu->pay()->miniApp([
    'amount' => 0.01, // 支付金额(元)
    'goods_desc' => '订单支付', // 商品描述
    'order_no' => 'M202603120001', // 业务订单号
    'notify_url' => 'https://your-domain.com/payment/huifu/notify', // 支付回调地址
    'sub_appid' => 'wx1234567890abcdef', // 微信子应用 appid
    'sub_openid' => 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o', // 用户 openid
    'delay_acct_flag' => 'Y', // 开启延迟分账
    'acct_split_bunch' => [
        'acct_infos' => [
            [
                'div_amt' => '0.0030', // 分账金额
                'huifu_id' => '666600010000002', // 分账接收方汇付号
            ],
            [
                'div_amt' => '0.0020', // 分账金额
                'huifu_id' => '666600010000003', // 分账接收方汇付号
            ],
        ],
    ],
]);

$query = $huifu->pay()->query([
    'org_req_seq_id' => 'rQ20260312123000123456789012345678',
    'org_req_date' => '20260312',
]);

$close = $huifu->pay()->close([
    'org_req_seq_id' => 'rQ20260312123000123456789012345678',
    'org_req_date' => '20260312',
]);

$result = $huifu->payout()->payToActor([
    'role_type' => 'supplier', // 主体类型
    'actor_id' => 20001, // 主体 ID
    'app_id' => 10000, // 应用 ID
    'amount' => 88.00, // 打款金额(元)
    'remark' => '供应商提现打款', // 业务备注
]);

$result = $huifu->refund()->scanPay([
    'huifu_req_seq_id' => 'rQ202603120001', // 原支付请求流水号
    'transaction_id' => '0036000123456789', // 原支付全局流水号
    'pay_time' => time(), // 原支付时间
], 10.00, 'refund202603120001'); // 退款金额、退款单号

$result = $huifu->refund()->refund($order, 10.00, 'refund202603120001');

$confirm = $huifu->split()->confirm([
    'huifu_id' => '666600010000001', // 发起方汇付号
    'org_req_seq_id' => 'rQ20260312123000123456789012345678', // 原支付请求流水号
    'org_req_date' => '20260312', // 原支付请求日期
    'pay_type' => 'ACCT_PAYMENT', // 交易类型
    'acct_split_bunch' => [
        'acct_infos' => [
            [
                'div_amt' => '0.0030', // 分账金额
                'huifu_id' => '666600010000002', // 分账接收方汇付号
            ],
            [
                'div_amt' => '0.0020', // 分账金额
                'huifu_id' => '666600010000003', // 分账接收方汇付号
            ],
        ],
    ],
    'remark' => 'order split confirm',
]);

$query = $huifu->split()->confirmQuery([
    'huifu_id' => '666600010000001',
    'org_req_seq_id' => 'rS20260312123500123456789012345678',
    'org_req_date' => '20260312',
]);

$refundConfirm = $huifu->split()->confirmRefund([
    'huifu_id' => '666600010000001',
    'org_req_seq_id' => 'rS20260312123500123456789012345678',
    'org_req_date' => '20260312',
    'acct_split_bunch' => [
        'acct_infos' => [
            [
                'div_amt' => '0.0010',
                'huifu_id' => '666600010000002',
            ],
        ],
    ],
    'remark' => 'split confirm refund',
]);

$result = $huifu->entry()->openIndividual([
    'name' => '测试用户', // 姓名
    'cert_no' => '3301xxxxxxxxxxxx', // 证件号
    'mobile_no' => '13800000000', // 手机号
    'cert_type' => '00', // 证件类型
    'card_no' => '6222xxxxxxxxxxxx', // 结算银行卡号
    'prov_id' => '310000', // 开户省编码
    'area_id' => '310100', // 开户市编码
    'bank_code' => '01050000', // 开户总行编码
    'branch_code' => '105290071008', // 开户支行联行号
]);

$result = $huifu->entry()->openEnterprise([
    'reg_name' => '测试企业', // 企业注册名称
    'license_code' => '9131xxxxxxxxxxxx', // 统一社会信用代码
    'contact_name' => '张三', // 联系人姓名
    'contact_mobile' => '13800000000', // 联系人手机号
    'legal_name' => '张三', // 法人姓名
    'legal_cert_no' => '3301xxxxxxxxxxxx', // 法人证件号
    'bank_code' => '01050000', // 开户总行编码
    'branch_name' => '中国建设银行上海张江支行', // 开户支行名称(可由系统解析联行号)
]);

$result = $huifu->entry()->openBusiness('6666000xxxxxxx', [
    'fee_rate' => '0.38',
]);

$detail = $huifu->entry()->detailByActor([
    'role_type' => 'supplier',
    'actor_id' => 20001,
    'app_id' => 10000,
]);

$banks = $huifu->bankBranches()->getBankOptions('建设');

$branches = $huifu->bankBranches()->getBranchList([
    'head_bank_code' => '01050000',
    'keyword' => '上海',
    'page' => 1,
    'pageSize' => 20,
]);

$branchCode = $huifu->bankBranches()->resolveBranchCode('中国建设银行上海张江支行', '01050000');
$isValid = $huifu->bankBranches()->isValidBranchCode($branchCode);
$branch = $huifu->bankBranches()->getByUnionCode($branchCode);

$tree = $huifu->regions()->tree();
$provinceList = $huifu->regions()->getChildren('');
$cityList = $huifu->regions()->getChildren('310000');
$districtCode = $huifu->regions()->getCodeByName('浦东新区', 3, '310100');

$huifu = new Application($config, [
    'logger' => $logger,
    'entry_repository' => $entryRepository,
    'branch_code_resolver' => $branchCodeResolver,
    'region_repository' => $regionRepository,
]);

EasyHuifu\Exception\EasyHuifuException

$basic = $huifu->entry()->basicOpenIndividual([
    'name' => '测试用户', // 姓名
    'cert_no' => '3301xxxxxxxxxxxx', // 证件号
    'mobile_no' => '13800000000', // 手机号
]);

$basic = $huifu->entry()->basicOpenEnterprise([
    'reg_name' => '测试企业', // 企业注册名称
    'license_code' => '9131xxxxxxxxxxxx', // 统一社会信用代码
    'reg_prov_id' => '310000', // 注册省编码
    'reg_area_id' => '310100', // 注册市编码
    'reg_district_id' => '310115', // 注册区县编码
    'reg_detail' => '浦东新区xx路xx号', // 注册地址详情
    'legal_name' => '张三', // 法人姓名
    'legal_cert_no' => '3301xxxxxxxxxxxx', // 法人证件号
    'contact_name' => '张三', // 联系人姓名
    'contact_mobile' => '13800000000', // 联系人手机号
]);

$basic = $huifu->entry()->basicOpenIndividual([
    'name' => '测试用户',
    'cert_no' => '3301xxxxxxxxxxxx',
    'mobile_no' => '13800000000',
]);

$busi = $huifu->entry()->openBusiness($basic['huifu_id'], [
    'settle_config' => [
        'settle_cycle' => 'T1',
    ],
    'cash_config' => [
        ['cash_type' => 'T1', 'fix_amt' => '0.00'],
    ],
]);