Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android can use like apple push-notification with php?

i use php to post to apple ..

$message = $error_msg;

  $deviceToken = $dtoken;
  $badge = 1;
  $sound = 'received3.caf';
    $body = array();
    $body['aps'] = array('alert' => $message);
    if ($badge)
            $body['aps']['badge'] = $badge;
    if ($sound)
            $body['aps']['sound'] = $sound;
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/administrator/applecert/apns-dev.pem');
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
    error_reporting(E_ALL);
    if (!$fp) {
            print "Failed to connect $err $errstr\n";
            return;
            } else {
           print "Connection OK\n";
        }
    $payload = json_encode($body);
    $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
    print "sending message :" . $payload . "\n";
    fwrite($fp, $msg);
    fclose($fp);

and andriod have similar way to post with php?

thanks ,all

like image 416
fifty arashi Avatar asked Jun 28 '26 04:06

fifty arashi


1 Answers

Take a look at the C2DM service google offers :

http://code.google.com/intl/fr-FR/android/c2dm/

like image 123
Yahel Avatar answered Jun 30 '26 17:06

Yahel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!