问题描述
我想使用PHP向特定用户发送推送通知.我知道这个问题被问过很多次.但是我的问题没什么不同.就我而言,推送通知是发送给所有用户的,即使我已将其指定为向特定用户发送推送,
I want to send push notification to a specific user using PHP. I know this question is asked many times. But my problem is little different. The push notifications are sent in my case, but to all users even though I have specified it to send push to a particular user,
为此,每当用户在其Android设备上安装应用程序时,我都会在Parse.com的安装表中保存一个唯一ID.这是android应用中的代码:
For that I am saving a unique ID in Parse.com 's installation table whenever user installs app on their android device.This is the code in the android app :
Parse.initialize(this, "XXXX", "XXXX");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("device_id", Secure.getString(getContentResolver(), Secure.ANDROID_ID));
installation.saveInBackground();
这很好.我可以在解析的安装表中看到该ID.
This works fine. I can see the id in the parse's installation table.
现在,这是我用来向特定设备ID发送推送通知的php脚本.它会发送推送通知,但会发送给所有用户.
Now, this is the php script I'm using to send push notification to specific device id. It does send the push notification, but to all users.
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);
推荐答案
在大量寻找解决方案之后,我检查了他们的github问题页面,并在已解决的问题"部分中找到了类似问题.解决方案是仅更新SDK.因为他们在 ParsePush.php 中输入了错误.因此,如果有人遇到此问题,请更新您的解析PHP SDK .
After searching a lot for a solution, I checked their github issues page and in the 'closed issues' section I found out a similar issue. The solution was to just update the SDK. Because they had made a typo in the ParsePush.php.So, if anyone is having this issue, please update your Parse PHP SDK.
这篇关于使用解析向特定用户发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!