升级完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);
    }

 

相关文章:

  • 2021-03-31
  • 2021-12-09
  • 2021-10-26
  • 2021-09-20
  • 2022-12-23
  • 2021-08-24
  • 2022-01-24
  • 2021-10-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-04-02
  • 2021-12-23
  • 2022-12-23
  • 2021-10-15
相关资源
相似解决方案