一言·古诗词 API
<img src="https://api.gushi.ci/all.svg">
<h3>简介</h3>
<p>古诗词·一言API 是一个可以随机返回一句古诗词名句的接口。具有以下特点:</p>
<ul>
<li>快:使用 Vert.x Java 全异步框架开发,使用Redis数据库,确保毫秒级稳定响应。</li>
<li>全:支持 svg / txt / json / png 调用,满足你在任何地方的调用需求</li>
<li>准:可以根据你的喜好,在指定的分类中进行随机返回</li>
</ul>
<p>项目首页:<a href="https://gushi.ci"><a href="https://gushi.ci">https://gushi.ci</a></a></p>
<h3>使用</h3>
<h4>API举例</h4>
<ul>
<li><a href="https://api.gushi.ci/all.json"><a href="https://api.gushi.ci/all.json">https://api.gushi.ci/all.json</a></a></li>
<li><a href="https://api.gushi.ci/all.svg"><a href="https://api.gushi.ci/all.svg">https://api.gushi.ci/all.svg</a></a></li>
<li><a href="https://api.gushi.ci/shuqing/libie.png"><a href="https://api.gushi.ci/shuqing/libie.png">https://api.gushi.ci/shuqing/libie.png</a></a></li>
<li><a href="https://api.gushi.ci/rensheng.txt"><a href="https://api.gushi.ci/rensheng.txt">https://api.gushi.ci/rensheng.txt</a></a></li>
</ul>
<h4>API地址格式(仅支持https)</h4>
<p><code>https://api.gushi.ci/{一级分类}/{二级分类(可选)}.{返回格式(可选)}</code></p>
<p>查看所有目前支持的分类:<a href="https://api.gushi.ci/"><a href="https://api.gushi.ci/">https://api.gushi.ci/</a></a></p>
<p>目前支持的后缀:.svg .txt .png .json 不加后缀默认返回 json</p>
<h4>SVG 调用</h4>
<pre><code class="language-html"><img src="https://api.gushi.ci/all.svg"></code></pre>
<p>SVG后缀是我们推荐的最优调用方案,可以在部分论坛、任何博客、小程序内无损直接调用,并且可以一定程度上控制样式。缺点是部分老旧浏览器不支持。</p>
<p>你可以直接修改svg控制最大长度</p>
<pre><code class="language-html"><img src="https://api.gushi.ci/all.svg" style="max-width:100%;"></code></pre>
<p>或者使用我们的<b>svg专用</b>的自定义参数
个性化参数</p>
<table>
<thead>
<tr>
<th>说明</th>
<th>参数名</th>
<th>默认值</th>
<th>合法范围</th>
</tr>
</thead>
<tbody>
<tr>
<td>字体大小(px)</td>
<td>font-size</td>
<td>20</td>
<td>[8,50]</td>
</tr>
<tr>
<td>字体间隔(px)</td>
<td>spacing</td>
<td>1.5</td>
<td>[0,30]</td>
</tr>
</tbody>
</table>
<p>调用示例</p>
<pre><code class="language-html"><img src="https://api.gushi.ci/all.svg?font-size=18&spacing=4"></code></pre>
<h4>JSON 调用</h4>
<pre><code class="language-html"><script>
var xhr = new XMLHttpRequest();
xhr.open('get', 'https://api.gushi.ci/all.json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var data = JSON.parse(xhr.responseText);
var gushici = document.getElementById('gushici');
gushici.innerText = data.content;
}
};
xhr.send();
</script></code></pre>
<p>JSON调用可以获取来源、作者、分类等信息,可以供你自定义拼接显示效果。</p>
<h4>PNG 调用</h4>
<pre><code class="language-html"><img src="https://api.gushi.ci/all.png"></code></pre>
<p>我们会提供透明的PNG文件。PNG方法兼容性最好,可以在几乎任何地方插入。并且支持所有浏览器。缺点是不能控制样式,另外,由于流量限制,我们只会给您传送较小的图片源文件。</p>
<h4>TXT 调用</h4>
<pre><code class="language-html"><script>
var xhr = new XMLHttpRequest();
xhr.open('get', 'https://api.gushi.ci/all.txt');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var gushici = document.getElementById('gushici');
gushici.innerText = xhr.responseText;
}
};
xhr.send();
</script></code></pre>
<p>TXT调用和JSON调用基本一致,可以节省一些流量。或者,你甚至可以使用 iframe 来调用我们的接口</p>
<h4>获取七天点击量数据</h4>
<p><a href="https://api.gushi.ci/log"><a href="https://api.gushi.ci/log">https://api.gushi.ci/log</a></a></p>
<blockquote>
<p>搬运自 <a href="https://github.com/xenv/gushici">xenv/gushici:<a href="https://github.com/xenv/gushici">https://github.com/xenv/gushici</a></a></p>
</blockquote>