推送通知使用离子和php与明确的例子
问题描述:
我是新的离子框架。推送通知使用离子和php与明确的例子
我需要在我的移动应用程序中使用离子与谷歌GCM(后端为PHP)实现推送通知。
我花了很多时间,因此我只有错误。所以,我需要一个清晰的例子与PHP。
答
对于前端看到Here
对于后端让你API_ACCESS_KEY的发送卷曲请求GCM。请参见下面的代码
// API_ACCESS_KEY you can get it from your google account
define('API_ACCESS_KEY', 'AIzaSyA_XXXXXXXvXXXXxxxxxxXXXX');
$msg = array
(
'message' => 'YOUR MESSAGE',
'title' => 'YOUR TITLE',
'vibrate' => 1,
'sound' => 1
// you can also add images, additionalData
);
// registration ids are registered device ids
$registrationIds =['ID1',ID2];
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
+0
我需要前端更多详细信息...离子前端不正常工作..设备令牌每秒更换 – Balakumaran
http://*.com/questions/36762552/ionic-push-notifications-on-android-doesnt-register-token-on-ionic-io/36765094#36765094检查我的答案android推送通知 –
我不知道关于php后端推送,但前端请参考这个答案 –