일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 시놀로지
- disabled
- synology
- 무선랜카드
- lsusb
- submit
- 따라다니는 배너
- javascript
- 커널
- XMLHTTP
- utf-8
- form
- AC1300
- Injection
- Getrows
- include
- DS718+
- 크로스 컴파일
- readonly
- jquery 레이어
- euc-kr
- ajax
- SQL Injection
- jQuery
- RTL88x2BU
- ASP
- FileSystemObject
- replace
- PHP GCM
- println
- Today
- Total
아는 것이 좋은 것이다.
[PHP] 푸시 메시지 보내기 (GCM) 본문
<?php
function sendGCM(){
// Replace with the real server API key from Google APIs
$apiKey = ""; //구글에서 발급받은 API키값
$regid = $_REQUEST['regid']; // 디바이스 키값
// Replace with the real client registration IDs
$registrationIDs = array( $regid );
// Message to be sent
$message = iconv("EUC-KR", "UTF-8", "한글 테스트 TEST!!"); //보낼 메시지
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send'; //GCM 전송URL
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the URL, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
echo $result;
//print_r($result);
//var_dump($result);
}
sendGCM(); // 푸시알림 전송
?>
'PHP' 카테고리의 다른 글
[PHP] GCM 푸시 예제 소스(2) (0) | 2014.07.19 |
---|---|
[PHP] 배열출력하기, 배열 확인하기 (0) | 2014.07.18 |
[PHP] 문자열 인코딩 변환 (0) | 2014.06.30 |
[PHP] 오류 메시지 출력 설정 (0) | 2014.06.24 |
[PHP] Fatal error: Allowed memory size of 8388608 bytes exhausted... (0) | 2014.06.19 |