具体写操作

@param  $file string 日志文件的名称
@param  $msg string 要写入的信息
@return false|int 写入是否成功
542289
private function write(string $file, string $msg)
    {
        // 将文件名中的目录分隔符标准化
        $file = str_replace('\\', '/', $file);

        // 在日志目录下创建年目录
        $path = $this->dirRoot . date('Y-m-d') . '/' . $file . '.log';
        makeDir(dirname($path));

        // 写入文件
        return write($path, $msg, FILE_APPEND | LOCK_EX);
    }
339422
public function reply($msg)
    {
        // 获取消息类型
        $msg_type = '';
        if (gettype($msg)=='string') {
            $msg_type = 'text_simple';
        } elseif (gettype($msg)=='array') {
            $msg_type = $msg['type'];
        }

        switch ($msg_type) {
            /**
             * 1.1 回复文本消息(简洁输入)
             *
             * Examples:
             * ```
             * $wechat->reply('hello world!');
             * ```
             */
            case 'text_simple':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[text]]></MsgType>'.
                        '<Content><![CDATA[%s]]></Content>'.
                        '</xml>',
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg);
                break;

            /**
             * 1.2 回复文本消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
             *    'type' => 'text',
             *    'content' => '嘿嘿，呵呵~~'
             * ));
             * ```
             */
            case 'text':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[text]]></MsgType>'.
                        '<Content><![CDATA[%s]]></Content>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['content']);
                break;

            /**
             * 2 回复图片消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *     'type' => 'image',
              *    'media_id' => 'Uq7OczuEGEyUu--dYjg7seTm-EJTa0Zj7UDP9zUGNkVpjcEHhl7tU2Mv8mFRiLKC'
             * ));
             * ```
             */
            case 'image':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[image]]></MsgType>'.
                        '<Image><MediaId><![CDATA[%s]]></MediaId></Image>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['media_id']);
                break;

            /**
             * 3 回复语音消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *     'type' => 'voice',
              *    'media_id' => 'rVT43tfDwjh4p1BV2gJ5D7Zl2BswChO5L_llmlphLaTPytcGcguBAEJ1qK4cg4r_'
             * ));
             * ```
             */            
            case 'voice':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[voice]]></MsgType>'.
                        '<Voice><MediaId><![CDATA[%s]]></MediaId></Voice>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['media_id']);
                break;

            /**
             * 4 回复视频消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *    'type' => 'video',
              *    'media_id' => 'yV0l71NL0wtpRA8OMX0-dBRQsMVyt3fspPUzurIS3psi6eWOrb_WlEeO39jasoZ8',
              *    'title' => '视频消息的标题',            //可选
              *    'description' => '视频消息的描述'        //可选
             * ));
             * ```
             */
            case 'video':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[video]]></MsgType>'.
                        '<Video>'.
                        '<MediaId><![CDATA[%s]]></MediaId>'.
                        '<Title><![CDATA[%s]]></Title>'.
                        '<Description><![CDATA[%s]]></Description>'.
                        '</Video>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['media_id'], 
                        isset($msg['title']) ? $msg['title'] : '',
                        isset($msg['description']) ? $msg['description'] : '');
                break;

            /**
             * 5 回复音乐消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *    'type' => 'music',
              *    'title' => '音乐标题',                        //可选
              *    'description' => '音乐描述',                //可选
              *    'music_url' => 'http://me.diary8.com/data/music/2.mp3',        //可选
              *    'hqmusic_url' => 'http://me.diary8.com/data/music/2.mp3',    //可选
              *    'thumb_media_id' => 'O39wW0ZsXCb5VhFoCgibQs5PupFb6VZ2jH5A8gHUJCJz2Qmkrb7objoTue7bGTGQ',
             * ));
             * ```
             */
            case 'music':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[music]]></MsgType>'.
                        '<Music>'.
                        '<Title><![CDATA[%s]]></Title>'.
                        '<Description><![CDATA[%s]]></Description>'.
                        '<MusicUrl><![CDATA[%s]]></MusicUrl>'.
                        '<HQMusicUrl><![CDATA[%s]]></HQMusicUrl>'.
                        '<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>'.
                        '</Music>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(),
                        isset($msg['title']) ? $msg['title'] : '',
                        isset($msg['description']) ? $msg['description'] : '',
                        isset($msg['music_url']) ? $msg['music_url'] : '',
                        isset($msg['hqmusic_url']) ? $msg['hqmusic_url'] : '',
                        $msg['thumb_media_id']);
                break;

            /**
             * 6 回复图文消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
             *    'type' => 'news',
             *    'articles' => array(
             *        array(
             *            'title' => '图文消息标题1',                                 //可选
             *            'description' => '图文消息描述1',                           //可选
             *            'picurl' => 'http://me.diary8.com/data/img/demo1.jpg',      //可选
             *            'url' => 'http://www.example.com/'                          //可选
             *        ),
             *        array(
             *            'title' => '图文消息标题2',
             *            'description' => '图文消息描述2',
             *            'picurl' => 'http://me.diary8.com/data/img/demo2.jpg',
             *            'url' => 'http://www.example.com/'
             *        ),
             *        array(
             *            'title' => '图文消息标题3',
             *            'description' => '图文消息描述3',
             *            'picurl' => 'http://me.diary8.com/data/img/demo3.jpg',
             *            'url' => 'http://www.example.com/'
             *        )
             *     )
             * ));
             * ```
             */
            case 'news':
                $articles = '';
                foreach ($msg['articles'] as $article) {
                    $articles .= sprintf('<item>'.
                                    '<Title><![CDATA[%s]]></Title>'.
                                    '<Description><![CDATA[%s]]></Description>'.
                                    '<PicUrl><![CDATA[%s]]></PicUrl>'.
                                    '<Url><![CDATA[%s]]></Url>'.
                                '</item>', 
                                $article['title'],
                                $article['description'],
                                $article['picurl'],
                                $article['url']);
                }
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[news]]></MsgType>'.
                        '<ArticleCount>%s</ArticleCount>'.
                        '<Articles>%s</Articles>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(),
                        count($msg['articles']),
                        $articles);
                break;
            
            /**
             * 0 转发到多客服接口
             *
             * Examples:
             * ```
             * $wechat->reply(array(
             *    'type' => 'transfer_customer_service',
             *    'kf_account' => 'test1@test'                // 可选
             * ));
             * ```
             */
            case 'transfer_customer_service':
                $xml_transinfo = '';
                if (isset($msg['kf_account']) && !empty($msg['kf_account'])) {
                    $xml_transinfo = sprintf('<TransInfo>'.
                            '<KfAccount><![CDATA[%s]]></KfAccount>'.
                            '</TransInfo>',
                            $msg['kf_account']);
                }
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[transfer_customer_service]]></MsgType>%s'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(),
                        $xml_transinfo);
                break;

            /**
             * 0 异常消息处理
             *
             */ 
            default:
                @error_log("$msg_type is not a message type that can be used.", 0);
                exit();                
                break;
        }
        
        // 对消息加解密方式 兼容模式\安全模式 - 加密消息
        if ($this->encrypt_type == 'aes' && $xml != '') {

            // 异常处理: 未配置encodingAESKey
            if ($this->encodingAESKey === false) {
                @error_log('EncodingAESKey Not Defined.', 0);
                exit();
            }

            $reply_timestamp = time();

            // 消息加密
            $pc = new Prpcrypt($this->encodingAESKey);            
            $reply_encrypt = $pc->encrypt($xml, $this->appId);
            // 消息加密: 异常处理
            if ($reply_encrypt === false) {
                @error_log('Encrypt Message Error.', 0);
                exit();
            }

            // 生成安全签名
            $reply_signature = SHA1::getSHA1($this->token, $reply_timestamp, $this->nonce, $reply_encrypt);
            // 生成安全签名: 异常处理
            if ($reply_signature===false) {
                @error_log('Get Message Signature Error.', 0);
                exit();
            }

            // 生成发送的xml
            $xml = sprintf('<xml>'.
                        '<Encrypt><![CDATA[%s]]></Encrypt>'.
                        '<MsgSignature><![CDATA[%s]]></MsgSignature>'.
                        '<TimeStamp>%s</TimeStamp>'.
                        '<Nonce><![CDATA[%s]]></Nonce>'.
                        '</xml>', 
                        $reply_encrypt,
                        $reply_signature,
                        $reply_timestamp,
                        $this->nonce);
        }
