コード例 #1
0
 public function testNtfs()
 {
     $records = Devices::all();
     $regIds = $records->lists('gcm_reg_id');
     $result = Notification::sendNtfsToDevices('test message', $regIds);
     return Response::json(array('status' => 'success', 'data' => $result));
 }
コード例 #2
0
ファイル: Notification.php プロジェクト: httvncoder/151722441
 /**
  * Static function for send message to devices.
  * 
  * @param string $message
  * @param unknown $deviceIds
  * @return boolean|unknown
  */
 public static function sendNtfsToDevices($message = '', $deviceIds = array())
 {
     if (!$message || !$deviceIds) {
         return false;
     }
     // Get registration ids
     $records = Devices::whereIn('id', $deviceIds)->get();
     $regIds = $records->lists('gcm_reg_id');
     if (!count($regIds)) {
         return false;
     }
     $registration_ids = implode(',', $regIds);
     $fields = array('registration_ids' => $regIds, 'data' => array('message' => $message));
     $headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
     // Open connection
     $ch = curl_init();
     // Set the url, number of POST vars, POST data
     curl_setopt($ch, CURLOPT_URL, GOOGLE_GCM_URL);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Disabling SSL Certificate support temporarly
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
     // Execute post
     $result = curl_exec($ch);
     if ($result === FALSE) {
         die('Curl failed: ' . curl_error($ch));
     }
     // Close connection
     curl_close($ch);
     //$result = EXRHelper::curl(GOOGLE_GCM_URL, json_encode($fields), $headers);
     return $result;
 }
コード例 #3
0
ファイル: RestDevices.php プロジェクト: httvncoder/151722441
 /**
  * API function for register device.
  *
  * @return Response
  */
 public function postRegisterDevice()
 {
     $data = Input::all();
     // Validator for post params
     $valids = Validator::make($data, ['device_id' => 'required|alpha_dash', 'gcm_reg_id' => 'alpha_dash', 'phone_number' => 'numeric']);
     extract($data);
     // Check is valid
     if ($valids->fails()) {
         return Response::json(array('status' => 'Error', $valids->messages()));
     }
     // Check device_id exists in db
     $record = Devices::where('device_id', '=', $device_id)->first();
     if (empty($record)) {
         $record = new Devices();
         $record->device_id = $device_id;
         $record->gcm_reg_id = $gcm_reg_id;
         $record->save();
     }
     return Response::json(array('status' => 'Success', 'data' => $record));
 }