天使漫步IT工作室天使漫步IT工作室

PHP Notice: Undefined index: HTTP_RAW_POST_DATA - 微信支付


Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 110

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 116

因为换了环境以后,以前好好的微信支付SDK出现了PHP Notice: Undefined index: HTTP_RAW_POST_DATA的错误。
原因是因为:

微信支付SDK PHP版使用$GLOBALS['HTTP_RAW_POST_DATA']获取POST请求的数据,但是在高版本PHP中HTTP_RAW_POST_DATA已经被废除了。

解决微信支付报错HTTP_RAW_POST_DATA,只要将HTTP_RAW_POST_DATA替换掉即可。

在WxPay.Api.php中搜索以下代码:

$xml = $GLOBALS['HTTP_RAW_POST_DATA'];

替换为:

$xml = file_get_contents('php://input');

兼容低版本的方案

替换为:

$xml = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input")

本站原创,欢迎转载,转载敬请标明出处:天使漫步IT工作室 » PHP Notice: Undefined index: HTTP_RAW_POST_DATA - 微信支付
添加新评论


Warning: Use of undefined constant php - assumed 'php' (this will throw an Error in a future version of PHP) in /www/wwwroot/u11u.com/usr/themes/wq/comments.php on line 38