升级
This commit is contained in:
@@ -16,6 +16,10 @@ class CrossrefService
|
||||
private $timeout = 15; // 请求超时(秒)
|
||||
private $maxRetry = 2; // 单个DOI最大重试次数
|
||||
private $crossrefUrl = "https://api.crossref.org/works/"; // 接口地址
|
||||
private $pubmedAbbr = true; // CrossRef 无期刊缩写时,是否回退到 PubMed/NLM 规范缩写
|
||||
|
||||
/** @var PubmedService|null 懒加载 */
|
||||
private $pubmedService = null;
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
@@ -24,6 +28,7 @@ class CrossrefService
|
||||
if (isset($config['timeout'])) $this->timeout = intval($config['timeout']);
|
||||
if (isset($config['maxRetry'])) $this->maxRetry = intval($config['maxRetry']);
|
||||
if (isset($config['crossrefUrl'])) $this->crossrefUrl = (string)$config['crossrefUrl'];
|
||||
if (isset($config['pubmed_abbr'])) $this->pubmedAbbr = (bool)$config['pubmed_abbr'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +196,15 @@ class CrossrefService
|
||||
|
||||
$title = $this->getTitle($msg);
|
||||
$publisher = $this->getPublisher($msg);
|
||||
$joura = !empty($publisher['title']) ? $publisher['title'] : ($publisher['short_title'] ?? '');
|
||||
$validDoi = $this->filterValidDoi($doi);
|
||||
// 期刊缩写优先级:CrossRef short-container-title → PubMed/NLM 规范缩写 → CrossRef 全称
|
||||
$shortTitle = trim((string)($publisher['short_title'] ?? ''));
|
||||
$fullTitle = trim((string)($publisher['title'] ?? ''));
|
||||
$joura = $shortTitle;
|
||||
if ($joura === '') {
|
||||
$pubmedAbbr = $this->lookupPubmedJournalAbbr($validDoi);
|
||||
$joura = $pubmedAbbr !== '' ? $pubmedAbbr : $fullTitle;
|
||||
}
|
||||
$authors = $this->getAuthors($msg);
|
||||
$dateno = $this->getVolumeIssuePages($msg);
|
||||
$retractInfo = $this->checkRetracted($msg);
|
||||
@@ -280,6 +293,34 @@ class CrossrefService
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 用 PubMed/NLM 反查期刊规范缩写(CrossRef 无缩写时的兜底)。
|
||||
* 任何异常都吞掉并返回空串,保证不影响主流程。
|
||||
*
|
||||
* @param string $doi 已规整的裸 DOI
|
||||
* @return string 缩写或空串
|
||||
*/
|
||||
private function lookupPubmedJournalAbbr($doi)
|
||||
{
|
||||
$doi = trim((string)$doi);
|
||||
if (!$this->pubmedAbbr || $doi === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->pubmedService === null) {
|
||||
$this->pubmedService = new PubmedService([
|
||||
'email' => $this->mailto,
|
||||
'timeout' => $this->timeout,
|
||||
]);
|
||||
}
|
||||
$abbr = $this->pubmedService->journalAbbrByDoi($doi);
|
||||
return is_string($abbr) ? trim($abbr) : '';
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取作者列表
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user