Per*_*ril 0 php push parse-platform
我想使用查询发送推送通知
我有这个问题
$ages = array(18,19,20,21)
$parseQuery = new parseQuery('_User');
$parseQuery->whereContainedIn('age', $ages);
$result = $parseQuery->find();
Run Code Online (Sandbox Code Playgroud)
我想向他们发送推送通知我应该使用安装还是另一种方式?谢谢
更新:
我正在使用这个sdk https://github.com/apotropaic/parse.com-php-library
从我返回的代码列表中我将向他们发送通知我想将推送通知发送到_User类
看起来您正在使用parseQuery检索具有您指定的年龄限制的用户.$result根据文档,一旦掌握了用户数据,就可以使用curl发送推送通知.
以下是我在网上找到的一些代码,应该很容易将其用于现有代码,以便向您检索到的用户发送推送通知.
<?php
$APPLICATION_ID = "xxxxxxxx";
$REST_API_KEY = "xxxxxxxxx";
$MESSAGE = "your-alert-message";
$url = 'https://api.parse.com/1/push';
$data = array(
'channel' => '',
'type' => 'android',
'expiry' => 1451606400,
'where' => array(
'age' => array('$in' => array(18,19,20,21))
),
'data' => array(
'alert' => 'greetings programs',
),
);
$_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);
Run Code Online (Sandbox Code Playgroud)
值得注意的是,你需要php-curl来实现这一点.如果您还没有安装或启用它,则非常容易.或者,file_get_contents如果您想要使用开箱即用的东西,您可以使用同样的东西.
编辑:我已$data使用您在问题中定义的约束更新了数组.您不需要使用parseQuery来查找具有更新代码的用户.你有效地告诉Parse在调用中应用约束.
更新2:我没有测试过这段代码,但是库使得在README中设置非常简单.该库只是使用下面的卷曲,所以你可以使用更方便的.
$parse = new parsePush('Sample push message');
$parse->where = array(
'age' => array('$in' => array(18,19,20,21))
);
//create acl
$parse->ACL = array("*" => array("write" => true, "read" => true));
$r = $parse->send();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4078 次 |
| 最近记录: |