mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
update api url
This commit is contained in:
parent
cdbbc159b9
commit
35df80aa21
@ -275,7 +275,7 @@ class Extranet
|
|||||||
case "soup":
|
case "soup":
|
||||||
$text = "鸡汤分完了";
|
$text = "鸡汤分完了";
|
||||||
$data = self::curl('https://api.ayfre.com/jt/?type=bot', 5);
|
$data = self::curl('https://api.ayfre.com/jt/?type=bot', 5);
|
||||||
if ($data = trim($data)) {
|
if ($data) {
|
||||||
$text = "心灵鸡汤:{$data}";
|
$text = "心灵鸡汤:{$data}";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -285,22 +285,27 @@ class Extranet
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $url
|
* @param $url
|
||||||
* @param int $cacheSecond
|
* @param int $cacheSecond 缓存时间(秒),如果结果为空则缓存有效30秒
|
||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function curl($url, int $cacheSecond = 0, int $timeout = 15): string
|
private static function curl($url, int $cacheSecond = 0, int $timeout = 15): string
|
||||||
{
|
{
|
||||||
if ($cacheSecond > 0) {
|
if ($cacheSecond > 0) {
|
||||||
$res = Cache::remember("curlCache::" . md5($url), Carbon::now()->addSeconds($cacheSecond), function () use ($timeout, $url) {
|
$key = "curlCache::" . md5($url);
|
||||||
return Ihttp::ihttp_request($url, [], [], $timeout);
|
$content = Cache::remember($key, Carbon::now()->addSeconds($cacheSecond), function () use ($cacheSecond, $key, $timeout, $url) {
|
||||||
|
$result = Ihttp::ihttp_request($url, [], [], $timeout);
|
||||||
|
$content = Base::isSuccess($result) ? trim($result['data']) : '';
|
||||||
|
if (empty($content) && $cacheSecond > 30) {
|
||||||
|
Cache::put($key, "", Carbon::now()->addSeconds(30));
|
||||||
|
}
|
||||||
|
return $content;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$res = Ihttp::ihttp_request($url, [], [], $timeout);
|
$result = Ihttp::ihttp_request($url, [], [], $timeout);
|
||||||
|
$content = Base::isSuccess($result) ? trim($result['data']) : '';
|
||||||
}
|
}
|
||||||
if (Base::isSuccess($res)) {
|
//
|
||||||
return $res['data'];
|
return $content;
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user