通过微信批次单号查询批次单
//微信支付批次号
$payment_no = $row['payment_no'];
// 微信支付商户号
$mchid = "******";
// 商户API证书序列号
$serial_no = "********";
// 请求随机串
$nonce_str = bin2hex(random_bytes(16));
// 时间戳
$timestamp = time();
// 构建请求参数
$requestParams = [
'need_query_detail' => true,
'offset' => 0,
'limit' => 20,
'detail_status' => 'SUCCESS',
];
// 构建URL
$url = "https://api.mch.weixin.qq.com/v3/transfer/batches/batch_id/{$payment_no}?" . http_build_query($requestParams);
// 请求方法
$method = "GET";
// 解析URL
$urlParts = parse_url($url);
$urlPath = $urlParts['path'] . (isset($urlParts['query']) ? '?' . $urlParts['query'] : '');
// 构建签名消息
$message = $method . "\n" . $urlPath . "\n" . $timestamp . "\n" . $nonce_str . "\n";
// 签名
$privateKeyPath = $_SERVER['DOCUMENT_ROOT']."/apiclient_key.pem";
$privateCertPath = $_SERVER['DOCUMENT_ROOT']."/apiclient_cert.pem";
$privateKey = file_get_contents($privateKeyPath);
openssl_sign($message, $signature, $privateKey, '*******');
$signature = base64_encode($signature);
// 构建Authorization头
$token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$mchid, $nonce_str, $timestamp, $serial_no, $signature);
// 构建请求头
$headers = [
"Authorization: WECHATPAY2-SHA256-RSA2048 " . $token,
"Accept: application/json",
"User-Agent: PHP-CURL",
"Content-Type: application/json"
];
// 初始化cURL会话
$ch = curl_init();
// 设置cURL选项
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSLCERT, $privateCertPath);
curl_setopt($ch, CURLOPT_SSLKEY, $privateKeyPath);
// 执行cURL请求
$response = curl_exec($ch);
// 检查是否有错误
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
// 输出响应
echo $response;
}
// 关闭cURL会话
curl_close($ch);
返回空,我应该如何排查原因