Quickblox错误"错误的事件"向AP发送推送通知

时间:2016-08-09 18:41:04

标签: php quickblox

我使用Quickblox向iPhone用户发送推送通知。我为会话创建了PHP函数并创建了一个用户并且API工作正常,但是测试发送推送通知,我在Dashboard / Queue上遇到错误:"错误的事件"在消息列上。事件已创建但从未到达。 API的响应没问题,就像文档一样。 我不知道为什么会收到这个错误。

这是我的代码:

if (isset($_POST['mensaje'])) {
    // Quickblox user Sign Up
    $session = createSession( . . . , '...', '...', '...', '...');
    $token = $session->token;
    $group = '...'; // Hardcoded only for testing
    $resp = sendQBPush($_POST['mensaje'], $group, $token);
}

和功能:

function sendQBPush($msg, $group, $token)
{
    if (!$msg) {
        return false;
    }

    $message = base64_encode($msg);

    // Build post body
    $post_body = array(
        'event' => array(
            'notification_type' => 'push',
            'environment' => 'production',
            'user' => array(
                'tags' => array(
                    'any' => $group
                )
            ) ,
            'push_type' => 'apns',
            'message' => 'payload=' . $message
        )
    );
    $request = json_encode($post_body);
    $ch = curl_init('http://api.quickblox.com/events.json');
    curl_setopt($ch, CURLOPT_POST, true); // Use POST
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // Setup post body
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'QuickBlox-REST-API-Version: 0.1.0',
        'QB-Token: ' . $token
    ));
    $resultJSON = curl_exec($ch);
    $responseJSON = json_decode($resultJSON);
    echo $resultJSON;

    // Check errors
    if ($responseJSON) {
        return $responseJSON;
    }
    else {
        $error = curl_error($curl) . '(' . curl_errno($curl) . ')';
        return $error;
    }

    // Close connection
    curl_close($curl);
}

感谢您的帮助

0 个答案:

没有答案