| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * 站点设置.
- *
- * @author ningque
- * @date 2020-01-22 11:36:11
- */
- declare(strict_types=1);
- namespace Modules\Api\Services;
- class SiteService
- {
- public function makeFilename($rootPath, $id = 1, $depth = 2)
- {
- $filename = '';
- for ($i = 1; $i <= $depth; $i++) {
- $str = random(2);
- $rootPath .= '/' . $str;
- $filename .= $str;
- }
- $filename = $id . $depth . $filename . md5(microtime()) . mt_rand(1000, 9999) . '.mp4';
- $this->mkDirs($rootPath);
- return [
- 'filename' => $filename,
- 'path' => $rootPath,
- ];
- }
- public function mkDirs($dir, $mode = 0777)
- {
- if (is_dir($dir) || @mkdir($dir, $mode)) {
- return true;
- }
- if (!$this->mkDirs(dirname($dir), $mode)) {
- return false;
- }
- return @mkdir($dir, $mode);
- }
- public function writeLog($filename, $msg)
- {
- $file = public_path('/logs/' . $filename . date('Ymd') . '.log');
- !is_dir(dirname($file)) && mkdir(dirname($file), 0777, true);
- $handle = fopen($file, 'a');
- flock($handle, LOCK_EX);
- fwrite($handle, sprintf("%s\r\n%s\r\n", date('Y-m-d H:i:s', time()), $msg));
- flock($handle, LOCK_UN);
- fclose($handle);
- }
- public function encryptImage($cover, $path)
- {
- $path = '/var/www/resource/wp/ig/' . $path . '/'. date('mdH', time());
- $name = $path . '/' .substr(md5(microtime()) . mt_rand(1000, 9999), 0, 16);
- $this->mkDirs($path);
- $encryptImage = aes_encrypt(file_get_contents($cover), 'wPK8CxWaOwPuVzgs', '', 'AES-128-ECB');
- file_put_contents($name. '.ceb', $encryptImage);
- file_put_contents($name. '.png', file_get_contents($cover));
- $name = str_replace('/var/www/resource/wp', '', $name);
- return $name. '.ceb';
- }
- }
|