formatter WxSendVideoMsg to Json string
@param WxSendVideoMsg $msg
@return string
350023
protected function sendVideoMsgToJsonString(WxSendVideoMsg $msg)
    {
        $formatStr = '{
                        "touser":"%s",
                        "msgtype":"%s",
                        "video":
                        {
                          "media_id":"%s",
                          "thumb_media_id":"%s",
                          "title":"%s",
                          "description":"%s"
                        }
                    }';
        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getMsgType(),
                                        $msg->getMediaId(),
                                        $msg->getThumbMediaId(),
                                        $msg->getTitle(),
                                        $msg->getDescription()
                        );

        return $result;
    }
433562
public function format_error_message($errormsg) {
        $errors = unserialize($errormsg);
        $output = 'mnet_xmlrpc_client request returned errors:'."\n";
        foreach ($errors as $error) {
            $output .= "$error\n";
        }
        return $output;
    }
975614
protected function sendMusicMsgToJsonString(WxSendMusicMsg $msg)
    {
        $formatStr = '{
                        "touser":"%s",
                        "msgtype":"%s",
                        "music":
                        {
                          "title":"%s",
                          "description":"%s",
                          "musicurl":"%s",
                          "hqmusicurl":"%s",
                          "thumb_media_id":"%s"
                        }
                    }';
        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getMsgType(),
                                        $msg->getTitle(),
                                        $msg->getDescription(),
                                        $msg->getMusicUrl(),
                                        $msg->getHQMusicUrl(),
                                        $msg->getThumbMediaId()
                            );

        return $result;
    }
1343225
public function parseServerFirstMessage($msg)
    {
        $i = $r = $s = false;

        foreach (explode(',', $msg) as $val) {
            list($attr, $aval) = array_map('trim', explode('=', $val, 2));

            switch ($attr) {
            case 'i':
                $this->_iterations = intval($aval);
                $i = true;
                break;

            case 'r':
                /* Beginning of server-provided nonce MUST be the same as the
                 * nonce we provided. */
                if (strpos($aval, $this->_nonce) !== 0) {
                    return false;
                }
                $this->_nonce = $aval;
                $r = true;
                break;

            case 's':
                $this->_salt = base64_decode($aval);
                $s = true;
                break;
            }
        }

        if ($i && $r && $s) {
            $this->_authmsg .= ',' . $msg;
            return true;
        }

        return false;
    }
1036167
public function pack($msg)
    {
        if (!$msg instanceof Message) {
            trigger_error("Given parameter is not a message instance.",
                          E_USER_ERROR);
            return;
        }

        // Set value using serialzed message.
        $this->value = $msg->serializeToString();

        // Set type url.
        $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
        $desc = $pool->getDescriptorByClassName(get_class($msg));
        $fully_qualifed_name = $desc->getFullName();
        $this->type_url = GPBUtil::TYPE_URL_PREFIX.substr(
            $fully_qualifed_name, 1, strlen($fully_qualifed_name));
    }
852265
function(msg, levelMsg) {
    if (console.isTimestamped()) {
        return "[" + levelMsg + " - " + new Date().toJSON() + "] " + msg;
    } else {
        return "[" + levelMsg + "] " + msg;
    }
}
486375
public static function outputJson($data = null, $msg = '', $code = 0)
    {
        if (!$code) {
            return [
                'code' => 0,
                'msg' => $msg,
                'data' => $data,
            ];
        } else {
            return [
                'code' => $code,
                'msg' => $msg ? $msg : '未知错误',
            ];
        }
    }
371199
public static function fromMessage(Message $msg)
    {
        $requestId = $msg->shift();
        $actionName = $msg->shift();
        $parameters = $msg->toArray();

        return new self($requestId, $actionName, $parameters);
    }
