Laravel 微信支付分账功能开发步骤

Laravel tytrock ⋅ 于 2025-02-10 14:55:53 ⋅ 95 阅读

Laravel版本:5.8

overtrue/wechat扩展版本:4.0

分账官方文档:https://pay.weixin.qq.com/doc/v3/partner/4012072582


1、发起支付时标识当前交易允许分账

统一下单方法下数组增加键名profit_sharing,值为Y

$wechat->order->unify([
    'body'         => '***',
    'out_trade_no' => '***',
    'total_fee'    => 100,
    'notify_url'   => url('wechat/notify'),
    'trade_type'   => 'JSAPI',
    'sub_openid'   => $openid,
    'profit_sharing'  => 'Y'
]);


2、添加分账接收方

$receiver = [
	"type"          => "MERCHANT_ID",//MERCHANT_ID/PERSONAL_OPENID/PERSONAL_SUB_OPENID
	"account"       => '1111111',//MERCHANT_ID时为商户ID
	"name"          => 'ABC科技有限公司',//商户全称,必须与商户平台上的商户名称一致
	"relation_type" => "PARTNER"
];
$res = $payment->profit_sharing->addReceiver($receiver);


3、发起分账

$out_trade_no = "***";//商户分账单号
$transaction_id = "****";//微信支付订单号
$receivers = [
	[
		"type"        => "MERCHANT_ID",
		"account"     => "1111111",
		"amount"      => 1,
		"name" => '',
		"description" => "分到商户"
	]
];
$sharing = $payment->profit_sharing->share($transaction_id,$out_trade_no,$receivers);


4、查询分账结果(非必要)

$res = $payment->profit_sharing->query($transaction_id,$out_trade_no);


5、分账回退(如发生退款,需要回退分账金额)

如easywechat中没有此方法,即表示未更新到最新扩展,可手动添加(到官方github中复制该方法下来,https://github.com/w7corp/easywechat/blob/5.x/src/Payment/ProfitSharing/Client.php)

$out_trade_no = "****";//退款订单号
$out_return_no = "****";//系统内部退款单号
$return_amount = 1;
$return_account = "1111111";
$description = "订单取消";
$res = $payment->profit_sharing->returnShare($out_trade_no,$out_return_no,$return_amount,$return_account,$description);




回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter