处理base64编码的图片上传
@return bool
773556
public function upBase64()
    {
        $base64Data = Yii::$app->request->post($this->fileField);
        $img = base64_decode($base64Data);
        $this->oriName = $this->config['oriName'];
        $this->fileSize = strlen($img);
        $this->fileType = $this->getExtension();
        $this->fullName = $this->getFullName();
        $this->filePath = $this->getFilePath();
        $this->fileName = $this->getFileName();
        $dirName = dirname($this->filePath);

        if (!is_dir($dirName)) {//递归创建保存目录
            FileHelper::createDirectory($dirName, $this->dirMode, true);
        }
        //检查文件大小是否超出限制
        if (!$this->checkSize()) {
            $this->stateInfo = Yii::t('attachment', 'The file size exceeds the site limit.');
            return false;
        }

        //移动文件
        if (!(file_put_contents($this->filePath, $img) && file_exists($this->filePath))) { //移动失败
            $this->stateInfo = Yii::t('attachment', 'An error occurred while saving the file.');
            return false;
        } else { //移动成功
            $this->saveModel();
            $this->stateInfo = 'SUCCESS';
            return true;
        }
    }
595702
public function isBase64()
    {
        // An empty string is by definition not encoded.
        if ($this->getLength() === 0) return false;

        // Grab the current string value.
        $possiblyEncoded = $this->scalarString;

        // Attempt to decode it.
        $decoded = base64_decode($possiblyEncoded, true);

        // If we get false it can't be base64
        if ($decoded === false) return false;

        // Lets double check
        return (base64_encode($decoded) === $this->scalarString);
    }
1176400
private function upBase64()
    {
        $base64Data = $_POST[$this->fileField];
        $img = base64_decode($base64Data);

        $this->oriName = $this->config['oriName'];
        $this->fileSize = strlen($img);
        $this->fileType = $this->getFileExt();
        $this->fullName = $this->getFullName();
        $this->filePath = $this->getFilePath();
        $this->fileName = $this->getFileName();
        $dirname = dirname($this->filePath);

        //检查文件大小是否超出限制
        if (! $this->checkSize()) {
            $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
            return;
        }

        //创建目录失败
        if (! file_exists($dirname) && ! mkdir($dirname, 0777, true)) {
            $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
            return;
        } else {
            if (! is_writeable($dirname)) {
                $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
                return;
            }
        }

        //移动文件
        if (! (file_put_contents($this->filePath, $img) && file_exists($this->filePath))) { //移动失败
            $this->stateInfo = $this->getStateInfo("ERROR_WRITE_CONTENT");
        } else { //移动成功
            $this->stateInfo = $this->stateMap[0];
        }

    }
547390
public function setKey()
    {
        if(trim(env('APP_KEY')) != '') {
            return true;
        }
        $appKey='';
        for($i=0;$i<32;$i++) {
            $appKey.=chr(rand(0,255));
        }
        $appKey = 'base64:'.base64_encode($appKey);
        $file = $this->basePath('.env');
        $lines = $this->parseEnvFile($file);
        $flag = false;
        foreach($lines as $i => $line) {
            $lines[$i] = trim($line);
            $lines[$i] = trim($line, "\n");
            if(strpos($line, 'APP_KEY') !== false) {
                $data = explode('=', $line, 2);
                if(!isset($data[1]) || trim($data[1]) == '') {
                    $lines[$i] = "APP_KEY=".$appKey;
                    $flag = true;
                }
            }
        }
        if($flag == false) {
            $lines = ["APP_KEY=".$appKey] + $lines;
        }
        $data = implode("\n", $lines);
        if(file_put_contents($file, $data)) {
            putenv("APP_KEY=$appKey");
            $_ENV['APP_KEY'] = $appKey;
            $_SERVER['APP_KEY'] = $appKey;
            return true;
        }
        else {
            throw new Exception('Failed to write in .env file.');
        }
    }
433333
public function isFromKeyword()
    {
        // 未加载,说明未匹配到任何关键字
        if (!$this->loaded) {
            return false;
        }

        // 已加载,但id为空,说明未匹配到任何关键字
        if ($this->loaded && !$this['id']) {
            return false;
        }

        // 如果是默认回复,说明未匹配到任何关键字
        if ($this['id'] == 'default') {
            return false;
        }

        return true;
    }
