iOS Push Service (PHP Server)

<?php


$deviceToken = '[DEVICE TOKEN(TRIM)]'; // 디바이스 토큰 ID (trim형식)

$message = '[STRING_MESSAGE]'; // 전송할 메시지


// 개발용

$apnsHost = 'gateway.sandbox.push.apple.com';

$apnsCert = '[PEM FILE NAME]';


// 실서비스용

//$apnsHost = 'gateway.push.apple.com';

//$apnsCert = '[PEM FILE NAME]';


$apnsPort = 2195;


$payload = array('aps' => array('alert' => $message, 'badge' => 0, 'sound' => 'default'));

$payload = json_encode($payload);


$streamContext = stream_context_create();

stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);


$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);


if($apns)

{

  $apnsMessage = chr(0).chr(0).chr(32).pack('H*', str_replace(' ', '', $deviceToken)).chr(0).chr(strlen($payload)).$payload;

  fwrite($apns, $apnsMessage);

  fclose($apns);

}

?>

이 글을 공유하기


댓글(0)

Designed by CMSFactory.NET