<?php

namespace RxConnexionBundle\Service;

use Symfony\Component\DependencyInjection\ContainerInterface;

Class NotificationService {

    private $container;

    public function __construct(ContainerInterface $container) {

        $this->container = $container;
    }

    public function send($params) {

        $url = $this->container->getParameter('ws_server') . '/send';

        $fields = json_encode($params);

        $headers = array(
            'Authorization: key=' . $this->container->getParameter('api_secret'),
            'Content-Type: application/json'
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        //curl_setopt($ch, CURLOPT_URL, 'http://121.58.210.91/send');
        //curl_setopt($ch, CURLOPT_PORT, 8008);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);

        $result = curl_exec($ch);

        curl_close($ch);


    }
}