溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

lumen PHP7 APP支付 原生微信支付 微信異步回調(diào)問題

發(fā)布時(shí)間:2020-07-14 00:34:10 來源:網(wǎng)絡(luò) 閱讀:10934 作者:努力的C 欄目:web開發(fā)

用的lumen寫的接口,APP支付。
PHP 7 。微信支付。按照微信官網(wǎng)文檔寫的。能正常生成prepay_id給客戶端,但是客戶端支付成功后,微信異步回調(diào)接口一直沒有接收到數(shù)據(jù)。網(wǎng)上查了好多原因:
1、有說notify_url 地址不對(duì)的,不能帶參數(shù)。這確實(shí)是一個(gè)注意的地方,但是我的url是OK的。
2、有的是說接口接收微信xml數(shù)據(jù)時(shí)應(yīng)該用 $xml = file_get_contents('php://input'); 因?yàn)镻HP7把之前那個(gè)$GLOBAL 變量取消了。。。。但是我按照這個(gè)寫,依然沒有接收到數(shù)據(jù)。
3、通過查NGINX訪問日志,發(fā)現(xiàn)微信確實(shí)訪問了我的回調(diào)接口,但是我這邊就是接受不到數(shù)據(jù)。。。。。emmmmm
4、最后同事。。。用了lumen里Request 里自帶的getContent() 方法就能接受到。。。。
5、看了一下getContent() 的源碼

public function getContent($asResource = false)
    {
        $currentContentIsResource = is_resource($this->content);
        if (\PHP_VERSION_ID < 50600 && false === $this->content) {
            throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
        }

        if (true === $asResource) {
            if ($currentContentIsResource) {
                rewind($this->content);

                return $this->content;
            }

            // Content passed in parameter (test)
            if (is_string($this->content)) {
                $resource = fopen('php://temp', 'r+');
                fwrite($resource, $this->content);
                rewind($resource);

                return $resource;
            }

            $this->content = false;

            return fopen('php://input', 'rb');
        }

        if ($currentContentIsResource) {
            rewind($this->content);

            return stream_get_contents($this->content);
        }

        if (null === $this->content || false === $this->content) {
            $this->content = file_get_contents('php://input');
        }

        return $this->content;
    }

估計(jì)是走了 return stream_get_contents($this->content);

但是查了一下 stream_get_contents($this->content);和file_get_contents('php://input'); 沒看出什么區(qū)別。
所以知道的大佬方便說一下嘛?

OK,網(wǎng)上又找了一下相關(guān)資料 https://stackoverflow.com/questions/21991906/how-do-i-get-raw-form-data-in-laravel

說是Laravel會(huì)攔截所有輸入。 如果您使用5.6之前的PHP,php://輸入流只能被讀取一次。 這意味著你需要從框架中獲取數(shù)據(jù)。 您可以通過訪問Request實(shí)例上的getContent方法來完成此操作,如下所示:

$content = Request::getContent(); // Using Request facade
     /* or */ 
$content = $request->getContent(); // If you already have a Request instance
                                   // lying around, from say the controller 
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI