微信轉(zhuǎn)賬提示^ array:2 [
"code" => "SIGN_ERROR"
"message" => "Authorization不合法"
]
function wechatTransfer($batch_name, $out_trade_no, $money, $openid, $username)
{
$url = 'https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills';
// 構(gòu)造請求數(shù)據(jù)
$data = [
//appid
'appid' => 'wxa77e92bad39baaa8',
//單號
'out_bill_no' => $out_trade_no,
//轉(zhuǎn)賬場景ID
'transfer_scene_id' => '1005',
//用戶openid
'openid' => $openid,
//轉(zhuǎn)賬金額
'transfer_amount' => $money*100,
//轉(zhuǎn)賬備注
'transfer_remark' => $batch_name,
//轉(zhuǎn)賬場景報備信息參數(shù) https://pay.weixin.qq.com/doc/v3/merchant/4013774588
'transfer_scene_report_infos'=>[
[
'info_type' => '崗位類型',
'info_content' => $batch_name
],
[
'info_type' => '報酬說明',
'info_content' => '推廣傭金提現(xiàn)'
]
]
];
$config = getCertPem();
// 生成簽名
$timestamp = time();
$nonceStr = uniqid();
$body = json_encode($data, JSON_UNESCAPED_UNICODE);
$message = sprintf("%s\n%s\n%d\n%s\n%s\n",
"POST",
parse_url($url, PHP_URL_PATH),
$timestamp,
$nonceStr,
$body
);
$apiclient_cert_path = $config['certPem'];
$apiclient_cert_arr = openssl_x509_parse(file_get_contents($apiclient_cert_path));
$serial_no = $apiclient_cert_arr['serialNumberHex'];//證書序列號
$privateKey = openssl_pkey_get_private(file_get_contents($config['keyPem']));
if (!$privateKey) {
throw new Exception('加載私鑰失敗');
}
openssl_sign($message, $signature, $privateKey, 'sha256WithRSAEncryption');
$signature = base64_encode($signature);
// 構(gòu)造請求頭
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => sprintf(
'WECHATPAY2-SHA256-RSA2048 mchid="%s",nonce_str="%s",signature="%s",timestamp="%d",serial_no="%s"',
'1712040441',
$nonceStr,
$signature,
$timestamp,
$serial_no
),
];
$response = https_request($url,$headers,$body);
$result = json_decode($response, true);
return $result;
}