Gaoming13\WechatPhpSdk\Api::progressWxPayNotify PHP Method

progressWxPayNotify() public method

处理微信支付异步通知
public progressWxPayNotify ( ) : array
return array [是否支付成功, 异步通知的原始数据, 回复微信异步通知的数据]
    public function progressWxPayNotify()
    {
        // PHP7移除了HTTP_RAW_POST_DATA
        $xml = file_get_contents('php://input');
        try {
            libxml_disable_entity_loader(true);
            $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
            if (!is_array($data)) {
                return [false, $data, ['return_code' => 'FAIL', 'return_msg' => '']];
            }
            // 格式是否正确
            if (!array_key_exists('return_code', $data)) {
                return [false, $data, ['return_code' => 'FAIL', 'return_msg' => 'return_code is not set']];
            }
            // 是否支付成功
            if ($data['return_code'] != 'SUCCESS') {
                return [false, $data, ['return_code' => 'FAIL', 'return_msg' => 'return_code is ' . $data['return_code']]];
            }
            // 签名是否正确
            $sign1 = SHA1::getSign2($data, 'key=' . $this->key);
            if ($sign1 != $data['sign']) {
                return [false, $data, ['return_code' => 'FAIL', 'return_msg' => '签名验证失败']];
            }
            // 支付成功
            return [true, $data, ['return_code' => 'SUCCESS', 'return_msg' => 'OK']];
        } catch (\Exception $e) {
            return [false, [], ['return_code' => 'FAIL', 'return_msg' => $e->getMessage()]];
        }
    }