以下示例代码适用于 www.apishop.net 网站下的API,使用本文提及的接口调用代码示例前,您需要先申请相应的API服务。

  1. 驾考题库:获取驾考题目与答案
  2. ISBN书号查询:通过10位或13位ISBN查询书号信息,包含书名、作者、出版社、价格、出版日期、印次、装帧方式、语种、摘要等信息。
  3. 万年历查询:查询指定日期的星期、星座、农历、生肖、天干地支、岁次、黄历相关的福神、喜神、宜忌等信息,还可以进行阴阳历转换。
  4. 节假日查询:全年节假日查询
  5. 成语大全:包含发音、解释、出自典故、近义词、反义词、例句等数据,可进行成语接龙、成语竞猜等游戏开发。
  6. 谜语大全:字谜、动物、灯谜、物品、儿童、植物、及成语等各种类型的谜语。
  7. 标准中文电码查询:中文、电码之间相互转换
  8. 新华字典:包含汉字的发音、部首、结构、笔顺、五笔、英文、解释、内容、多音字等。
  9. 汉语词典:包括词语的发音、解释、例子、出自、近义词、反义词等数据,包含成语、俗语等。
  10. 名言警句:涵盖人生、励志等多个方面
  11. 英语名言:激励自己、领悟人生、经典名言
  12. 绕口令:热门绕口令,经典绕口令,绕口令大全

API Shop(apishop.net)提供多达50款的常用第三方API,可以从github上下载代码示例合集:https://github.com/apishop/All-APIs

以上接口均包含PHP、Python、C#和Java等四种语言的代码示例,以 获取绕口令列表 API为例:

(1)基于PHP的 获取绕口令列表 API服务请求的代码示例

<?php
$method = "POST";
$url = "https://api.apishop.net/common/tongue/getTongueList";
$headers = NULL;
$params = array("page" => "", //页码"pageSize" => "", //获取条数(最多15条,默认10)
);$result = apishop_curl($method, $url, $headers, $params);
If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}
} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";
}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/
function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL)
{// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("\ufeff", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim");foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}
}
复制代码

(2)基于Python的 获取绕口令列表 API服务请求的代码示例

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 测试环境: python2.7
# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖
import requests
import json
import sysreload(sys)
sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"
url = "https://api.apishop.net/common/tongue/getTongueList"
headers = None
params = {         "page":"", #页码"pageSize":"", #获取条数(最多15条,默认10)
}
result = apishop_send_request(method=method, url=url, params=params, headers=headers)
if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))
else:# 返回内容异常,发送请求失败print('发送请求失败')
复制代码