error_log($xml);
        echo $xml;
    }
1198179
public static function readPo($file)
    {
        $file = file($file, FILE_IGNORE_NEW_LINES);
        
        $messages = array();
        $message = array();
        $property = null;
        
        foreach ($file as $line) {
            $line = trim($line);
            if ($line == '') {
                continue;
            }
            if ($line[0] == '#') {
                continue;
            }
            if ($line[0] == '"') {
                if (! isset($property)) {
                    continue;
                }
                $message[$property] .= stripcslashes(substr($line, 1, - 1));
                continue;
            }
            list ($property, $msg) = explode(' ', $line, 2);
            if ($property == 'msgid') {
                if (count($message)) {
                    $messages[] = $message;
                }
                $message = array();
            }
            $message[$property] = stripcslashes(substr($msg, 1, - 1));
        }
        if (count($message)) {
            $messages[] = $message;
        }
        
        $l = new Locale();
        foreach ($messages as $message) {
            if (! isset($message['msgid'])) {
                continue;
            }
            if ($message['msgid'] == '') {
                $properties = explode("\n", $message['msgstr']);
                foreach ($properties as $property) {
                    list ($property, $value) = explode(':', $property, 2);
                    if (trim(strtolower($property)) == 'plural-forms') {
                        $l->pluralForms = $value;
                        break;
                    } elseif (trim(strtolower($property)) == 'language') {
                        $value = LanguageTag::parseTag($value);
                        $l->name = $value[0];
                        $l->region = $value[1];
                    }
                }
            }
            $id = $message['msgid'];
            if (isset($message['msgid_plural'])) {
                $id = $message['msgid_plural'];
                $plurals = array();
                foreach ($message as $property => $value) {
                    if ($value != '' and strncmp($property, 'msgstr', 5) == 0) {
                        $plurals[intval(substr($property, 7, - 1))] = $value;
                    }
                }
                if (count($plurals)) {
                    $l->set($id, $plurals);
                }
            } elseif (isset($message['msgstr'])) {
                $message = $message['msgstr'];
                if ($message != '') {
                    $l->set($id, $message);
                }
            }
        }
        return $l;
    }
