Send message to User and device
It functions transform to Real message data array

@param Object $msg
@param String $to
513469
public function sendRealMessageToDevice(Message $message, Device $device, $user = null, Request $request = null)
    {
        if ($this->isDisabled()) {
            return false;
        }

        $em = $this->container->get('doctrine')->getManager();

        $config = $this->container->getParameter('sopinet_chat.config');

        $messageData = $message->getMyMessageObject($this->container, $request);

        $text = $message->__toString();

        $messageArray = array();

        $vars = get_object_vars($messageData);

        foreach($vars as $key => $value) {
            $messageArray[$key] = $value;
        }

        if ($message->getChat() != null) {
            $em = $this->container->get('doctrine.orm.default_entity_manager');

            /** @var ChatRepository $repositoryChat */
            $repositoryChat = $em->getRepository('SopinetChatBundle:Chat');
            $repositoryChat->enabledChat($message->getChat());

            $chatData = $message->getChat()->getMyAddMessageObject($this->container);
            $varsChat = get_object_vars($chatData);
            foreach($varsChat as $key => $value) {
                $messageArray[$key] = $value;
            }
        }

        if ($user != null) {
            $messageArray['toUserId'] = $user->getId();

            //Calculamos el numero de mensajes pendientes que tiene

            // Get MessagePackage
            $reMessagePackage = $em->getRepository("SopinetChatBundle:MessagePackage");
            $messagesPackage = $reMessagePackage->findBy(array(
                'toUser' => $user->getId(),
                'toDevice' => $device->getDeviceId(),
                'processed' => false
            ));

            //Añadimos uno para que cuente el actual mensaje
            $messageArray['badge'] = count($messagesPackage) + 1;
        }else{
            $messageArray['badge'] = 0;
        }

        if ($device->getDeviceType() == Device::TYPE_ANDROID && $config['enabledAndroid']) {
            return $this->sendGCMessage($messageArray, $text, $device->getDeviceGCMId());
        } elseif ($device->getDeviceType() == Device::TYPE_IOS && $config['enabledIOS']) {
            return $this->sendAPNMessage($messageArray, $text, $device->getDeviceId(), $message->getMyIOSContentAvailable(), $message->getMyIOSNotificationFields());
        } elseif ($device->getDeviceType() == Device::TYPE_WEB && $config['enabledWeb']) {
            return $this->sendWebMessage($messageArray, $text, $device->getDeviceId());
        } elseif ($device->getDeviceType() == Device::TYPE_VIRTUALNONE) {
            // Do Nothing, but return true, so, state = 1, it is "sent" (in virtualnone: saved)
            return true;
        }
    }
1144639
public function message($msg)
    {
        foreach ($this as $client) {
            try {
                $this->execute(
                    "sendtextmessage",
                    array("msg" => $msg, "target" => $client, "targetmode" => Teamspeak::TEXTMSG_CLIENT)
                );
            } catch (TeamSpeak3_Adapter_ServerQuery_Exception $e) {
                /* ERROR_client_invalid_id */
                if ($e->getCode() != 0x0200) {
                    throw $e;
                }
            }
        }
    }
201538
public function send($to)
    {
        $message = Swift_Message::newInstance($this->subject)
                ->setFrom(array(MAIL_USERNAME => 'View Tuber'))
                ->setTo($to)
                ->setBody($this->body);
        if ($this->mailer->send($message))
        {
            echo 'Sent';
        }
        else
        {
            echo 'Failed';
        }
    }
461666
public function send(string $to, Sms $sms, array $params = []): bool
    {
        $content = $sms->content($this->agent_name);
        if (!$content) {
            throw new SmsException('The agent : ' . $this->agent_name . ' not supported by SMS');
        }
        $full_content = $this->getFullContent($content, $params);
        $this->result->setStatus(true)->setContent($full_content)->setParams($params);
        return true;
    }
277642
protected function sendData($data, $recordsFiltered, $recordsTotal)
    {
        $toJson = array(
            'draw' => intval($this->request['draw']),
            'recordsTotal' => intval($recordsTotal),
            'recordsFiltered' => intval($recordsFiltered),
            'data' => $this->dataOutput($data), );
        if (isset($this->toSend)) {
            $toJson = array_merge($this->toSend, $toJson);
        }
        exit(json_encode($toJson));
    }
1185060
protected function sendVoiceMsgToXmlString(WxSendVoiceMsg $msg)
    {
        $formatStr = <<<XML
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%d</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Voice>
<MediaId><![CDATA[%s]]></MediaId>
</Voice>
</xml>
XML;
        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getFromUserName(),
                                        strtotime($msg->getCreateTime()),
                                        $msg->getMsgType(),
                                        $msg->getMediaId()
                        );


        return $result;
    }
811057
public function notify($to, $message)
    {
        $params = [
            'username'  => strtoupper($to),
            'api_token' => $this->config['token'],
            'location'  => Arr::get($this->config, 'location'),
            'link'      => Arr::get($this->config, 'link'),
        ];

        return $this->send($this->buildUrlFromString('yo'), $params);
    }
823250
public function notify($to, $message)
    {
        $params = [
            'to'          => $to,
            'service_key' => $this->config['token'],
            'event_type'  => Arr::get($this->config, 'event_type', 'trigger'),
            'client'      => Arr::get($this->config, 'client', null),
            'client_url'  => Arr::get($this->config, 'client_url', null),
            'details'     => Arr::get($this->config, 'details', null),
            'description' => $message,
        ];

        return $this->send($this->buildUrlFromString('create_event.json'), $params);
    }
