douqie1852 2018-03-25 18:19
浏览 58

获取“Webhook通知中发送的无效JSON”Authorize.net

My Authorize.net webhook is set up properly on the A.net side, and when I trigger an event to get the notification, I get this in the error log:

PHP Fatal error: Uncaught exception 'JohnConde\Authnet\AuthnetInvalidJsonException' with message 'Invalid JSON sent in the Webhook notification' in /.../AuthnetWebhook.php:67 Stack trace: 0 /.../webhook.php(23): JohnConde\Authnet\AuthnetWebhook->__construct('xxxxxxxxxxx...', '', Array) 1 {main} thrown in /.../AuthnetWebhook.php on line 67

I can successfully setup the webhook and get notification history through the library on Github. Here is the code I'm using as my endpoint. Both allow_url_fopen and allow_url_include are set to enabled on my server.

<?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;
}



?>

Thanks for any help!

  • 写回答

2条回答 默认 最新

  • duanhu7400 2018-03-25 18:24
    关注

    Your payload is an empty string.. you can see it in the error.

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

    So

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

    I am not familiar with AuthnetWebhook but I would bet (if I was a gambler) that the payload variable should not be empty.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?