아는 것이 좋은 것이다.

[PHP] GCM 푸시 예제 소스(2) 본문

PHP

[PHP] GCM 푸시 예제 소스(2)

start0 2014. 7. 19. 17:27

<?


$reg_id = $_REQUEST['regid'];


$headers = array(

'Content-Type:application/json',

'Authorization:key=API키값'

);


//$temp_id = $_POST['id'];

$temp_msg = "메시지 테스트";





//$myServer = "localhost,포트(기본적으로 mssql은 1433을 씀)";

//$myUser = "아이디";

//$myPass = "비밀번호";

//$myDB = "DB명";

//$db = mssql_connect($myServer, $myUser, $myPass) or die ("서버 연결 실패");

//mssql_select_db($myDB,$db) or die ("DB 연결 실패");



//$result=mssql_query("select reg_id from personinfo where id = '$temp_id'");


//$reg_id = mssql_result($result, 0, "reg_id");


//echo "Reg_id = $reg_id 입니다.";







$arr   = array();

$arr['data'] = array();

$arr['data']['msg'] = "메시지";

$arr['registration_ids'] = array();

$arr['registration_ids'][0] = "$reg_id";




$ch = curl_init();



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

curl_setopt($ch, CURLOPT_HTTPHEADER,  $headers);

curl_setopt($ch, CURLOPT_POST,    true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

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

$response = curl_exec($ch);

echo $response;

curl_close($ch);

?>

Comments