使用yansongda 进行分账

use Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\AddReceiverPlugin;
use Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\CreatePlugin;
use Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\UnfreezePlugin;


```php
//以微信分账为例子
public function profitSharingByWX(Request $request)
{
//1、分账功能中需要先添加分账接收方
//添加分账接收方信息,account可以是openid也可以是商户号
$profitsharing_accounting_post_data = [
'type' => 'PERSONAL_OPENID',
'account' => $openid,
'relation_type' => 'SERVICE_PROVIDER'
];
//2、先添加分账接收方插件
$addReceiverPlugin = Pay::wechat(config('payment'))->mergeCommonPlugins([
AddReceiverPlugin::class
], $profitsharing_accounting_post_data);
//3、使用插件添加分账接收方
$profitsharing_accounting_result_data = Pay::wechat(config('payment'))->pay($addReceiverPlugin, $profitsharing_accounting_post_data);

//获取微信支付交易号
$transactionId = XXX;
//生成分账单号
$profitsharingOrderNo = XXX;

//4、拼装分账数据
$profitsharing_post_data = [
'transaction_id' => $transactionId,
'out_order_no' => $profitsharingOrderNo,
'receivers' => [
[
'type' => 'PERSONAL_OPENID',
'account' => $openid,
'amount' => $profitSharingAmount, // 分账金额,单位:分
'description' => $description, //分账描述
],
],
//该参数标志是否解冻订单金额,为true说明该订单后续不允许再次分账
// 'unfreeze_unsplit' => $unfreeze_unsplit,
'unfreeze_unsplit' => false,
];
//5、分账插件
$createPlugin = Pay::wechat(config('payment'))->mergeCommonPlugins([
CreatePlugin::class
], $profitsharing_post_data);
//6、发起分账
$profitsharing_result_data = Pay::wechat(config('payment'))->pay($createPlugin, $profitsharing_post_data);
}

```

posted @ 2025-08-26 18:15  93丶Fss  阅读(19)  评论(0)    收藏  举报