我在安卓手机的Phonegap应用程序中使用PushBots插件。我需要从google云消息服务器获得设备注册id,以发送用户特定的推送通知。我在后端使用PHP和mySQL .基本上,一旦设备准备就绪,我需要将设备注册id保存到mysql db。请帮我找个解决办法。
发布于 2015-08-17 04:52:50
首先获取设备令牌并将其存储到数据库中,然后将其用于发送推送通知。
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
//setting up for android
if(PushbotsPlugin.isAndroid()){
PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
}
//get the device token
PushbotsPlugin.getToken(function(token){
console.log(token);
//setup an ajax request to store the device token
$.ajax({
url:'register.php',
method:"POST",
data:{token :token},
success:function(data){
console.log("from server"+data);
},
error:function(err){
console.log("error"+err);
}
});
});
}register.php
<?php
$token=$_POST['token'];
//setup database query for store the token
if($query==true){
echo 'success';
}else{
echo 'error';
}
?>还可以用值替换PUSH_BOT_APP_ID和GCM_SENDER_ID
https://stackoverflow.com/questions/32041531
复制相似问题