489242
public static function create($base64)
    {
        if (($pos = strpos($base64, self::STOPPER)) !== false) {
            $base64 = substr($base64, $pos + strlen(self::STOPPER));
        }

        return \Yii::createObject([
            'class'  => self::className(),
            'base64' => $base64
        ]);
    }
704471
public function render()
    {
        $value = $this->arguments['value'];
        if ($value === null) {
            $value = $this->renderChildren();
        }
        if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            return $value;
        }

        return base64_decode($value);
    }
390299
public function getHex64(): string
    {
        $result = '0x';
        for ($i = 7; $i >= 0; $i--) {
            $result .= sprintf('%02X', $this->bytes[$i]);
        }
        return $result;
    }
442869
public function verify()
    {
        $data = file_get_contents("php://input");
        $data = Xml::xmlToArr($data);
        if ($data['sign'] != Helper::signature($data, Datasheet::get('md5_key'))) {
            throw new \Exception('微信异步通信签名验证失败');
        }
        return $data;
    }
713689
public static function convertAlphabets($base64)
    {
        $base64 = rtrim($base64, '=');
        return strtr($base64, self::BASE64_ALPHABET, self::ALPHABET);
    }
628441
public function toBase64() {
        ob_start ();
        $this->saveAs();
        $data = ob_get_contents();
        ob_end_clean();
        return 'data:image/'.$this->realType.';base64,'.base64_encode($data);
    }
161318
function urlToBase64 (url) {
  return new Promise((resolve, reject) => {
    request.get(url, (err, response, body) => {
      err && reject(err)
      resolve(body.toString('base64'))
    })
  })
}
908176
public function getBase64Source(){
                $Fullpath = $this->owner->getFullPath();

                $cache = SS_Cache::factory('Base64Image');
                $cachekey = md5($Fullpath);
                if(!($Base64Image = $cache->load($cachekey))){
                    $Base64Image = base64_encode(file_get_contents($Fullpath));
                    $cache->save($Base64Image);
                }

                $type = strtolower($this->owner->getExtension());

                return "data:image/".$type.";base64,".$Base64Image;
        }
194500
public static function EnableGZipEncoding () {
		return static::LasyClassVarConstAccessCallback('accept_encoding_gzip', function () {
			$accept_encodings = \ickx\fw2\core\net\http\Request::GetHeader('Accept-Encoding');
			if ($accept_encodings === false) {
				return false;
			}
			foreach (explode(',', $accept_encodings) as $accept_encoding) {
				if (trim($accept_encoding) === 'gzip') {
					return true;
				}
			}
			return false;
		});
	}
583241
public function getKey()
    {
        if (Str::startsWith($this->key, 'base64:')) {
            return base64_decode(substr($this->key, 7));
        }

        return $this->key;
    }
189098
public function result()
    {
        $hash = strtoupper(md5($this->p_id . $this->s_id . $this->o_id . $this->tr_id . $this->key));

        if ($hash == $this->hash) //Əgər dogrudursa 1, yoxsa 0 qaytarılmalı
        {
            return true;
        } else {
            return false;
        }
    }
1201481
public function valid()
    {
        $encryptStr = "";
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            $postStr = file_get_contents("php://input");
            $disableEntities = libxml_disable_entity_loader(true);
            $array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            libxml_disable_entity_loader($disableEntities);
            $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"] : '';
            if ($this->encrypt_type == 'aes') {
                $encryptStr = $array['Encrypt'];
                !class_exists('Prpcrypt', false) && require __DIR__ . '/Prpcrypt.php';
                $pc = new Prpcrypt($this->encodingAesKey);
                $array = $pc->decrypt($encryptStr, $this->appid);
                if (!isset($array[0]) || intval($array[0]) > 0) {
                    $this->errCode = $array[0];
                    $this->errMsg = $array[1];
                    Tools::log("Interface Authentication Failed. {$this->errMsg}[{$this->errCode}]", "ERR - {$this->appid}");
                    return false;
                }
                $this->postxml = $array[1];
                empty($this->appid) && $this->appid = $array[2];
            } else {
                $this->postxml = $postStr;
            }
        } elseif (isset($_GET["echostr"])) {
            if ($this->checkSignature()) {
                @ob_clean();
                exit($_GET["echostr"]);
            }
            return false;
        }
        if (!$this->checkSignature($encryptStr)) {
            $this->errMsg = 'Interface authentication failed, please use the correct method to call.';
            return false;
        }
        return true;
    }