返回介绍

分账

发布于 2021-04-03 04:02:27 字数 5443 浏览 1926 评论 0 收藏 0

官方文档 https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_1&index=1

use EasyWeChat\Factory;
$config = [
    'app_id'     => '***',
    "secret"     => "***",
    'mch_id'     => '***',
    'key'        => '***',
    'cert_path'  => 'cert.pem',
    'key_path'   => 'key.pem',
    'notify_url' => 'http://***.com/notify.php',
];
$payment = Factory::payment($config);

添加接收方

商户发起添加分账接收方请求,后续可通过发起分账请求将结算后的钱分到该分账接收方。

$receiver = [
    "type"          => "PERSONAL_OPENID",
    "account"       => "…………",//PERSONAL_OPENID:个人openid
    "name"          => "张三",//接收方真实姓名
    "relation_type" => "PARTNER"
];
$payment->profit_sharing->addReceiver($receiver);
$receiver = [
    "type"          => "MERCHANT_ID",
    "account"       => "132456798",//MERCHANT_ID:商户ID
    "name"          => "商户全称",//商户全称
    "relation_type" => "PARTNER"
];
$payment->profit_sharing->addReceiver($receiver);

删除接收方

$payment->profit_sharing->deleteReceiver($receiver);

单次分账

$transaction_id = "***";
$out_trade_no = "***";
$receivers = [
    [
        "type"        => "PERSONAL_OPENID",
        "account"     => "***",
        "amount"      => 2,
        "description" => "分到个人"
    ],
    [
        "type"        => "MERCHANT_ID",
        "account"     => "***",
        "amount"      => 1,
        "description" => "分到商户"
    ]
];
$sharing = $payment->profit_sharing->share($transaction_id,$out_trade_no,$receivers);

多次分账

$payment->profit_sharing->multiShare($transaction_id,$out_trade_no,$receivers);

多次分账完结

$params = [
    "transaction_id" => "",
    "out_order_no"   => "",
    "description"    => ""
];
$payment->profit_sharing->markOrderAsFinished($params);

分账查询

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

查询结果

Array
(
    [return_code] => SUCCESS
    [result_code] => SUCCESS
    [mch_id] => ***
    [nonce_str] => 38e92cbe2790642f
    [sign] => 8904B6440C58785540950F2911500F55C9A94CAC75790B0721B9AA470E6BF9A8
    [transaction_id] => 4200000589202007249764665257
    [out_order_no] => 202007241544057945
    [order_id] => 30000103702020072402011591464
    [status] => FINISHED
    [receivers] => [{"type":"MERCHANT_ID","account":"***","amount":7,"description":"解冻给分账方","result":"SUCCESS","finish_time":"20200724172033"},{"type":"PERSONAL_OPENID","account":"***","amount":2,"description":"分到个人1","result":"SUCCESS","finish_time":"20200724172033"},{"type":"PERSONAL_OPENID","account":"***-g4","amount":1,"description":"分到郭","result":"SUCCESS","finish_time":"20200724172034"}]
)

分账退回

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文