开发调试级日记
@param string $msg 日记关键描述
@param string/array $data 场景上下文信息
@return NULL
761824
public function debug($msg, $data = NULL) {
        if (!$this->isAllowToLog(static::LOG_LEVEL_DEBUG)) {
            return;
        }

        $this->log('debug', $msg, $data);
    }
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;
    }
952776
public function showError($msg = null)
    {
        $errorMessage = null;
        $code = null;
        if ((null === $code) && (null === $msg)) {
            $errorCode = $this->connection->errorCode();
            $errorInfo = $this->connection->errorInfo();
        } else {
            $errorCode = $code;
            $errorInfo = $msg;
        }
    
        if (is_array($errorInfo)) {
            $errorMessage = null;
            if (isset($errorInfo[1])) {
                $errorMessage .= $errorInfo[1];
            }
            if (isset($errorInfo[2])) {
                $errorMessage .= ' : ' . $errorInfo[2];
            }
        } else {
            $errorMessage = $errorInfo;
        }
        throw new Exception('Error: ' . $errorCode . ' => ' . $errorMessage  . '.');
    }
1195376
protected function parseError($msg) {
        $args = func_get_args();

        if (count($args) > 1) {
            array_shift($args);
            $msg = vsprintf($msg, $args);
        }

        $line = $this->scanner->currentLine();
        $col = $this->scanner->columnOffset();
        $this->events->parseError($msg, $line, $col);
        return false;
    }
221633
public function check($data)
	{
		$failure  = 0;
		$messages = array();

		if (is_string($data))
		{
			$data = array('text' => $data);
		}

		$data = $this->prepareData($data);

		foreach ($this->detectors as $id => $detector)
		{
			$spam = false;
			$msg  = null;

			try
			{
				if ($detector->detect($data))
				{
					$spam = true;

					if ($detector->message())
					{
						$messages[] = $detector->message();
					}

					$failure++;
				}

				$msg = $detector->message();
			}
			catch (Exception $e)
			{
				$this->setError($e->getMessage());
			}

			$this->mark($id, $spam, $msg);
		}

		$result = new Result($failure > 0, $messages);

		return $result;
	}
219317
public function sendMassMessage($data)
    {
        return $this->auth(function () use ($data) {
            if (!is_string($data)) {
                $data = json_encode($data, JSON_UNESCAPED_UNICODE);
            }

            return $this->http->postJson(
                $this->baseUrl . 'cgi-bin/message/mass/send?access_token=' . $this->accessToken,
                $data
            );
        });
    }
1040810
public function sendMessage(array $data)
    {
        $result = $this->httpRaw(self::WECHAT_MESSAGE_SEND_PREFIX, $data, [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok' ? $result : $this->dump([self::WECHAT_BASE_URL . self::WECHAT_MESSAGE_SEND_PREFIX, $this->getAccessToken(), $data, $result]);
    }
669504
public function success($msg = null, $data = null, $extraData = [])
    {
        $return = $this->output(1, $msg, $data, $extraData);

        return $this->responseJson($return);
    }
315774
private static Date getSentDate(MimeMessage msg, Date defaultVal) {
        if (msg == null) {
            return defaultVal;
        }
        try {
            Date sentDate = msg.getSentDate();
            if (sentDate == null) {
                return defaultVal;
            } else {
                return sentDate;
            }
        } catch (MessagingException me) {
            return new Date();
        }
    }
329287
public function set($data)
    {
        $this->error = [];
        $result = null;
        switch ($this->format) {
            case 'nvp':
                parse_str($data, $this->data);
                $result = !empty($this->data);
                break;

            case 'json':
            default:
                $this->data = empty($data) ? [] : (json_decode($data, true) ?: []);
                $result = json_last_error() == JSON_ERROR_NONE;
                if (empty ($result)) {
                    $this->error = [
                        'error' => json_last_error(),
                        'msg'   => json_last_error_msg(),
                    ];
                }
                break;
        }

        return $result;
    }
552841
protected function buildSendPackageData(array $data)
    {
        if (preg_match('/^(62[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data[ 'msisdn' ]) == 1) {
            $data[ 'msisdn' ] = '0' . substr($data[ 'msisdn' ], 2);
        } elseif (preg_match('/^(\+62[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data[ 'msisdn' ]) == 1) {
            $data[ 'msisdn' ] = '0' . substr($data[ 'msisdn' ], 3);
        }

        if (preg_match('/^(0[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data[ 'msisdn' ]) == 1) {
            return [
                'number'          => trim($data[ 'msisdn' ]),
                'message'         => urlencode(stripslashes(utf8_encode($data[ 'message' ]))),
                'sendingdatetime' => isset($data[ 'sendingTime' ]) ? $data[ 'sendingTime' ] : null,
            ];
        }

        return false;
    }
713606
public function log($msg, $level = ProcessLogger::INFO, array $data = [])
    {
        $msg = sprintf('[%s:%d] %s', $this->getPidRole(), $this->pid, $msg);

        return $this->lgr->log($msg, $level, $data);
    }
707141
public function sendTemplateMessage(array $data)
    {
        $result = $this->httpRaw(self::WECHAT_TEMPLATE_MESSAGE_SEND_PREFIX, array_merge([
            'url' => null,
            'topcolor' => '#FF0000'
        ], $data), [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['msgid']) ? $result['msgid'] : false;
    }
980240
public function parseServerFinalMessage($msg)
    {
        foreach (explode(',', $msg) as $val) {
            list($attr, $aval) = array_map('trim', explode('=', $val, 2));

            switch ($attr) {
            case 'e':
                return false;

            case 'v':
                return (base64_decode($aval) === $this->_serversig);
            }
        }

        return false;
    }
94518
protected function message_read($data)
    {
        $cmd = Utility::ParseCommand(ord($data[0]));
        $message_type = $cmd['message_type'];
        $flags = $cmd['flags'];
        Debug::Log(Debug::DEBUG, "message_read(): message_type=" . Message::$name[$message_type] . ", flags={$flags}");
        Debug::Log(Debug::DEBUG, 'message_read(): Dump', $data);
        $pos = 1;
        $remaining_length = Utility::DecodeLength($data, $pos);
        $message_object = $this->getMessageObject($message_type);
        $message_object->decode($data, $remaining_length);
        return $message_object;
    }
362202
private function emitMessage( $data ) {
		$msg = "event: message\n";
		$msg .= 'data: ' . wp_json_encode( $data ) . "\n\n";
		$msg .= ':' . str_repeat( ' ', 2048 ) . "\n\n";
		// Buffers are nested. While one buffer is active, flushing from child buffers are not really sent to the browser,
		// but rather to the parent buffer. Only when there is no parent buffer are contents sent to the browser.
		if ( ob_get_level() ) {
			// Keep for later
			$this->msgStack[] = $msg;
		} else {
			// Flush to browser
			foreach ( $this->msgStack as $stack ) {
				echo $stack;
			}
			$this->msgStack = []; // Reset
			echo $msg;
			flush();
		}
	}
829967
protected function _msgText($stream, $data)
    {
        if ($data instanceof Horde_Stream) {
            if ($stream) {
                $data->rewind();
                return $data->stream;
            }
            return strval($data);
        }

        if (is_resource($data)) {
            rewind($data);
            return $stream
                ? $data
                : stream_get_contents($data);
        }

        if (!$stream) {
            return strval($data);
        }

        $tmp = fopen('php://temp', 'w+');

        if (!is_null($data)) {
            fwrite($tmp, $data);
            rewind($tmp);
        }

        return $tmp;
    }