收藏
回答

微信商户提现到零钱,一直提示为久版本?

$config = [

'appid'        => 'wxxxxxxx',        // 公众号/小程序 AppID

'mchid'        => '17adsadsada',        // 商户号

'api_v3_key'   => 'wyfdffaaaaaaaaaaa',

'serial_no'    => '47E4A59E96dsadasdasdsadsadsasadsad',

'key_path'     => './protect/wxzs/apiclient_key.pem'  // 私钥证书路径

];


// -------------------------- 最新版提现函数 --------------------------

function transferToBalance($openid, $money, $out_batch_no, $config) {

$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';

$money_fen = (int)($money * 100); // 金额单位:分


// 官方最新标准请求体

$body = json_encode([

"appid"               => $config['appid'],

"out_batch_no"        => $out_batch_no,

"batch_name"          => "用户余额提现",

"batch_remark"        => "用户余额提现",

"total_amount"        => $money_fen,

"total_num"           => 1,

"transfer_detail_list" => [

[

"out_detail_no"   => $out_batch_no,

"transfer_amount" => $money_fen,

"transfer_remark" => "余额提现",

"openid"          => $openid

]

],

"transfer_scene_id" => "1005",

"notify_url" => "https://www.weixin.qq.com/wxpay/pay.php"

], JSON_UNESCAPED_UNICODE);


// 签名参数

$timestamp = time();

$nonce_str = uniqid();

$private_key = file_get_contents($config['key_path']);


// 微信V3签名格式(官方标准)

$sign_message = "POST\n/v3/transfer/batches\n{$timestamp}\n{$nonce_str}\n{$body}\n";

openssl_sign($sign_message, $sign, $private_key, 'sha256WithRSAEncryption');

$sign = base64_encode($sign);


// 请求头(严格按官方要求)

$headers = [

'Authorization: WECHATPAY2-SHA256-RSA2048 mchid="' . $config['mchid'] . '",nonce_str="' . $nonce_str . '",signature="' . $sign . '",timestamp="' . $timestamp . '",serial_no="' . $config['serial_no'] . '"',

'Content-Type: application/json',

'Accept: application/json',

'User-Agent: wechatpay-php'

];


// 发送请求

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);


$result = curl_exec($ch);

curl_close($ch);


return json_decode($result, true);

}


// -------------------------- 调用测试 --------------------------

$out_batch_no = date('YmdHis') . mt_rand(1000, 9999);

$openid ='oolxxxxxxxxxx'; // 用户openid

$money = 1; // 提现金额,单位:元


$res = transferToBalance($openid, $money, $out_batch_no, $config);


echo "<pre>";

echo 'iiiii';

print_r($res);

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容