본문 바로가기

공부

curl 과 서버 push

1. 간단하게 우회 기능을 할 수 있는지에 대한 테스트


public function test_proxy(){

$url = "http://bubble.ohoh.tv/bubble/get_date";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$content = curl_exec($ch);

curl_close($ch);

echo $content;

}





2. push 메시지 보내기


public function test_push(){

$url = 'https://android.googleapis.com/gcm/send';

$reg_id = '';

$headers=array('Content-Type:application/json','Authorization:key='api key');

$arr = array();

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

$arr['data']['TopMessage'] = 'information'; 

$arr['data']['AppTitleMessage'] = 'this is test'; 

$arr['data']['AppTextMessage'] = 'yeong min ugly'; 

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

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

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);

        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);

}

728x90