1039920
protected function sendSmsMessage(TwilioSmsMessage $message, $to)
    {
        $params = [
            'body' => trim($message->content),
        ];

        if ($messagingServiceSid = $this->getMessagingServiceSid($message)) {
            $params['messagingServiceSid'] = $messagingServiceSid;
        }

        if ($from = $this->getFrom($message)) {
            $params['from'] = $from;
        }

        if (! $from && ! $messagingServiceSid) {
            throw CouldNotSendNotification::missingFrom();
        }

        $this->fillOptionalParams($params, $message, [
            'statusCallback',
            'statusCallbackMethod',
            'applicationSid',
            'maxPrice',
            'provideFeedback',
            'validityPeriod',
        ]);

        if ($message instanceof TwilioMmsMessage) {
            $this->fillOptionalParams($params, $message, [
                'mediaUrl',
            ]);
        }

        return $this->twilioService->messages->create($to, $params);
    }
1013643
public function endpoint_sendmessage($to = NULL, $from = NULL, $body = NULL)
        {
            return $this->sendmessage($to, $from, $body);
        }
519023
public function send(string $to, Sms $sms, array $params = []): bool
    {
        $content = $sms->content($this->agent_name);
        if (!$content) {
            $this->result->setStatus(false)->setMessage('The agent : ' . $this->agent_name . ' not supported by SMS');
            return false;
        }

        $send_params = [
            'RegionId' => self::ENDPOINT_REGION,
            'AccessKeyId' => $this->config['access_key_id'],
            'Format' => 'JSON',
            'SignatureMethod' => 'HMAC-SHA1',
            'SignatureVersion' => '1.0',
            'SignatureNonce' => uniqid(),
            'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
            'Action' => 'SendSms',
            'Version' => '2017-05-25',
            'PhoneNumbers' => $to,
            'SignName' => SmsConfig::getSign(),
            'TemplateCode' => $content,
            'TemplateParam' => json_encode($params, JSON_FORCE_OBJECT),
            'OutId' => '',
        ];
        $send_params['Signature'] = $this->signature($send_params);

        $curl = new CurlRequest();
        list($code,$res) = $curl->request('POST',self::ENDPOINT_URL,['body' =>$send_params ]);

        $this->result->setReceiptData($res)->setContent($content)->setParams($params);

        $receipt_data = json_decode($res,true);
        if ($receipt_data === false) {
            $this->result->setStatus(false)->setMessage('Request failed!');
            return false;
        }
        $this->result->setMessage($receipt_data['Message'])->setReceiptId($receipt_data['RequestId']);
        if ($code == 200) {
            if($receipt_data['Code'] != 'OK') {
                $this->result->setStatus(false);
                return false;
            } else{
                $this->result->setStatus(true)->setReceiptId($receipt_data['BizId']);
                return true;
            }
        } else {
            $this->result->setStatus(false);
            return false;
        }

    }
214768
public function sendText($toUser, $content)
    {
        $ret = array();
        $ret['touser'] = $toUser;
        $ret['msgtype'] = 'text';
        $ret['text']['content'] = $content;
        return $this->send($ret);
    }
12282
private function message($msg, $level)
    {
        if ($this->transcoder) {
            $this->transcoder->dispatch(TranscodeEvents::MESSAGE, new MessageEvent($msg, $level, $this));
        }
    }
1145362
public function sendCustomServiceMessage(WxSendMsg $msg)
    {
        $url    = sprintf(self::CS_SEND_MESSAGE_URL, $this->getAccessTokenString());
        $client = $this->getHttpClient();
        $client->setUrl($url);
        $client->setHeaderArray(['Content-Type: application/json']);
        $client->setMethod(Client::METHOD_POST);
        $client->setPostFields($this->getFormatter()->toJsonString($msg));
        if (!$client->exec()) {
            throw new Exception("call send custom service message fail");
        }

        $result = json_decode($client->getResponse(), true);
        if (isset($result['errcode']) && isset($result['errmsg'])) {
            return (0 == $result['errcode']);
        }

        throw new Exception("error response for sending custom service message");
    }
1153790
public function rcpt($to)
    {
        if ($this->_mail == false) {
            throw new SMTPException(__('Must call MAIL before calling RCPT'));
        }

        $this->_send('RCPT TO:<' . $to . '>');
        $this->_expect(array(250, 251), 300);

        $this->_rcpt = true;
    }
443065
public function sendPresenceUnsubscription($to)
    {
        $node = new ProtocolNode('presence', ['type' => 'unsubscribe', 'to' => $this->getJID($to)], null, '');
        $this->sendNode($node);
    }
1149428
protected function sendNewsMsgToJsonString(WxSendNewsMsg $msg)
    {
        $itemArray  = $msg->getAllArticleItems();
        $itemStr    = '';
        foreach ($itemArray as $item) {
            $itemStr .= $this->sendNewsItemToJsonString($item) . ',';
        }

        $itemStr    = substr($itemStr, 0, -1);

        $formatStr = '{
                        "touser":"%s",
                        "msgtype":"%s",
                        "news":{
                            "articles": [
                             %s
                             ]
                        }
                    }';

        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getMsgType(),
                                        $itemStr
                            );

        return $result;
    }