| 제목 | Google Firebase를 이용한 간단한(?) PUSH 서버 파트 코드입니다. | ||
|---|---|---|---|
| 글쓴이 | 담덕 | 작성시각 | 2017/01/18 12:27:58 | 
| 
                         | 
                |||
| 
                         구글이 선보인 Firebase를 사용해서 PUSH를 보내는 간단한 sample 코드입니다. 모델로 구현을 했는데 상황에 따라서 controller로 구현을 해도 될 듯 합니다. 
<?php
class Firebase_model extends CI_Model {
	private $FIREBASE = "https://fcm.googleapis.com/fcm/send";
	private $key = "<firebase key>";
	public function __construct()
	{
		parent::__construct();
	}
	// title : 제목
	// message : PUSH 내용
	// 디바이스 token : tokens (배열 type)
	public function send($title, $message, $tokens) {
		$msg = array (
			'title'		=> $title,
			'message' 	=> $message
		);
		$fields = array(
			'registration_ids' 	=> $tokens, // array type
			'data' => $msg
		);
		$headers = array(
			'Authorization: key='.$this->key,
			'Content-Type: application/json'
		);
		$ch = curl_init();
		curl_setopt ($ch, CURLOPT_URL, $this->FIREBASE);
		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);
		return $result;
	}
}
 호출은 controller에서 아래와 같이 하면 됩니다. $title = "제목입니다."; $message = "내용입니다."; $tokens = array( "단말기 token1", "단말기 token2", "단말기 token3", "단말기 token4" ); $this->firebase_model->send($title, $message, $tokens); 
  | 
                |||
| 다음글 | svg방식으로 구현된 우리나라 시도별 지도 입니다. (1) | ||
| 이전글 | 2.2.1 force_download helper 오류... (3) | ||
| 
                             
                                kaido
                                /
                                2017/01/18 14:00:23 /
                                추천
                                0
                             
                             | 
                    
| 
                             
                                한대승(불의회상)
                                /
                                2017/01/18 16:30:19 /
                                추천
                                0
                             
                            급 관심이 가는데요 ^^ 기회가 되면 활용해 봐야 겠습니다. 좋은 정보 감사 합니다.  | 
                    
오호. 한번 해봐야겠네요
좋은 정보 감사합니다 ㅎㅎ