402241
def encodeMsg(self, mesg):
        ''''''

        fmt = self.locs.get('log:fmt')
        if fmt == 'jsonl':
            s = json.dumps(mesg, sort_keys=True) + '\n'
            buf = s.encode()
            return buf

        elif fmt == 'mpk':
            buf = s_msgpack.en(mesg)
            return buf

        mesg = f'Unknown encoding format: {fmt}'
        raise s_exc.SynErr(mesg=mesg)
738544
protected function sendMusicMsgToXmlString(WxSendMusicMsg $msg)
    {
        $formatStr = <<<XML
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%d</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Music>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<MusicUrl><![CDATA[%s]]></MusicUrl>
<HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
</Music>
</xml>
XML;
        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getFromUserName(),
                                        strtotime($msg->getCreateTime()),
                                        $msg->getMsgType(),
                                        $msg->getTitle(),
                                        $msg->getDescription(),
                                        $msg->getMusicUrl(),
                                        $msg->getHQMusicUrl(),
                                        $msg->getThumbMediaId()
                                    );

        return $result;
    }
1169265
public function json($code, $msg = '', $data = null) {
        $result = json_encode(['code' => $code, 'msg' => $msg, 'data' => $data]);
        $this->contentType(self::TYPE_JSON);
        $this->_response->end($result);
    }
520343
protected function sendNewsMsgToXmlString(WxSendNewsMsg $msg)
    {
        $itemArray  = $msg->getAllArticleItems();
        $itemStr    = '';
        foreach ($itemArray as $item) {
            $itemStr .= $this->sendNewsItemToXmlString($item);
        }

        $formatStr = <<<XML
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%d</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<ArticleCount>%d</ArticleCount>
<Articles>
%s
</Articles>
</xml>
XML;

        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getFromUserName(),
                                        strtotime($msg->getCreateTime()),
                                        $msg->getMsgType(),
                                        $msg->getArticleCount(),
                                        $itemStr
                        );

        return $result;
    }
1250433
protected function sendTextMsgToJsonString(WxSendTextMsg $msg)
    {
        $formatStr = '{
                        "touser":"%s",
                        "msgtype":"%s",
                        "text":
                        {
                             "content":"%s"
                        }
                    }';
        $result = sprintf($formatStr,   $msg->getToUserName(),
                                        $msg->getMsgType(),
                                        $msg->getContent()
                        );


        return $result;
    }
492846
public function formatMessageForBroadcast (TypeInterface $type)
    {
        $json = ['msgtype' => $type->getType()];

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

        return $json;
    }
1088694
protected function sendNewsItemToJsonString(WxSendNewsMsgItem $item)
    {
        $formatStr = '{
                         "title":"%s",
                         "description":"%s",
                         "url":"%s",
                         "picurl":"%s"
                     }';
        $result = sprintf($formatStr,   $item->getTitle(),
            $item->getDescription(),
            $item->getPicUrl(),
            $item->getUrl()
        );

        return $result;
    }
516823
public static function parse(string $msg): Message
    {
        $obj = new self;
        $parts = explode("\r\n", $msg);
        $obj->body = MessageBody::parse(array_pop($parts));
        foreach ($parts as $line) {
            if ($line) {
                $pair = explode(': ', $line);
                $obj->headers[$pair[0]] = $pair[1];
            }
        }
        return $obj;
    }
1208634
public function msend(Message $msg)
    {
        if (ZMQ::SOCKET_ROUTER === $this->getSocketType()) {
            $msg->prepend($msg->getRoutingInformation());
        }

        if ($this->verbose) {
            $this->getLogger()->debug('SEND: '.$this->id);
            $this->getLogger()->debug($msg);
        }
        $parts = $msg->toArray();
        $iMax = count($parts)-1;
        if ($iMax < 0) {
            throw new RuntimeException('No parts to send.');
        }
        for ($i = 0; $i < $iMax; $i++) {
            $this->send($parts[$i], ZMQ::MODE_SNDMORE);
        }
        $this->send($parts[$iMax]);
        if ($this->verbose) {
            $this->getLogger()->debug('Message sent.');
        }

        return $this;
    }