0

我的 Authorize.net webhook 在 A.net 端正确设置,当我触发一个事件来获取通知时,我在错误日志中得到这个:

PHP 致命错误:未捕获的异常 'JohnConde\Authnet\AuthnetInvalidJsonException' 和消息 'Invalid JSON sent in the Webhook notification' in /.../AuthnetWebhook.php:67 堆栈跟踪:0 /.../webhook.php(23) : JohnConde\Authnet\AuthnetWebhook->__construct('xxxxxxxxxxx...', '', Array) 1 {main} 在第 67 行的 /.../AuthnetWebhook.php 中抛出

我可以通过 Github 上的库成功设置 webhook 并获取通知历史记录。这是我用作端点的代码。allow_url_fopen 和 allow_url_include 在我的服务器上都设置为启用。

<?php

namespace myapplication;

use JohnConde\Authnet\AuthnetWebhook;

require('.../config.inc.php');

require('.../autoload.php');

$headers = getallheaders();
$payload = file_get_contents("php://input");
$webhook = new AuthnetWebhook(AUTHNET_SIGNATURE, $payload, $headers);
if ($webhook->isValid()) {

    $transactionId = $webhook->payload->id;

    $fp = fopen('results.json', 'w');
    fwrite($fp, json_encode($webhook));
    fclose($fp);


    // Access notifcation values
    // echo $webhook->eventType;
}



?>

谢谢你的帮助!

4

2 回答 2

1

您的有效负载是一个空字符串..您可以在错误中看到它。

AuthnetWebhook->__construct('xxxxxxxxxxx...', '', Array)

所以

new AuthnetWebhook(AUTHNET_SIGNATURE, $payload, $headers); 

我不熟悉,AuthnetWebhook但我敢打赌(如果我是赌徒)有效载荷变量不应该为空。

于 2018-03-25T18:24:01.420 回答
0

解决了。端点 URL 不正确。我有 mysite.com/webhook.php 并且需要 www.mysite.com/webhook.php。

于 2018-03-25T22:24:22.850 回答