1
如何使用php代码通过Parse.com推送通知。我想把它推到特定的定义的通道,即subscribeInBackground。如何使用PHP将分析推送通知发送到特定通道?
如果有人提供了一个快速解决方案,那么它对我来说真的很有帮助。 我在下面的链接引用,但它没有帮助。
如何使用php代码通过Parse.com推送通知。我想把它推到特定的定义的通道,即subscribeInBackground。如何使用PHP将分析推送通知发送到特定通道?
如果有人提供了一个快速解决方案,那么它对我来说真的很有帮助。 我在下面的链接引用,但它没有帮助。
在服务器端(PHP)使用此代码(我的作品)
function sendPush($message,$email)
{
$APPLICATION_ID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //put your identifiers here
$REST_API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // and here
$url = 'https://api.parse.com/1/push';
$data = array(
// 'where' => '{}', //uncomment this line to send push to all users
'where' => array( // send to specific user via email
'email' => $email
),
'data' => array(
'alert' => $message,
),
);
$_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_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
echo $result;
}
,并在客户端(安卓)使用此代码通过电子邮件注册和识别每个用户:
public static void subscribeWithEmail(String email) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("email", email);
installation.saveInBackground();
}
然后...当你打电话给你sendPush功能服务器会发送消息经由通过电子邮件和消息sendPush功能特定的用户...
,你想具体的通道,是吗?在PHP代码替换这...
$data = array(
'channel' => 'yourChannelName',
'data' => array(
'alert' => $message,
),
);
在Android上使用此代码为订阅频道:
ParsePush.subscribeInBackground("yourChannelName", new SaveCallback() {
@Override
public void done(ParseException e) {
Log.d("LOG","successfully subscribed to channel :)");
}
});
请粘贴您迄今为止尝试过的代码。 – Tauqir