PHP code example of shebaoting / laravel-huifu
1. Go to this page and download the library: Download shebaoting/laravel-huifu 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/ */
shebaoting / laravel-huifu example snippets
use Shebaoting\Huifu\Facades\Huifu;
// 192.00 元下单,自动格式化金额,自动封装微信参数
try {
$result = Huifu::miniAppPay(
'GB20260124001', // 商户订单号
192, // 金额 (支持 float/string/int)
'擦玻璃专项服务', // 商品描述
'oVYIxxxxxxxJbXg' // 用户的 OpenID
);
// 直接给前端返回 pay_info 即可唤起支付
return response()->json($result['pay_info']);
} catch (\Shebaoting\Huifu\Exceptions\HuifuApiException $e) {
// 获取汇付返回的错误描述
return $e->getMessage();
}
// 场景 A:按比例分成。商家分 90%,剩下的钱自动留给平台
Huifu::splitByRatio('原单号', '原支付日期Ymd', 100.00, [
'66660001xxxx' => 0.9,
]);
// 场景 B:按固定金额分成。给师傅分 80 元,剩下的钱留给平台
Huifu::splitByAmount('原单号', '原支付日期Ymd', [
'66660002xxxx' => 80.00,
]);
public function notify()
{
return Huifu::handleCallback(function($data) {
// $data 已经是验签通过后的业务数据数组
// 在这里处理你的订单状态更新逻辑
// ...
return true; // 返回 true 自动向汇付响应 "success"
});
}
// 直接传本地图片路径,自动转为汇付需要的 CURLFile
$fileId = Huifu::uploadImage(storage_path('app/id_card.jpg'), 'F55');
echo "汇付文件ID: " . $fileId;
$balance = Huifu::getBalance('6666000xxxxx');
echo "可用余额: ¥" . $balance;
use BsPaySdk\request\V2UserBasicdataQueryRequest;
$res = Huifu::request(V2UserBasicdataQueryRequest::class, [
'huifu_id' => '666600012345'
]);
bash
php artisan huifu:install