gpt4 book ai didi

php - 解析 REST API : Having the channel name, 我可以在实际发送到 Push 之前获取设备类型吗?

转载 作者:可可西里 更新时间:2023-10-31 22:15:14 25 4
gpt4 key购买 nike

我们有一个服务器,它偶尔会向我们的用户发送推送。每个用户在 Parse 中都有自己的 channel 名称。因为我们的 ios 和 android 推送看起来完全不同,所以我们尝试发送两次推送,一次针对他的 channel 名称和 android 设备,一次针对他的 channel 名称和 ios 设备:

$aAndroidPush = array(
"where" => array(
"deviceType" => "Android",
"channels" => array('$in' => array("push_user"))
),
"data" => array(
"action" => "com.android.action",
"alertMessage" => "this is a push",
"t" => "web",
"m" => 0
)
);

$aIOSPush = array(
"where" => array(
"deviceType" => "ios",
"channels" => array('$in' => array("push_user"))
),
"data" => array(
"alert" => "this is a push",
"sound" => "p.mp3",
"t" => "web",
"m" => 0 ,
"badge" => ""
)
);

$aHeaders = array(
"Content-Type: application/json",
"X-Parse-Application-Id: parse_app_id" .,
"X-Parse-REST-API-Key: parse_rest_key" .
);

$oRest = curl_init();
curl_setopt($oRest,CURLOPT_HTTPHEADER,$aHeaders);
curl_setopt($oRest,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($oRest,CURLOPT_RETURNTRANSFER, true);
curl_setopt($oRest,CURLOPT_URL,"https://api.parse.com/1/push");
curl_setopt($oRest, CURLOPT_POST, 1);

curl_setopt($oRest, CURLOPT_POSTFIELDS, json_encode($aIOSPush));
curl_exec($oRest);

curl_setopt($oRest, CURLOPT_POSTFIELDS, json_encode($aAndroidPush));
curl_exec($oRest);

所以我的问题是,有没有一种方法可以在发送推送之前在解析(REST API 或新的 PHP API)中进行查询,以查看目标 channel 是使用 android 还是 ios,从而只发送一个推送请求而不是两个?

最佳答案

Parse 有很好的 PHP docs这可以帮助这里。因为您在 Android 中使用自定义推送通知处理程序,所以默认的推送代码可能不适合您。

要查看的其中一件事是对“_Installation”对象的解析查询。

您的代码将是:

$query = new ParseQuery("_Installation"); // or try ParseInstallation()?
$query->equalTo("objectId", $yourObjectId);
$result = $query->first();
if ($result->get("deviceType") == "android") {
// we are Android
} else {
// we are iOS
}

在推送之前了解您在安装上还有哪些其他数据会有所帮助。如果您有 objectId,那么这段代码就可以工作了。如果你有一个channels数组,你需要在这些 channel 中选择用户,然后在数组上foreach,获取objectId , 并以这种方式进行查询。

如果您发表评论让我知道一个或另一个,我很乐意解释。

关于php - 解析 REST API : Having the channel name, 我可以在实际发送到 Push 之前获取设备类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29536717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com