일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Design Pattern
- git
- 성능
- 카프카 트랜잭션
- JPA
- graphql
- ddd
- APNS
- nginx
- GCM
- GCM 번역
- 푸시
- 자바스크립트
- 웹사이트 성능
- 디자인패턴
- php
- 웹사이트성능
- kafka
- Push
- 도메인 주도 개발
- notification
- 웹사이트최적화기법
- nginx설정
- 페이스북 번역
- gcm 푸시 번역
- Java
- 푸시 번역
- nginx설치
- 카프카
- Today
- Total
간단한 개발관련 내용
[APNs] Simple Sender by PHP 본문
PHP 간단하게 만들어 봤었던 테스트 푸시 발송 기능.
<?php
$title = 'this is title';
$message = 'message!!!';
$title = preg_replace("/\"/", "'", $title);
$message = preg_replace("/\"/", "'", $message);
$result = array();
$apnsHost = 'gateway.push.apple.com';
$apnsCert = '.../apns_production.pem'; // iOS Developer 를 통한 생성.
$apnsPort = 2195;
$apnsToken = 'abcdefg012345'; // app token
$payload = array();
// 현재 발송 메시지 형태
$payload['aps'] = array(
"alert" => $message,
"badge" => 1,
"sound" => "pushSound.caf",
"content-available" => 1);
$payload['extra'] = array("param1" => 0, "param2" => "");
$push = 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, 10, STREAM_CLIENT_CONNECT, $streamContext);
if($apns) {
$apnsMessage = chr(0).chr(0).chr(32).pack('H*', str_replace(' ', '', $apnsToken)).chr(0).chr(strlen($push)).$push;
var_dump($apnsMessage);
fwrite($apns, $apnsMessage);
@fclose($apns);
}
?>