Formats the provided message for sending as a push message to the specified recipient.

@param TypeInterface $message The message to send.
@param string        $openID  The user id of the message recipient.

@return array
177206
public function formatMessageForPush (TypeInterface $message, $openID)
    {

        $json = [];
        $json['touser'] = $openID;
        $json['msgtype'] = $message->getType();

        $methodName = 'format' . ucfirst($message->getType()) . 'ForPush';
        if (method_exists($this, $methodName)) {
            $json[$message->getType()] = $this->$methodName($message);
        } elseif ($message instanceof Uploaded) {   
            $json[$message->getType()] = ['media_id' => $message->getMediaID()];
        }

        return $json;
    }
1370157
public function dispatch(MessageInterface $message)
    {
        $builder = $this->notificationBuilder;

        $notifications = $builder->buildNotifications($message);

        /** @var Notification $notification */
        foreach ($notifications as $notification) {
            $this->sendNotification($notification);
        }

        return $this;
    }
1179368
public function sendText (Type\Text $message)
    {
        $this->sendReply(
            $this->buildMessage(
                [
                    'MsgType' => $message->getType(),
                    'Content' => $message->getContent(),
                ]
            )
        );
    }
63570
public function message($message = '', $type = 'info')
    {
        if (is_array($message)) {
            foreach ($message as $issue) {
                $this->addMessage($issue, $type);
            }

            return $this;
        }

        return $this->addMessage($message, $type);
    }
1042260
public function addMessage(Message $message)
    {
        $type = $message->getType();
        if (!array_key_exists($type, $this->messages)) {
            $this->messages[$type] = [];
        }

        if ($message->getId() !== null) {
            $this->messages[$type][$message->getId()] = $message;
        } else {
            $this->messages[$type][] = $message;
        }

        return $this;
    }
1199492
public function sendByOpenid($touser = [], $message = [])
    {
        $msg = array_merge(['touser' => $touser], $message);
        $msg['msgtype'] = array_keys($message)[0];

        return $this->http->jsonPost(self::API_SEND, $msg);
    }
997720
private static function write(IOInterface $io, string $message)
    {
        $msg = [
            '[Panthor]: ' . $message,
        ];

        $io->write($msg);
    }
1290649
public function sendUserMessage($id, $message, $type = 'popup_chat')
    {
        if ($this->isEmptyId($id)) {
            throw new InvalidArgumentException;
        }

        if (!$message) {
            throw new InvalidArgumentException;
        }

        if (!in_array($type, ['popup_chat', 'popup_small', 'popup_big', 'email'])) {
            throw new InvalidArgumentException;
        }

        $params = [
            'body' => $message,
            'type' => $type
        ];
        $res = $this->call('users/' . $id . '/sendmessage', $params, 'post');

        if ($res) {
            return true;
        }

        return false;
    }
428699
public function buildNotifications(MessageInterface $message)
    {
        $notifications  = new \ArrayIterator();
        $recipientQueue = new \SplQueue();
        $recipientChunk = new \ArrayIterator();

        foreach ($message->getRecipientDeviceCollection() as $recipient) {
            $recipientChunk->append($recipient);

            if ($recipientChunk->count() >= $message->getMaxRecipientsPerMessage()) {
                $recipientQueue->enqueue($recipientChunk);
                $recipientChunk = new \ArrayIterator();
            }
        }

        if ($recipientChunk->count()) {
            $recipientQueue->enqueue($recipientChunk);
        }

        while (!$recipientQueue->isEmpty()) {
            $notification = $this->createNotification($recipientQueue->dequeue(), $message);
            $notifications->append($notification);
        }

        return $notifications;
    }
147240
public function preProcessMessage(MessageInterface $message)
    {
        foreach ($this->getProcessorStore()->getProcessors() as $processor) {
            $message = $processor->preProcessMessage($message);
        }

        return $message;
    }
256643
public function add($message = null, $type = 'notice')
    {
        if (!isset($this->messages[$type]) || !is_array($this->messages[$type])) {
            $this->messages[$type] = [];
        }
        if ($message) {
            $this->messages[$type][] = $message;
        }
        $this->writeToSession();
        return $this;
    }
1342014
private static function prepare( $type, $message )
	{
		// to avoid typos and other mistakes we 
		// validate the alert type
		$type = strtolower( $type );
		if ( !in_array( $type, static::$_types ) ) 
		{
			throw new Exception( "UI\Alert - Unknown alert type '{$type}'!" );
		}

		// We always need to return an array
		if ( !is_array( $message ) )
		{
			return array( $message );
		}
		return $message;
	}
551379
public function openidVoice($media_id = '', $openids = [])
    {
        $queryStr                      = [];
        $queryStr['touser']            = $openids;
        $queryStr['voice']['media_id'] = $media_id;
        $queryStr['msgtype']           = 'voice';

        $this->module = 'message';

        $res = $this->_post('mass/send', $queryStr);

        return $res;
    }
1360231
protected function buildRecipients($message)
    {
        foreach (['to', 'cc', 'bcc', 'replyTo'] as $type) {
            foreach ($this->{$type} as $recipient) {
                $message->{$type}($recipient['address'], $recipient['name']);
            }
        }

        return $this;
    }
727129
public function send($message, $type = self::TYPE_POST)
    {
        if ($message instanceof ProfileInterface) {
            return $this->sendProfile($message->toData(), $type);
        }

        if ($message instanceof UserInterface) {
            return $this->sendUserApi($message);
        }

        if ($message instanceof CodeInterface) {
            return $this->sendMessengerCode($message->toData());
        }

        return $this->sendMessage($message->toData());
    }
322784
public function addMessage($message, $type = 'success')
    {
        Events::dispatch('onMessageDisplay', array('message' => $message, 'type' => $type));
        $this->messages[] = array('message' => $message, 'type' => $type);
    }
1278533
public function addMessage($message, $type)
    {
        if (!is_string($message)) {
            throw new \InvalidArgumentException('Message must be a string');
        }
        if (!$message) {
            throw new \InvalidArgumentException('Message can\'t be empty');
        }
        if (!is_string($type)) {
            throw new \InvalidArgumentException('Type must be a string');
        }
        if (!$type) {
            throw new \InvalidArgumentException('Type can\'t be empty');
        }
        $this->messages[$type][] = $message;

        return $this;
    }