Home  >  Article  >  Backend Development  >  How to solve WeChat payment php7.0 error problem

How to solve WeChat payment php7.0 error problem

藏色散人
藏色散人Original
2022-01-24 09:17:242727browse

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.

How to solve WeChat payment php7.0 error problem

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn