웹스쿨

안드로이드 GCM 호출 예시 본문

개발 경험 Tip/PHP

안드로이드 GCM 호출 예시

마스터욱 2023. 3. 31. 00:20
반응형

옛날에 회사다닐때 썻던 소스인데,

이번에 안드로이드 프로그램 만들일이 있어서 다시 사용하게 됨~

근대 오래되서 기억이 잘 안나네 -_-;

 

코드이그나이터에서 제작했던 함수임~

 

  1. public function index()
  2. {
  3.     //print_r($this->param);exit;
  4.  
  5.     $auth = "";
  6.  
  7.     if(count($this->param['pushKeys']) == 0) {
  8.         exit('Push 식별 번호가 전달되지 않았습니다.');
  9.     }
  10.  
  11.     $data = array(
  12.         'registration_ids'  => $this->param['pushKeys'],
  13.         'data'              => $this->param['input']
  14.     );
  15.    
  16.     $headers = array(
  17.         "Content-Type:application/json",
  18.         "Authorization:key=".$auth
  19.     );
  20.  
  21.     $ch = curl_init();
  22.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  23.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  24.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  26.     curl_setopt($ch, CURLOPT_POST, true);
  27.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  28.     $result = curl_exec($ch);
  29.  
  30.     $this->api->setLog($_SERVER['DOCUMENT_ROOT']."/assets/debug/push.txt"$result);
  31.  
  32.     curl_close($ch);
  33.  
  34.     if($result && strstr(strtoupper($result)strtoupper("success\":1,\""))) {
  35.         return 1;
  36.     }
  37.  
  38.     return 0;
  39. }

 

http://twinw.tistory.com/100 

 

위 링크를 참조해보는것도 좋을것 같다.


이 게시글은
https://webschool.kr/?v=board_view&board_key=7&idx=576
에서 작성한 글입니다. 소스코드의 경우 해당 블로그에서 이뿌게 노출이 되지 않을 수 있사오니, 위 링크로 들어오셔서 보시길 바랍니다.

반응형