php 微信支付异步回调接口,lumen PHP7 APP支付 原生微信支付 微信异步回调问题

用的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'); 没看出什么区别。

所以知道的大佬方便说一下嘛?

说是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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值