【发布时间】:2015-11-09 22:17:08
【问题描述】:
我想使用 PHP 向特定用户发送推送通知。我知道这个问题被问了很多次。但我的问题有点不同。在我的情况下,推送通知是发送给所有用户的,即使我已指定它向特定用户发送推送,
为此,每当用户在其 Android 设备上安装应用程序时,我都会在 Parse.com 的安装表中保存一个唯一 ID。 这是android应用程序中的代码:
Parse.initialize(this, "XXXX", "XXXX");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("device_id", Secure.getString(getContentResolver(), Secure.ANDROID_ID));
installation.saveInBackground();
这很好用。我可以在解析器的安装表中看到 id。
现在,这是我用来向特定设备 ID 发送推送通知的 php 脚本。它确实会发送推送通知,但会发送给所有用户。
require_once('autoload.php');
use Parse\ParseInstallation;
use Parse\ParsePush;
use Parse\ParseClient;
ParseClient::initialize( 'XXXXXX', 'XXXXX', 'XXXXX' );
function sendPush($query){
$notification = "Test notification!";
$data = array("alert" => $notification);
ParsePush::send(array(
"where" => $query,
"data" => $data
));
}
$query = ParseInstallation::query();
$query->equalTo("device_id", "XXXXXX");
sendPush($query);
【问题讨论】:
-
如果您尝试通过 Parse Dashboard 发送它是否有效?
-
是的,通过 Parse Dashboard 可以正常工作。
标签: php android parse-platform