(3)基于C#的 获取绕口令列表 API服务请求的代码示例

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;namespace apishop_sdk
{
class Program
{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, Dictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-urlencoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCount(paramData);using (Stream requestStream = wbRequest.GetRequestStream()){using (StreamWriter swrite = new StreamWriter(requestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();using (Stream responseStream = wbResponse.GetResponseStream()){using (StreamReader sread = new StreamReader(responseStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https://api.apishop.net/common/tongue/getTongueList";Dictionary<string, string> param = new Dictionary<string, string>();          param.Add("page", ""); //页码param.Add("pageSize", ""); //获取条数(最多15条,默认10)Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, headers);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Response>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", result));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", result));}Console.ReadLine();}}
}
复制代码

(4)基于Java的 获取绕口令列表 API服务请求的代码示例

package net.apishop.www.controller;import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;/**
* httpUrlConnection访问远程接口工具
*/
public class Api
{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数     重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String requestMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnection();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Content-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");//conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOutputStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https://api.apishop.net/common/tongue/getTongueList";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>();           params.put("page", ""); //页码params.put("pageSize", ""); //获取条数(最多15条,默认10) String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, params);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("result"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc"));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}
}
复制代码

eoLinker-API_Shop_知识类API调用的代码示例合集:驾考题库、ISBN书号查询、万年历查询等...相关推荐

  1. eoLinker-API_Shop_验证码识别与生成类API调用的代码示例合集:六位图片验证码生成、四位图片验证码生成、简单验证码识别等...

    以下示例代码适用于 www.apishop.net 网站下的API,使用本文提及的接口调用代码示例前,您需要先申请相应的API服务. 六位图片验证码生成:包括纯数字.小写字母.大写字母.大小写混合.数 ...

  2. rest api 示例2_REST API教程– REST Client,REST Service和API调用通过代码示例进行了解释

    rest api 示例2 Ever wondered how login/signup on a website works on the back-end? Or how when you sear ...

  3. 【JS】JavaScript中创建数组的6种方式(代码示例合集)

    创建数组的6种方式 <!DOCTYPE html> <html lang="en"><head><meta charset="U ...

  4. isbn书号查询api,根据图书ISBN查询详细信息

    isbn书号查询api,根据图书ISBN查询详细信息,目前支持 京东,当当,博库电商图书. 接口名称:isbn书号查询api 接口平台:开放接口 接口地址:http://v.juhe.cn/ebook ...

  5. 2020年前端面试之JS手写代码题合集

    2020年前端面试之JS手写代码题合集 预计会有上千道题,后续慢慢补! 1.  写一个把字符串大小写切换的方法 function caseConvert(str){return str.replace ...

  6. 收藏!PyTorch常用代码段合集

    ↑↑↑关注后"星标"Datawhale 每日干货 & 每月组队学习,不错过 Datawhale干货 作者:Jack Stark,来源:极市平台 来源丨https://zhu ...

  7. PyTorch常用代码段合集

    ↑ 点击蓝字 关注视学算法 作者丨Jack Stark@知乎 来源丨https://zhuanlan.zhihu.com/p/104019160 极市导读 本文是PyTorch常用代码段合集,涵盖基本 ...

  8. 【深度学习】PyTorch常用代码段合集

    来源 | 极市平台,机器学习算法与自然语言处理 本文是PyTorch常用代码段合集,涵盖基本配置.张量处理.模型定义与操作.数据处理.模型训练与测试等5个方面,还给出了多个值得注意的Tips,内容非常 ...

  9. 收藏 | PyTorch常用代码段合集

    点上方蓝字计算机视觉联盟获取更多干货 在右上方 ··· 设为星标 ★,与你不见不散 仅作学术分享,不代表本公众号立场,侵权联系删除 转载于:作者丨Jack Stark@知乎 来源丨https://zh ...

  10. 驾考题库API接口,免费好用

    1.前言 驾考题库API接口,公安部最新驾照考试题库,分小车.客车.货车.摩托车4类,科目一和科目四2种. 查看接口完整信息:https://www.idmayi.com/doc/detail?id= ...

最新文章

  1. 再发布一个windows live writer 插件 图标信息框 wlw plugin icon info frame
  2. 比特币现金众筹应用Lighthouse正式上线
  3. 不允许一个迭代的对象自己接着迭代下去(Python)【fronzenset】
  4. Spring Cloud Eureka 自我保护机制
  5. 页表长度和页表大小_在请求调页系统中,若逻辑地址中的页号超过页表控制寄存器中的页表长度,则会引起( ) 。_学小易找答案...
  6. 2021年中国单一麦芽的威士忌市场趋势报告、技术动态创新及2027年市场预测
  7. 女人让男人感到自卑的九个经典(摘于网络)
  8. 快速排序的C++实现
  9. Oracle常用操作【自己的练习】
  10. ROS1云课→22机器人轨迹跟踪
  11. colmak键盘_萌神进化 IKBC 新POKER2机械键盘体验
  12. dubbo filter原理
  13. 对许多张图片进行批量裁剪,看看我是如何快速做到的
  14. 机器视觉的9大快速开发库简单介绍
  15. 设计模式-抽象工厂总结
  16. Using a password on the command line interface can be insecure.
  17. html的音频在线地址,HTML 音频(Audio)
  18. spout 和bolt关系_在Bolt CMS中记录检索和分页
  19. swift python混合开发_引用swift项目
  20. LwIP源码分析(3):内存堆和内存池代码详解

热门文章

  1. Alex 的 Hadoop 菜鸟教程: 第7课 Hbase 使用教程
  2. 如何安装仿宋GB2312字体
  3. 【U8+】用友U816.1版本和天高联用,不显示“实施导航”功能模块
  4. 关于新版本Firefox浏览器无法使用firebug与firepath问题的解决方案
  5. Go 语言圣经-习题汇总(Go 程序设计语言/The Go Programming Language)
  6. BlueScreenView: 系统蓝屏分析工具
  7. sprintf_s用法c语言,sprintf_s函数的使用
  8. xamarin怎么调用java的_Xamarin使用教程六:如何引用JAR档案
  9. matlab数据存成脚本,matlab的excel的读和写(生成脚本m文件)
  10. 【目标检测】基于帧差法+Vibe算法实现车辆行人检测matlab源码