- 微信支付native,使用wechatpay-php框架案例代码 不成功?
php微信支付框架地址: https://github.com/wechatpay-apiv3/wechatpay-php 以 关闭订单 POST 方法为例: $promise = $instance ->v3->pay->transactions->outTradeNo->_out_trade_no_->close ->post([ // 请求消息 'json' => ['mchid' => '1xx98216'], // 变量名 => 变量值 'out_trade_no' => 'O7302615137356d1722326151', ]); print_r($promise); 实际输出 GuzzleHttp\Psr7\Response Object ( [reasonPhrase:GuzzleHttp\Psr7\Response:private] => No Content [statusCode:GuzzleHttp\Psr7\Response:private] => 204 [headers:GuzzleHttp\Psr7\Response:private] => Array ( [Server] => Array ( [0] => nginx ) [Date] => Array ( [0] => Tue, 30 Jul 2024 09:30:00 GMT ) [Content-Type] => Array ( [0] => application/json; charset=utf-8 ) [Content-Length] => Array ( [0] => 0 ) [Connection] => Array ( [0] => keep-alive ) [Keep-Alive] => Array ( [0] => timeout=8 ) [Cache-Control] => Array ( [0] => no-cache, must-revalidate ) [X-Content-Type-Options] => Array ( [0] => nosniff ) [Request-ID] => Array ( [0] => 0898E5A2B50610F50518F1120F0B20D28F09203-0 ) [Content-Language] => Array ( [0] => zh-CN ) [Wechatpay-Nonce] => Array ( [0] => 516b2d553769c2f3800d56d89 ) [Wechatpay-Signature] => Array ( [0] => 1SO06eN7jVs3URu8kfFDMLrF8t16CyOKQAIuuk2r7HKZUgJzhEze8awLvHBw9y6usZRaU9Bp8E88bFSXlgqsyiTQMQ0yIkTCQtMjYVzZuPxzTV7N+/E7IrnttFyNEtM5hkqCB1b9nSsONUInqD7egXjCf7uiaymRWvANk/VRiH9+Fg6F4pmEFk7jEt5VyUKl8whKZO2aCX0p6IiRIBMR47LaKUpI03xD/D7MSO8f/nVqF58Uk+a0EzjihY/O/dFuIqmU1kLQj2chBaMudyElFZaHwJLgTzOly+Tr6Q== ) [Wechatpay-Timestamp] => Array ( [0] => 1722331800 ) [Wechatpay-Serial] => Array ( [0] => 55291D3F9F3AB3F3D7 ) [Wechatpay-Signature-Type] => Array ( [0] => WECHATPAY2-SHA256-RSA2048 ) ) [headerNames:GuzzleHttp\Psr7\Response:private] => Array ( [server] => Server [date] => Date [content-type] => Content-Type [content-length] => Content-Length [connection] => Connection [keep-alive] => Keep-Alive [cache-control] => Cache-Control [x-content-type-options] => X-Content-Type-Options [request-id] => Request-ID [content-language] => Content-Language [wechatpay-nonce] => Wechatpay-Nonce [wechatpay-signature] => Wechatpay-Signature [wechatpay-timestamp] => Wechatpay-Timestamp [wechatpay-serial] => Wechatpay-Serial [wechatpay-signature-type] => Wechatpay-Signature-Type ) [protocol:GuzzleHttp\Psr7\Response:private] => 1.1 [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #266 [size:GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( ) ) )
07-30 - 我使用wechatpay-php开发 商户订单号查询订单
我使用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":"订单不存在"} 为啥订单前面非要自动加-
07-29