修改自动推广的相关任务

This commit is contained in:
wangjinlei
2026-05-13 12:26:28 +08:00
parent c36eba77b1
commit fa878334cd
7 changed files with 289 additions and 29 deletions

View File

@@ -6,6 +6,7 @@ use think\Db;
use think\Env;
use think\Queue;
use think\Validate;
use app\common\CrossrefService;
class Preaccept extends Base
{
@@ -708,36 +709,66 @@ class Preaccept extends Base
}
/**
* 通过 DOI 获取文献元数据Crossref REST API
*
* POST 参数:
* doi 必填,可为纯 DOI10.xxxx/...)或 https://doi.org/10.xxxx/...
*
* 返回 data.formate 与旧版字段兼容: author, title, joura, dateno, doilink
* 另附 data.crossref: 原始摘要字段(不含 raw message避免体积过大
*/
public function searchDoi()
{
$data = $this->request->post();
$rule = new Validate([
"doi" => "require"
'doi' => 'require',
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$doi = str_replace('/', '%2F', $data['doi']);
// $url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$url = "https://citation.doi.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$res = myGet($url);
$frag = trim(substr($res, strpos($res, '.') + 1));
if ($frag == "") {
return jsonError("not find");
$doiInput = trim((string)$data['doi']);
if ($doiInput === '') {
return jsonError('doi empty');
}
if (mb_substr_count($frag, '.') != 3) {
return jsonError("formate fail");
// 去掉 URL 前缀,得到裸 DOI
$doiNorm = preg_replace('#^https?://(dx\.)?doi\.org/#i', '', $doiInput);
$doiNorm = trim($doiNorm, " \t\n\r\0\x0B/");
$svc = new CrossrefService([
'mailto' => trim((string)Env::get('crossref_mailto', '')),
]);
$summary = $svc->fetchWorkSummary($doiNorm);
if ($summary === null || empty($summary['doi'])) {
return jsonError('DOI not found or invalid (Crossref)');
}
$res = explode('.', $frag);
$f['author'] = prgeAuthor($res[0]);
$f['title'] = trim($res[1]);
$bj = bekjournal($res[2]);
$joura = formateJournal(trim($bj[0]));
$f['joura'] = $joura;
$f['dateno'] = str_replace(' ', '', str_replace('-', '', trim($bj[1])));
$f['doilink'] = strpos($data['doi'], "http") === false ? "http://doi.org/" . $data['doi'] : $data['doi'];
$re['formate'] = $f;
return jsonSuccess($re);
$title = trim((string)($summary['title'] ?? ''));
$jouraRaw = trim((string)($summary['joura'] ?? ''));
$authorStr = trim((string)($summary['author_str'] ?? ''));
$dateno = trim((string)($summary['dateno'] ?? ''));
$doilink = trim((string)($summary['doilink'] ?? ''));
if ($doilink === '') {
$doilink = 'https://doi.org/' . $summary['doi'];
}
$f = [
'author' => $authorStr !== '' ? prgeAuthor($authorStr) : '',
'title' => $title,
'joura' => $jouraRaw !== '' ? formateJournal($jouraRaw) : '',
'dateno' => str_replace(' ', '', str_replace('-', '', $dateno)),
'doilink' => $doilink,
];
$crossrefOut = $summary;
unset($crossrefOut['raw']);
return jsonSuccess([
'formate' => $f,
'crossref' => $crossrefOut,
'doi' => $summary['doi'],
]);
}