PushWoosh上的Android设备无效注册

时间:2014-07-11 08:51:22

标签: php android pushwoosh

我使用以下PHP代码向PushWoosh远程API发送推送通知。它适用于iOS设备,并且似乎完美适用于Android(即我从API获得了所有适当的成功响应)但是因为我在PushWoosh控制台和我的Android设备中获得了InvalidRegistration报告,所以Android设备注册有些不妥从PushWoosh取消注册。有人解释为什么? 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
 }

1 个答案:

答案 0 :(得分:0)

好的,如果这对另一个人有用,我会很高兴:

我们使用CakePHP静态字符串方法生成设备ID&#39;

String::uuid();

它以这种格式输出一个字符串:

485fc381-e790-47a3-9794-1337c0a8fe68

PushWoosh在注册iOS设备时没有遇到任何问题,但在Android设备上使用此格式时却无声地失败。剥离&#34; - &#34;从这一切都很好。

Boo PushWoosh没有错误或回复我的电子邮件。