我正在使用以下PHP代码向PushWoosh远程API发送推送通知。它的作品非常适合iOS设备,并且似乎完美适用于Android(即,我可以从API获得所有适当的成功响应),但是仅针对Android的设备注册存在缺陷,因为我在PushWoosh控制台和我的Android设备上获取InvalidRegistration报告从PushWoosh注销。任何人都明白为什么? PushWoosh支持几乎不存在(在支付服务之前考虑这一点)。PushWoosh的Android设备无效注册
我记录的响应消息与预期的一样 - 我找回未知设备,我注册它们并接收每个注册的成功响应,然后我重新发送通知,并且返回的响应消息成功并显示没有未知设备。然后,我检查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方法? hwid应该来自设备本身。对不起,我完全困惑。 – shader
我们使用自定义设备标识符将设备关联到用户帐户并存储在设备内存中并生成这些服务器端。更好的描述是应用程序安装ID,因为每次使用我们的服务注册应用程序实例时都会更新它。 –
为什么不为每个设备设置一个标签?这将达到同样的目的,不会与pushwoosh hwid混淆。 – shader