php实现微信商家转账到用户零钱示例代码

代码语言:php

所属分类:其他

代码描述:php实现微信商家转账到用户零钱示例代码

代码标签: php 微信 商家 转账 用户 零钱 示例 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php

function Transfer($_orderno, $pay_openid, $amount, $memo = "用户提现", $pay_realname = "") {


    $money = 10;
    $openid = "";
    $post_data = [
        "appid" =>"appid",
        //appid
        "out_batch_no" => $_orderno,
        //商家批次单号
        "batch_name" => $memo,
        //批次名称
        "batch_remark" => $memo,
        //批次备注
        "total_amount" => $amount*100,
        // 转账金额单位为“分”
        "total_num" => 1,
        // 转账总笔数
        //此处可以多笔提现  组合二维数组放到transfer_detail_list即可   我这里单笔操作,写死了
        "transfer_detail_list" => [
            [
                'out_detail_no' => $_orderno,
                'transfer_amount' => $amount*100,
                'transfer_remark' => $memo,
                'openid' => $pay_openid,
            ]
        ]
    ];

    $url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
    $result =http_post($url, json_encode($post_data,
        JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE));

    $result = json_decode($result, true);
    // var_dump($result);

    if (isset($result['code']) && $result['code'] == 200) {

        return Bfw::RetMsg(false, $result);

    } else {
        return Bfw::RetMsg(true, $result);
    }


}

function http_post($url, $param) {
    $authorization = $this->getV3Sign($url, "POST", $param);
    $curl = curl_init();
    $headers = [
        'Authorization:' . $authorization,
        'Accept:application/json',
        'Content-Type:application/json;charset=utf-8',
        'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
    ];
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 500);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST.........完整代码请登录后点击上方下载按钮下载查看

网友评论0