从 PHP 发送推送通知


sending push notification from php

<?php
$APPLICATION_ID = "XXXXXXXXXXXXXXX";
$REST_API_KEY = "XXXXXXXXXXXXXX";
$url = 'https://api.parse.com/1/push';
$data = array(
    'channel' => 'News',
    'type' => 'ios',
    'expiry' => 1451606400,
    'data' => array(
        'alert' => 'Test Push',
        'sound' => 'push.caf',
    ),
);
$_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_exec($curl);
?>

我正在使用此脚本发送推送通知。 是否必须提及频道?

每当我运行此脚本时,我都不会收到任何通知,而当我从解析站点发送时,设备正在接收通知。请帮忙。

您可以使用苗条库来实现这一点....检查此链接http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

你必须

使用 where 子句

$data = array(
  //'channel' => 'News',
  //'type' => 'ios',
  'where'=>'{}'
'expiry' => 1451606400,
'data' => array(
    'alert' => 'Test Push',
    'sound' => 'push.caf',
),);