Solution to WeChat payment php7.0 error: 1. Check WeChat API; 2. Use "php://inpu" instead of "$GLOBALS['HTTP_RAW_POST_DATA']" to obtain data.
The operating environment of this article: Windows7 system, PHP7.0 version, DELL G3 computer
How to solve WeChat payment php7 .0 error problem?
PHP7 WeChat payment callback failure solution:
After upgrading PHP7, I found that the WeChat payment callback failed. It turns out that $GLOBALS['HTTP_RAW_POST_DATA']; is not defined.
php7 removed this global variable.
The question code is as follows:
WeChat API: WxPay.Api.php
public static function notify($callback, &$msg) { //获取通知的数据 $xml = $GLOBALS['HTTP_RAW_POST_DATA'];//这里在php7下不能获取数据,使用 php://input 代替 if(!$xml){ $xml = file_get_contents("php://input"); } //如果返回成功则验证签名 try { $result = WxPayResults::Init($xml); } catch (WxPayException $e){ $msg = $e->errorMessage(); return false; } return call_user_func($callback, $result); }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve WeChat payment php7.0 error problem. For more information, please follow other related articles on the PHP Chinese website!