shorty = new Shorty(config("app.domain")); } /** * 获取短地址 */ public function getShortUrl($urls) { $isArray = 0; if (is_array($urls)) { $isArray = 1; } $urls = is_array($urls) ? $urls : [$urls]; $list = []; foreach ($urls as $url) { $key = "shortUrl_" . md5($url); $value = Cache::get($key, ''); if ($value) { $list[$url] = $value; continue; } try { $list[$url] = $this->shorty->run($url); Cache::put($key, $list[$url], 86400 * 7); } catch (\Exception $e) { \Log::info($e->getMessage()); //continue; } } if ($isArray == 0) { return $list[$urls[0]] ?? ''; } else { return $list; } } /** * 获取短地址访问量 */ public function getShortUrlHits($urls) { return UrlsFacade::getShortUrlHits($urls); } }