微信转账提示^ 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';
// 构造请求数据
$data = [
//appid
'appid' => 'wxa77e92bad39baaa8',
//单号
'out_bill_no' => $out_trade_no,
//转账场景ID
'transfer_scene_id' => '1005',
//用户openid
'openid' => $openid,
//转账金额
'transfer_amount' => $money*100,
//转账备注
'transfer_remark' => $batch_name,
//转账场景报备信息参数 https://pay.weixin.qq.com/doc/v3/merchant/4013774588
'transfer_scene_report_infos'=>[
[
'info_type' => '岗位类型',
'info_content' => $batch_name
],
[
'info_type' => '报酬说明',
'info_content' => '推广佣金提现'
]
]
];
$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);
// 构造请求头
$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;
}
信息类型,两条明细中必须分别填写以下两个取值:
活动名称
奖励说明
注:信息类型不可重复填写,请严格按照示例传入