기타

Android] GCM(Google cloud message) Python Server node.js Server, PHP Server, Client 참고 자료

린기린기린 2016. 1. 21. 15:09
반응형

안드로이드 GCM기능을 구현하기 위해서 여러 참고자료들을 확인해 보며 가장 좋았던 자료 공유해 드립니다.


1. 서버를 파이썬으로 구현하신분은  GCM서버 구현은

http://growingdever.tistory.com/186

를 참고하시면 될 것 같습니다.


2. 클라이언트의 경우에는(Node.js서버 포함)

http://blog.saltfactory.net/android/implement-push-service-via-gcm.html

를 참고하시면 많은 도움이 될 것입니다. 클라이언트 뿐만 아니라 node.js로 구현한 서버도 참고하실 수 있습니다.

* 클라이언트 구성부분에서 이슈 사항입니다.(해당 글 댓글)

 - R.string.gcm_defaultSenderId 에러의 경우 Set Up Google Play Services 에서 build.gradle 에서 두번째줄에 apply plugin: 'com.google.gms.google-services' 를 추가하세요.

 - 푸쉬안오시는 분들 .json파일의 client_id를

'android:패키지명'->'android'는 삭제 해주시고 '패키지명'으로 넣어주시면 정확하게 푸쉬옵니다.

-'com.google.android.gms:play-services-gcm:7.5.+' sync에러가 날 경우

'com.google.android.gms:play-services-gcm:8.1.0'로 변경해 주시면 됩니다.


3. php로 GCM 서버를 php로 구현하신분의 경우

아래 코드를 참고하시면 됩니다.



<?php

// API access key from Google API's Console

define( 'API_ACCESS_KEY', 'YOUR API KEY' );

$registrationIds = array("YOUR DEVICE TOKEN" );


// message

$msg = array(

    'message'       => 'here is a message. message',

    'title'         => 'This is a title. title',

    'subtitle'      => 'This is a subtitle. subtitle',

    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',

    'vibrate'   => 1,

    'sound'     => 1

);

$fields = array(

    'registration_ids'  => $registrationIds,

    'data'              => $msg

);


$headers = array(

    'Authorization: key=' . API_ACCESS_KEY,

    'Content-Type: application/json'

);


$ch = curl_init();

curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );

curl_setopt( $ch,CURLOPT_POST, true );

curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );

curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );

$result = curl_exec($ch );

curl_close( $ch );


echo $result;

?>



4. 기타

GCM Send 확인은

https://gcmsender.herokuapp.com/

에서 하시면 편합니다.

반응형