今日诗词API 是一个可以免费调用的诗词接口

文章介绍了如何使用JavaScriptSDK集成‘今日诗词API’,该API能根据条件智能推荐诗词并支持图片和JSON格式。同时,还展示了调用搜狐的IP接口来显示网页访客的地址、IP和行政区划代码,但2023年5月30日后该功能已不可用。
摘要由CSDN通过智能技术生成

一、今日诗词API 

每次返回一句诗词,根据时间、地点、天气、事件智能推荐,支持图片和 JSON 格式调用,一分钟快速部署

今日诗词

<span id="jinrishici-sentence">正在加载今日诗词....</span>
<script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>

使用

直接将代码粘贴保存在想要展示的位置即可。

效果图:每次刷新请求一次。

以下为jinrishici.js 内容

/**
 * 今日诗词V2 JS-SDK 1.2.2
 * 今日诗词API 是一个可以免费调用的诗词接口:https://www.jinrishici.com
 */
!function(e){var n,t={},o="jinrishici-token";function i(){return document.getElementById("jinrishici-sentence")||0!=document.getElementsByClassName("jinrishici-sentence").length}function c(){t.load(function(e){var n=document.getElementById("jinrishici-sentence"),t=document.getElementsByClassName("jinrishici-sentence");if(n&&(n.innerText=e.data.content),0!==t.length)for(var o=0;o<t.length;o++)t[o].innerText=e.data.content})}function r(e,n){var t=new XMLHttpRequest;t.open("get",n),t.withCredentials=!0,t.send(),t.onreadystatechange=function(n){if(4===t.readyState){var o=JSON.parse(t.responseText);"success"===o.status?e(o):console.error("今日诗词API加载失败,错误原因:"+o.errMessage)}}}t.load=function(n){return e.localStorage&&e.localStorage.getItem(o)?function(e,n){return r(e,"https://v2.jinrishici.com/one.json?client=browser-sdk/1.2&X-User-Token="+encodeURIComponent(n))}(n,e.localStorage.getItem(o)):function(n){return r(function(t){e.localStorage.setItem(o,t.token),n(t)},"https://v2.jinrishici.com/one.json?client=browser-sdk/1.2")}(n)},e.jinrishici=t,i()?c():(n=function(){i()&&c()},"loading"!=document.readyState?n():document.addEventListener?document.addEventListener("DOMContentLoaded",n):document.attachEvent("onreadystatechange",function(){"complete"==document.readyState&&n()}))}(window);

二、简单调用搜狐的IP接口让网页显示访客信息的代码,在要显示的布局位置添加下面代码即可。

2023年05月30日,测试,已不可用,

 

 <script src="//pv.sohu.com/cityjson?ie=utf-8">
    </script>
    <div style="background-color: #b7b1f2;">
        你的地址:
        <script type="text/javascript">
            document.write(returnCitySN["cname"]);
        </script>
        你的ip:
        <script type="text/javascript">
            document.write(returnCitySN["cip"]);
        </script>
        行政区划代码:
        <script type="text/javascript">
            document.write(returnCitySN["cid"]);
        </script>
    </div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lxw1844912514

你的打赏就是对我最大的鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值