Prepare the data to be sent

@param $topic
@param $message
@param $isCondition
@return array
426485
protected function buildData($topic, $message, $isCondition)
    {
        $condition = $isCondition ? ['condition' => $topic] : ['to' => '/topics/' . $topic];

        return array_merge($condition, $this->buildMessage($message));
    }
594448
def message(topic, message)
      msg = formatted_topic(topic) + message.to_s.gsub(%r!\s+!, " ")
      messages << msg
      msg
    end
1104349
public function sendBatch($topic, $task, array $messages, array $options = [])
    {
        return array_walk($messages, function ($data) use ($topic, $task, $options) {
            $this->send($topic, $task, $data, $options);
        });
    }
583917
public boolean send(String topic, String message) throws IOException {
        List<Session> sessions = topicSubscribers.get(topic);
        if (sessions != null) {
            for (Session session : sessions) {
                session.getBasicRemote().sendText(message);
            }
        }
        return sessions != null;
    }
808743
private function prepareMessage($message) {
    return is_string($message) ? $message :
      (is_object($message) && method_exists($message, '__toString') ? $message->__toString() :
            StringUtil::getDump($message));
  }
320568
public function subscribe(string $topic, array $options = [])
    {
        for (;;) {
            if (isset($this->messages[$topic])) {
                foreach ($this->messages[$topic] as $key => $message) {
                    yield $message;

                    unset($this->messages[$topic][$key]);
                }
            }

            sleep(1);
        }
    }
1374526
private function writeSession($message, $from = '', $is_error = false){
        if( session_id() ){
            $key = $is_error ? $this->error_key : $this->message_key;
            // Initialize
            if( !isset($_SESSION[$key]) || !is_array($_SESSION[$key]) ){
                $_SESSION[$key] = [];
            }
            // Add message
            $_SESSION[$key][] = ( empty($from) ? '' : sprintf('<strong>[%s]</strong> ', $from) ).$message;
        }
    }
1046274
public function send(string $address, string $subject, ?string $message = null): bool
    {
        // try to get message from global if not passed direct
        if ($message === null) {
            $message = $this->message;
        }

        try {
            if ($message === null) {
                throw new \Exception('Message body is empty!');
            }

            // try to build message and send it
            $message = (new \Swift_Message($subject))
                ->setFrom($this->from)
                ->setTo($address)
                ->setBody($message, 'text/html');
            $this->swift->send($message);
            return true;
        } catch (\Exception $e) {
            if (App::$Debug) {
                App::$Debug->addException($e);
                App::$Debug->addMessage('Send mail failed! Info: ' . $e->getMessage(), 'error');
            }
            return false;
        }
    }
17914
int sendMessageToTopicForSessions(Collection<Session> sessions, MessageToClient mtc, Object payload) {
		int sended = 0;
		JsTopicMessageController msgControl = messageControllerManager.getJsTopicMessageController(mtc.getId());
		Collection<Session> sessionsClosed = new ArrayList<>();
		for (Session session : sessions) {
			try {
				sended += checkAndSendMtcToSession(session, msgControl, mtc, payload);
			} catch (SessionException se) {
				sessionsClosed.add(se.getSession());
			}
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Send message to '{}' topic {} client(s) : {}", new Object[]{mtc.getId(), sessions.size() - sessionsClosed.size(), mtc});
		}
		topicManager.removeSessionsToTopic(sessionsClosed);
		return sended;
	}
942947
public function prepareMessage($message)
    {
        list($text, $level, $category, $timestamp) = $message;

        $result = [
            'category' => $category,
            'level' => Logger::getLevelName($level),
            '@timestamp' => date('c', $timestamp),
        ];

        if (isset($message[4])) {
            $result['trace'] = $message[4];
        }

        //Exceptions get parsed into an array, text and arrays are passed as is, other types are var_dumped
        if ($text instanceof \Exception) {
            //convert exception to array for easier analysis
            $result['message'] = [
                'message' => $text->getMessage(),
                'file' => $text->getFile(),
                'line' => $text->getLine(),
                'trace' => $text->getTraceAsString(),
            ];
        } elseif (is_array($text) || is_string($text)) {
            $result['message'] = $text;
        } else {
            $result['message'] = VarDumper::export($text);
        }

        if ($this->includeContext) {
            $result['context'] = $this->getContextMessage();
        }

        $message = implode("\n", [
            Json::encode([
                'index' => new \stdClass()
            ]),
            Json::encode($result)
        ]);

        return $message;
    }
464410
public function publishMessage(string $topicName, string $message){
        if(!$topicName || !$message){
            return $this->error('参数有误');
        }
        $topic = $this->client->getTopicRef($topicName);
        $request = new PublishMessageRequest($message);
        try{
            $topic->publishMessage($request);
            return $this->success('发布消息成功');
        }catch(MnsException $exception){
            return $this->parseException($exception, '发布消息');
        }
    }
724951
@Override
	public final void publish(Topic topic, Message message) throws JMSException
    {
        send(topic,message);
    }
764739
private function topicsForFcm($conditions)
    {
        $condition = '';
        foreach ($conditions as $partial) {
            if (array_key_exists('condition', $partial)) {
                $condition .= $partial['condition'];
            }

            if (array_key_exists('first', $partial)) {
                $topic = $partial['first'];
                $condition .= "'$topic' in topics";
            }

            if (array_key_exists('open_parenthesis', $partial)) {
                $condition .= $partial['open_parenthesis'];
            }

            if (array_key_exists('topic', $partial)) {
                $condition .= $this->topicsForFcm($partial['topic']);
            }

            if (array_key_exists('close_parenthesis', $partial)) {
                $condition .= $partial['close_parenthesis'];
            }
        }

        return $condition;
    }
1339076
public function publish($topicUri, $payload, $exclude = [], $eligible = [])
	{
		$type = WAMPProtocol::MSG_PUBLISH;
		$data = array($type, $topicUri, $payload, $exclude, $eligible);
		$this->send($data);
	}
857698
public function sendMail($to, $subject = '', $message = '', $headers = '')
    {
        if (empty($headers)) {
            $headers = 'From: ' . APP_SYS_EMAIL;
        }
        mail($to, $subject, $message, $headers);
    }
838259
def pub(self, topic, message):
        ''''''
        return self.send(' '.join((constants.PUB, topic)), message)
822647
public function send($message, $recipient, $mustInit = true)
    {
        if ($mustInit) $this->_init();

        $message_id = $this->_generateMessageId();
        $params = array(
            'message_type' => MESSAGE_TYPE_3,
            'mobile_number' => $recipient,
            'shortcode' => $this->short_code,
            'message_id' => $message_id,
            'message' => $message,
            'client_id' => $this->client_id,
            'secret_key' => $this->secret_key,
        );

        $query = http_build_query($params);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_POST, count($params));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);

        // Add the message_id in the response.
        $response = json_decode($response, true);
        $response['message_id'] = $message_id;
        $response = json_encode($response);

        return $response;
    }