request->post() : $aParam; // 获取输入参数 $sAuthorName = empty($aParam['author_name']) ? '' : $aParam['author_name']; $affiliation = empty($aParam['affiliation']) ? '' : $aParam['affiliation']; // 验证输入 if (empty($sAuthorName) || empty($affiliation)) { return json_encode(['status' => 2,'msg' => '']); } $url = "https://api.elsevier.com/content/search/author?query=affil(beijing)&count=1"; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_HTTPHEADER => [ 'X-ELS-APIKey: ' . $this->sApiKey, 'Accept: application/json' ], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_FAILONERROR => true ]); $response = curl_exec($ch); var_dump(curl_getinfo($ch));exit; // 第一步:检索作者ID $url = "https://api.elsevier.com/content/search/author"; $params = [ 'query' => "AUTHFIRST({$sAuthorName}) AND AFFIL({$affiliation})", 'count' => 1 ]; var_dump($this->sApiKey);exit(); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url . '?' . http_build_query($params), CURLOPT_HTTPHEADER => [ 'X-ELS-APIKey: ' . $this->sApiKey, 'Accept: application/json' ], CURLOPT_RETURNTRANSFER => true, // CURLOPT_TIMEOUT => 15, CURLOPT_FAILONERROR => true ]); $response = curl_exec($ch); echo '
';var_dump($response,curl_getinfo($ch));exit;
        if (curl_errno($ch)) {
            throw new \Exception('Scopus API错误: ' . curl_error($ch));
        }

        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($httpCode !== 200) {
            throw new \Exception("Scopus API返回错误: HTTP {$httpCode}");
        }

        $data = json_decode($response, true);
        if (empty($data['search-results']['entry'][0]['dc:identifier'])) {
            throw new \Exception('未找到匹配的作者');
        }

        // 提取作者ID(从"AUTHOR_ID:7004212771"中分离)
        $identifier = $data['search-results']['entry'][0]['dc:identifier'];
        $authorId = explode(':', $identifier)[1];

        // 第二步:获取作者指标
        $url = "https://api.elsevier.com/content/author/author_id/{$authorId}?view=METRICS";
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => $url,
            CURLOPT_HTTPHEADER => [
                'X-ELS-APIKey: ' . $apiKey,
                'Accept: application/json'
            ],
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 15,
            CURLOPT_FAILONERROR => true
        ]);

        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            throw new \Exception('指标API错误: ' . curl_error($ch));
        }

        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($httpCode !== 200) {
            throw new \Exception("指标API返回错误: HTTP {$httpCode}");
        }

        $data = json_decode($response, true);
        if (empty($data['author-retrieval-response'][0]['h-index'])) {
            throw new \Exception('未找到h指数数据');
        }

        // 提取其他作者信息
        $author = $data['author-retrieval-response'][0];
        $metrics = [
            'h_index' => $author['h-index'],
            'citation_count' => $author['citation-count'] ?? '未知',
            'document_count' => $author['document-count'] ?? '未知',
            'coauthors_count' => $author['coauthor-count'] ?? '未知',
            'affiliation_current' => $author['affiliation-current']['affiliation']['ip-doc']['afdispname'] ?? '未知'
        ];

        return json([
            'status' => 'success',
            'author_id' => $authorId,
            'author_name' => $author['author-profile']['preferred-name']['ce:indexed-name'] ?? '未知',
            'metrics' => $metrics
        ]);

        
    }
}