php android推送通知没有到达每个人

时间:2014-05-21 17:32:32

标签: android cordova push google-cloud-messaging

我在这里看了几个关于这个问题的线索,但似乎没有解决它,不知道我错过了什么,这是我的代码,它应该向所有设备发送通知,但它似乎错过了一些,感谢任何帮助:

foreach ($devices as $deviceArray) {
    $regIds[] = $deviceArray['device_id'];
}

$pusher->notify($regIds, $msg);

通知功能:

  public function notify($regIds, $data)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, self::GOOGLE_GCM_URL);
        if (!is_null($this->proxy)) {
            curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
        }
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders());
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getPostFields($regIds, $data));

        $result = curl_exec($ch);
        if ($result === false) {
            throw new \Exception(curl_error($ch));
        }

        curl_close($ch);

        $this->output = $result;
    }

private function getHeaders()
{
    $tempArray[0] = 'Authorization: key=' . $this->apiKey;
    $tempArray[1] = 'Content-Type: application/json';
    return $tempArray;

}

private function getPostFields($regIds, $data)
{
    $fields = array(
        'registration_ids' => is_string($regIds) ? array($regIds) : $regIds,
        'data'             => is_string($data) ? array( 'message' => $data) : $data,
    );
    return json_encode($fields, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
}

0 个答案:

没有答案