我使用以下PHP代码向PushWoosh远程API发送推送通知。它完美地工作于iOS设备,似乎完美地工作于Android(即我从API获得所有适当的成功响应),但只有当我在PushWoosh控制台获得InvalidRegistration报告,我的Android设备从PushWoosh注销注册时,Android设备才出现问题。有人能解释一下原因吗?PushWoosh支持实际上是不存在的(在支付服务之前考虑一下)。
我正在记录的响应消息如预期的那样-我得到未知设备,我注册它们并收到每次注册的成功响应,我重新发送通知,我得到的响应消息是成功的,没有显示未知设备。然后我在PushWoosh控制台中检查推送历史,报告显示InvalidRegistration消息和设备被删除。
<?php
//creates the notifications setting send time etc - this is not where the problem is
$notifications = $this->create_pushwoosh_notifications($devices);
$data = array("application"=>$appcode,
"auth"=>$apptoken,
"notifications"=>$notifications);
$pw = new push_woosh();
$r = $pw->create_message($data);
if($r){
$response = json_decode($r[1]);
if($response->status_code != 200){
//there was an error
}
error_log($response->status_message);
//retrieve message id's
$messages = $response->response->Messages;
//get any uknown devices associated with the message id's
$unknowns = $response->response->UnknownDevices;
//go through the messages
foreach($response->response->Messages as $message_id){
//act if there is unknowns
if(count($unknowns->$message_id)>0){//if there are unknown devices for a message
//flag that we need to resend once we have finished registering unknown devices
$resend = true;
//change the devices in notifications to the unknowns for the message_id that contained unknown devices
$notifications[$key[0]]['devices']=$unknowns->$message_id;
//loop unknowns
foreach($notifications[$key[0]]['devices'] as $device_id){
$regdata = array(
"application"=>$this->appcode,
"push_token"=>$devices[$device_id]['user_tokenid'],
"language"=>"en", // optional
"hwid"=> $devices[$device_id]['device_id'],//devices indexed by HWID
"timezone"=> 3600, // offset in seconds
"device_type"=>$devices[$device_id]['device_type']
);
}
//register the device
$r = $pw->register($regdata);
if($r){
$response = json_decode($r[1]);
if($response->status_code != 200){
//there was an error
}
error_log($response->status_message);
}else{
//also an error
}
}else{//remove the notification as all devices were known and dont need to resend
unset($notifications[$key[0]]);
}
}
if($resend){//we need to resend
//update $data with new $notifications
$data['notifications']=$notifications;
$r = $pw->create_message($data);
if($r){
$response = json_decode($r[1]);
if($response->status_code != 200){
//there was an error
}
error_log($response->status_message);
}else{
//also an error
}
}
}else{
//there was an error
}
好吧,如果这对其他人有用,我会很高兴的:
我们使用CakePHP静态字符串方法来生成设备ID的
String::uuid();
输出如下格式的字符串:
485fc381-e790-47a3-9794-1337c0a8fe68
PushWoosh在注册iOS设备时没有问题,但在Android设备上使用这种格式时却无声地失败了。去掉"-",一切都好。
Boo PushWoosh没有错也没有回复我的邮件