升級完PHP7 發現微信支付回調失敗。原來是 $GLOBALS['HTTP_RAW_POST_DATA'];沒有定義的問題。php7 移除了這個全局變量。
問題代碼如下:
微信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);
}