用的lumen写的接口,APP支付。
PHP 7 。微信支付。按照微信官网文档写的。能正常生成prepay_id给客户端,但是客户端支付成功后,微信异步回调接口一直没有接收到数据。网上查了好多原因:
1、有说notify_url 地址不对的,不能带参数。这确实是一个注意的地方,但是我的url是OK的。
2、有的是说接口接收微信xml数据时应该用 $xml = file_get_contents('php://input'); 因为PHP7把之前那个$GLOBAL 变量取消了。。。。但是我按照这个写,依然没有接收到数据。
3、通过查NGINX访问日志,发现微信确实访问了我的回调接口,但是我这边就是接受不到数据。。。。。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; }

估计是走了 return stream_get_contents($this->content);

但是查了一下 stream_get_contents($this->content);和file_get_contents('php://input'); 没看出什么区别。
所以知道的大佬方便说一下嘛?

OK,网上又找了一下相关资料 https://stackoverflow.com/questions/21991906/how-do-i-get-raw-form-data-in-laravel

说是Laravel会拦截所有输入。 如果您使用5.6之前的PHP,php://输入流只能被读取一次。 这意味着你需要从框架中获取数据。 您可以通过访问Request实例上的getContent方法来完成此操作,如下所示:

$content = Request::getContent(); // Using Request facade /* or */ $content = $request->getContent(); // If you already have a Request instance // lying around, from say the controller