我使用wechatpay-php开发 商户订单号查询订单
代码如下:
// 设置参数
// 商户号
$merchantId = 'XXXX98216';
// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
//file_get_contents是自己加的
$merchantPrivateKeyFilePath = file_get_contents('E:\fund\apiclient_key.pem');
$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
// 「商户API证书」的「证书序列号」
$merchantCertificateSerial = 'XXXX4CBC872A7C76329583239D3';
// 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名
$platformCertificateFilePath = file_get_contents('E:\fund\vendor\wechatpay\wechatpay\wechatXXXF3AB3FDFEA4696E95432A9BCD3D7.pem');
$platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
// 从「微信支付平台证书」中获取「证书序列号」
$platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);
// 构造一个 APIv3 客户端实例
$instance = Builder::factory([
'mchid' => $merchantId,
'serial' => $merchantCertificateSerial,
'privateKey' => $merchantPrivateKeyInstance,
'certs' => [
$platformCertificateSerial => $platformPublicKeyInstance,
],
]);
try {
// 打印订单号,确保其正确性
echo "out_trade_no: " . $out_trade_no . PHP_EOL;
$resp = $instance
->chain("v3/pay/transactions/out-trade-no/$out_trade_no")
->get(['query' => [
'mchid' => $merchantId,
]]);
echo $resp->getStatusCode(), PHP_EOL;
echo $resp->getBody(), PHP_EOL;
return $resp->getBody();
} catch (\Exception $e) {
// 进行错误处理
echo $e->getMessage(), PHP_EOL;
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
$r = $e->getResponse();
echo $r->getStatusCode() . ' ' . $r->getReasonPhrase(), PHP_EOL;
echo $r->getBody(), PHP_EOL, PHP_EOL, PHP_EOL;
}
echo $e->getTraceAsString(), PHP_EOL;
}
报错:
out_trade_no: O7291660515080d1722216605
Client error: `GET https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/-o7291660515080d1722216605?mchid=1682098216` resulted in a `404 Not Found` response:
{"code":"ORDER_NOT_EXIST","message":"订单不存在"}
为啥订单前面非要自动加-
请问这样改写对吗
$promise = $instance ->v3->pay->transactions->id->_transaction_id_ ->getAsync([ // Query 参数 'query' => ['mchid' => '12098216'], // 变量名 => 变量值 'transaction_id' => 'O7291660515080d1722216605', ]); print_r($promise);
$out_trade_no 得用template方式,认真看sdk的readme,不要瞎写
->v3->pay->transactions->id->_transaction_id_
->getAsync([
// Query 参数
'query' => ['mchid' => '12098216'],
// 变量名 => 变量值
'transaction_id' => 'O7291660515080d1722216605',
]);
print_r($promise);
->v3->pay->transactions->outTradeNo->_out_trade_no_->close
->postAsync([
// 请求消息
'json' => ['mchid' => '1682098216'],
// 变量名 => 变量值
'out_trade_no' => 'O7291660515080d1722216605',
]);
print_r($promise);
按照示例书写后 并没有退款成功 请问哪里不对