优化获取链接功能
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\cunkebao\controller;
|
||||
|
||||
use app\cunkebao\model\ContentLibrary;
|
||||
use app\cunkebao\model\ContentItem;
|
||||
use library\s2\titleFavicon;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use app\api\controller\WebSocketController;
|
||||
@@ -330,7 +331,7 @@ class ContentLibraryController extends Controller
|
||||
$library->timeEnd = isset($param['endTime']) ? strtotime($param['endTime']) : 0;
|
||||
$library->status = isset($param['status']) ? $param['status'] : 0;
|
||||
$library->updateTime = time();
|
||||
|
||||
|
||||
|
||||
$library->save();
|
||||
|
||||
@@ -752,7 +753,26 @@ class ContentLibraryController extends Controller
|
||||
/************************************
|
||||
* 数据采集相关功能
|
||||
************************************/
|
||||
|
||||
|
||||
function getExternalPageDetails($url)
|
||||
{
|
||||
$html = file_get_contents($url);
|
||||
$dom = new \DOMDocument();
|
||||
@$dom->loadHTML($html);
|
||||
$xpath = new \DOMXPath($dom);
|
||||
|
||||
// 获取标题
|
||||
$titleNode = $xpath->query('//title');
|
||||
$title = $titleNode->length > 0 ? $titleNode->item(0)->nodeValue : '';
|
||||
|
||||
// 获取图标链接
|
||||
$iconNode = $xpath->query('//link[@rel="shortcut icon"]/@href');
|
||||
$icon = $iconNode->length > 0 ? $iconNode->item(0)->nodeValue : '';
|
||||
|
||||
return ['title' => $title, 'icon' => $icon];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行朋友圈采集任务
|
||||
* @return \think\response\Json
|
||||
@@ -1414,22 +1434,33 @@ class ContentLibraryController extends Controller
|
||||
$urls = [];
|
||||
$url = is_string($moment['urls']) ? json_decode($moment['urls'], true) : $moment['urls'] ?? [];
|
||||
$url = $url[0];
|
||||
if(strpos($url, 'feishu.cn') !== false){
|
||||
|
||||
// 检查是否是飞书链接
|
||||
if (strpos($url, 'feishu.cn') !== false) {
|
||||
// 飞书文档需要登录,无法直接获取内容,返回默认信息
|
||||
$urls[] = [
|
||||
'url' => $url,
|
||||
'image' => 'http://karuosiyujzk.oss-cn-shenzhen.aliyuncs.com/2025/07/09/3db2a5d7fe49011ab68175a42a5094ce.jpeg',
|
||||
'desc' => '点击查看详情'
|
||||
'desc' => '飞书文档'
|
||||
];
|
||||
}else{
|
||||
$urls[] = [
|
||||
'url' => $url,
|
||||
'image' => 'http://karuosiyujzk.oss-cn-shenzhen.aliyuncs.com/2025/07/09/ec039d96fad6eab1d960f207d3d9ca9f.jpeg',
|
||||
'desc' => '点击查看详情'
|
||||
];
|
||||
$getUrlDetails = $this->getExternalPageDetails($url);
|
||||
$icon = 'http://karuosiyujzk.oss-cn-shenzhen.aliyuncs.com/2025/07/09/ec039d96fad6eab1d960f207d3d9ca9f.jpeg';
|
||||
if (!empty($getUrlDetails['title'])) {
|
||||
$urls[] = [
|
||||
'url' => $url,
|
||||
'image' => $icon,
|
||||
'desc' => '点击查看详情'
|
||||
];
|
||||
}else{
|
||||
$urls[] = [
|
||||
'url' => $url,
|
||||
'image' => !empty($getUrlDetails['icon']) ? $getUrlDetails['icon'] : $icon,
|
||||
'desc' => $getUrlDetails['title']
|
||||
];
|
||||
}
|
||||
}
|
||||
$moment['urls'] = $urls;
|
||||
|
||||
|
||||
}elseif ($moment['type'] == 15){
|
||||
//视频
|
||||
$contentType = 3;
|
||||
|
||||
Reference in New Issue
Block a user