iHitokoto API(一言-纯净API)一言api

时间:2017-9-5    作者:晨曦    分类:


本API作用:去除原API的各种链接、各种#@%……¥&%#¥总之。。简洁得只剩下字了!

食用使用方法:

数据获取

  • 请求地址:http://tool.lsgzs.cc/hitokoto
  • 请求方式:GET
  • 请求编码:接口:charset 参数:UTF8/GBK(必须大写,默认UTF8)
  • 请求参数:接口:code 参数:js(为空则返回纯文本)

实例

请求http://tool.lsgzs.cc/hitokoto
返回 起风了,必须好好活下去。

调用举例 – JavaScript + HTML

脚本地址http://tool.lsgzs.cc/hitokoto/?code=js

使用方法

将下面这段代码放入页面内需要展示一句话的位置即可

 <script type="text/javascript" src="http://tool.lsgzs.cc/hitokoto/?code=js"></script><div id="xlhitokoto"><script>xlhitokoto()</script></div> 

该脚本实质为document.write的脚本。

演示一下:

直到理解之前,都要好好考虑。

刷新试试?会变哦~
API服务通过负载均衡托管于国内外多台服务器,国内外加载速度应该都不会过100ms的,如果不是什么神级网站应该都可以受得住的吧

PHP源码:

 <?php if ($_GET['charset']=='GBK'){ header('Content-Type: text/html; charset=GBK'); $array=file('hitokoto.txt'); $rand=rand(0,3385); function utf8_to_gbk($str){ return mb_convert_encoding($str, 'gbk', 'utf-8'); } $string=$array[$rand]; if ($_GET['code']==='js') { echo "function xlhitokoto(){document.write(\""; echo trim(utf8_to_gbk($string)) . "\");}"; }else{ echo trim(utf8_to_gbk($string)); } }else{ header('Content-Type: text/html; charset=UTF-8'); $array=file('hitokoto.txt'); $rand=rand(0,3385); $string=$array[$rand]; if ($_GET['code']==='js') { echo "function xlhitokoto(){document.write(\""; echo trim($string); echo "\");}"; }else{ echo trim($string); } } ?> 

纯净一言api地址:点我

晨曦经验分享

编码问题。不同场景不同配置嘛
用utf8的就调用http://too.lsgzs.cc/hitokoto/?code=js
用gbk的就调用http://tool.lsgzs.cc/hitokoto/?code=js&charset=GBK

关于跨域问题

遇到跨域问题而且不是自己域名下的get请求得用json