收藏
回答

微信支付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
                (
                )

        )

)


回答关注问题邀请回答
收藏

1 个回答

  • 北望沣渭
    北望沣渭
    07-31

    请求是成功了,只是对GuzzleHttp\Psr7\Response的处理,用print_r是不够的,例如:

    <?php
    print_r( (string) $promise->getBody() );xi
    


    详细可阅读: https://docs.guzzlephp.org/en/stable/psr7.html#responses

    As described earlier, you can get the body of a response using the getBody() method.

    $body = $response->getBody();
    echo $body;
    // Cast to a string: { ... }
    $body->seek(0);
    // Rewind the body
    $body->read(1024);
    // Read bytes of the body
    


    07-31
    有用
    回复
登录 后发表内容