127977
static function message($msg)
    {
        $msg = empty($msg) ? '' : $msg;

        if(!is_string($msg)) {
            $msg = json_encode($msg);
        }

        echo $msg;

        return true;
    }
920674
public function debug($msg = true, $file = null, $line = null)
    {
        if (is_bool($msg)) {
            $this->debug = $msg;

            return $this;
        }

        if (is_object($msg)) {
            throw $this->exception('Do not debug objects');
        }

        // The rest of this method is obsolete
        if ((isset($this->debug) && $this->debug)
            || (isset($this->app->debug) && $this->app->debug)
        ) {
            $this->app->outputDebug($this, $msg, $file/*, $line*/);
        }
    }
1114309
public static function getFileMimeType($file)
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        if ($finfo) {
            $mime_type = finfo_file($finfo, $file);
            finfo_close($finfo);
            return $mime_type;
        }
        return false;
    }
714706
public function write($msg, $type = 'info', $force = false)
    {
        // 封装日志信息
        $log = $this->log;

        if (true === $force || empty($this->config['level'])) {
            $log[$type][] = $msg;
        } elseif (in_array($type, $this->config['level'])) {
            $log[$type][] = $msg;
        } else {
            return false;
        }

        // 写入日志
        $result = $this->driver->save($log);

        if ($result) {
            $this->log = [];
        }

        return $result;
    }
369505
public static function checkMinLength($field, $minLength, $msg)
    {
        if ((StringUtils::isEmpty($field) === false) && mb_strlen($field) < $minLength) {
            throw new MsgException($msg);
        }
    }
206272
public static function log($msg)
    {
        $msg = $msg . "\n";
        if (!self::$daemonize) {
            self::safeEcho($msg);
        }
        file_put_contents((string)self::$logFile, date('Y-m-d H:i:s') . ' ' . 'pid:' . getmypid() . ' ' . $msg, FILE_APPEND | LOCK_EX);
    }
887540
public function check($file = '')
        {
            $types = $this->getAllowedMimeTypes();
            if ($types === '*') {
                return true;
            }

            // dosyanın tipini alıyoruz
            $fileMimeType = $this->getFileMimeType();
            foreach($types as $type)
            {
                 if($type === $fileMimeType){
                     return true;
                 }else{
                     continue;
                 }
            }

            return false;
        }
534018
public static function read($file)
    {
        $cwd = getcwd();
        $log = $cwd.'/producer.log';

        if (file_exists($file)) {
            file_put_contents($log, file_get_contents($file), FILE_APPEND);
        }
    }
258208
public function file_contains_php($file)
    {
        $contents = file_get_contents($file);
        $position = strpos($contents, '<?php');
        return $position !== false;
    }
1349855
public static function checkFile($file)
    {
        if (Symphony::Log()) {
            Symphony::Log()->pushDeprecateWarningToLog('General::checkFile()', '`General::checkFileWritable()');
        }
        clearstatcache();
        $dir = dirname($file);

        if (
            (!is_writable($dir) || !is_readable($dir)) // Folder
            || (file_exists($file) && (!is_readable($file) || !is_writable($file))) // File
        ) {
            return false;
        }

        return true;
    }
973361
public static function checkLength($field, $length, $msg)
    {
        if ((StringUtils::isEmpty($field) === false) && mb_strlen($field) != $length) {
            throw new MsgException($msg);
        }
    }
231755
public static function log($msg, $mod = null, $file = 0, $line = 0)
    {
        self::logInfo($msg, $mod, $file, $line);
    }
1225663
public function validatePhpFile($file)
    {
        if (!$this->canValidatePhpCode()) {
            return null;
        }

        $output = shell_exec('php -l ' . escapeshellarg($file));

        $count = 0;
        $error = preg_replace('/Errors parsing.*$/', '', $output, -1, $count);
        return $count > 0 ? trim("$error") : true;
    }
465278
private function msg($msg): string
    {
        // 将数组转为字符串
        if (is_array($msg) or is_object($msg) or is_bool($msg)) {
            return json($msg);
        }

        // 返回可显示的字符串
        return (string)$msg;
    }