Javascript 推送程序无法发送或接收消息

Javascript 推送程序无法发送或接收消息,javascript,php,pusher,Javascript,Php,Pusher,我正在使用PHP中的pusher实时聊天库: ,并且我已经完成了安装此的所有步骤,但当我发送消息时,响应返回: Chat message sent. Result: success : { "activity": { "id": "58fec2f198619", "body": "hello world", "published": "Tue, 25 Apr 2017 03:30:57 +0000", "type": "chat-message",

我正在使用PHP中的pusher实时聊天库:

,并且我已经完成了安装此的所有步骤,但当我发送消息时,响应返回:

Chat message sent. Result: success : 

{
 "activity": {
    "id": "58fec2f198619",
    "body": "hello world",
    "published": "Tue, 25 Apr 2017 03:30:57 +0000",
    "type": "chat-message",
    "actor": {
      "displayName": "test",
      "objectType": "person",
      "image": {
        "url": "http:\/\/www.gravatar.com\/avatar\/61804bdff74c1969d90a1cac142a3b20?s=80&d=mm&r=g",
        "width": 48,
        "height": 48
      }
    }
  },
  "pusherResponse": {
    "body": "Unknown auth_key\n",
    "status": 400
  }
}
js:


$(函数(){
var pusher=新pusher(“API_键”{
群集:“ap2”,
加密:真
});
var chatWidget=新的pusher chatWidget(pusher{
附件:“#推送器#聊天工具”,
channelName:“站点范围的聊天频道”
});
});
PHP:


我已经验证了我的API密钥和机密,我不知道我遗漏了什么

<script>
    $(function () {
        var pusher = new Pusher("API_KEY", {
            cluster: 'ap2',
            encrypted: true
        });
        var chatWidget = new PusherChatWidget(pusher, {
            appendTo: "#pusher_chat_widget",
            channelName: 'site-wide-chat-channel'
        });
    });
</script>
<?php
require_once('./vendor/autoload.php');
require_once('Activity.php');
require_once('config.php');

date_default_timezone_set('UTC');

$chat_info = $_POST['chat_info'];

$channel_name = null;

if (!isset($_POST['chat_info'])) {
    header("HTTP/1.0 400 Bad Request");
    echo('chat_info must be provided');
}

if (!isset($_SERVER['HTTP_REFERER'])) {
    header("HTTP/1.0 400 Bad Request");
    echo('channel name could not be determined from HTTP_REFERER');
}

$channel_name = get_channel_name($_SERVER['HTTP_REFERER']);
$options = sanitise_input($chat_info);

$activity = new Activity('chat-message', $options['text'], $options);

$optionsIs = array(
    'cluster' => 'ap2',
    'encrypted' => true
);
$pusher = new Pusher(APP_KEY, APP_SECRET, APP_ID, $optionsIs);
$data = $activity->getMessage();
$response = $pusher->trigger('site-wide-chat-channel', 'chat_message', $data, null, true);

header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');

$result = array('activity' => $data, 'pusherResponse' => $response);
echo(json_encode($result));

function get_channel_name($http_referer)
{
    // not allowed :, / % #
    $pattern = "/(\W)+/";
    $channel_name = preg_replace($pattern, '-', $http_referer);
    return $channel_name;
}

function sanitise_input($chat_info)
{
    $email = isset($chat_info['email']) ? $chat_info['email'] : '';

    $options = array();
    $options['displayName'] = substr(htmlspecialchars($chat_info['nickname']), 0, 30);
    $options['text'] = substr(htmlspecialchars($chat_info['text']), 0, 300);
    $options['email'] = substr(htmlspecialchars($email), 0, 100);
    $options['get_gravatar'] = true;
    return $options;
}

?>