Find us on facebook

Jul 7, 2014

Push data to GCM server

public function sentToGcm($id, $devid, $oid, $ost) {

$response["success"] = 1;
$devid = $devid;
$registatoin_ids = array($devid);
$msgall = $ost;

$msg = array("message" => $msgall, "o_id" => $oid, 'type' => 'order_st');
$url = 'https://android.googleapis.com/gcm/send';
$fields = array('registration_ids' => $registatoin_ids, 'data' => $msg);
$headers = array('Authorization: key =AIzaSyD8E0T0h49MBYBST2aj_RuOCNxKReciCZA', 'Content-Type: application/json');

$data = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);
//$ss = Yii::app()->curl->post($url, $data);

echo $result;
}

No comments:

Post a Comment