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);