php获取未经授权的消息parse.com api

php获取未经授权的消息parse.com api,php,Php,我想通过parse.com api发送推送通知。 这是我的php代码: <?php $APPLICATION_ID = "your-app-id"; $REST_API_KEY = "your-api-key"; $MESSAGE = "your-alert-message"; if (!empty($_POST)) { $errors = array(); foreach (array('app' => 'APPLICATION_ID', 'api' =>

我想通过parse.com api发送推送通知。 这是我的php代码:

<?php

$APPLICATION_ID = "your-app-id";
$REST_API_KEY = "your-api-key";
$MESSAGE = "your-alert-message";

if (!empty($_POST)) {

    $errors = array();
    foreach (array('app' => 'APPLICATION_ID', 'api' => 'REST_API_KEY', 'body' => 'MESSAGE') as $key => $var) {
        if (empty($_POST[$key])) {
            $errors[$var] = true;
        } else {
            $$var = $_POST[$key];
        }
    }

    if (!$errors) {
        $url = 'https://api.parse.com/1/push';
        $data = array(
            'channel' => '',
            'type' => 'android',
            'expiry' => 1451606400,
            'data' => array(
                'alert' => $MESSAGE,
            ),
        );
        $_data = json_encode($data);
        $headers = array(
            'X-Parse-Application-Id: ' . $APPLICATION_ID,
            'X-Parse-REST-API-Key: ' . $REST_API_KEY,
            'Content-Type: application/json',
            'Content-Length: ' . strlen($_data),
        );

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $_data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $response = curl_exec($curl);
    }
}
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Parse API</title>
</head>
<body>
    <?php if (isset($response)) {
        echo '<h2>Response from Parse API</h2>';
        echo '<pre>' . htmlspecialchars($response) . '</pre>';
        echo '<hr>';
    } elseif ($_POST) {
        echo '<h2>Error!</h2>';
        echo '<pre>';
        var_dump($APPLICATION_ID, $REST_API_KEY, $MESSAGE);
        echo '</pre>';
    } ?>

    <h2>Send Message to Parse API</h2>
    <form id="parse" action="" method="post" accept-encoding="UTF-8">
        <p>
            <label for="app">APPLICATION_ID</label>
            <input type="text" name="app" id="app" value="<?php echo htmlspecialchars($APPLICATION_ID); ?>">
        </p>
        <p>
            <label for="api">REST_API_KEY</label>
            <input type="text" name="api" id="api" value="<?php echo htmlspecialchars($REST_API_KEY); ?>">
        </p>
        <p>
            <label for="api">REST_API_KEY</label>
            <textarea name="body" id="body"><?php echo htmlspecialchars($REST_API_KEY); ?></textarea>
        </p>
        <p>
            <input type="submit" value="send">
        </p>
    </form>
</body>
</html>
我将前两行的密钥插入parse.com中的密钥

编辑 当我通过php发布消息时,它会显示{result:true},但我不会在手机上收到消息。 我看一下parse.com的仪表板。靶子上写着“频道”,但当我从parse.com网站发送消息时,它会说只有一个人,每个人都会收到消息。

试试这个


感谢您的回复,但我尝试了,但我收到了相同的错误我收到了此消息{代码:115,错误:无法为查询目标推送设置设备类型。}尝试一下,删除'type'=>'android'代码:$data=array'where'=>'{}',expiration'=>1451606400',data'=>array'alert'=>$message;
$data = array(

    'where' => '{}',
    'expiry' => 1451606400,
    'data' => array(
        'alert' => $MESSAGE,
    ),
    );