谜语大全
ALAPI 官方文档
获取最新的谜语大全
基本说明:
接口地址:https://v1.alapi.cn/api/riddle
返回格式:json
请求方式:get/post
请求示例:https://v1.alapi.cn/api/riddle
请求参数说明:
名称 类型 必填 说明
num int 选填 获取谜语的数量,默认10条
page int 选填 页码数量
返回参数说明:
名称 类型 说明
title string 标题
content string 内容
answer string 谜底
JSON返回示例:
{
	"code": 200,
	"msg": "success",
	"data": {
		"current_page": 1,
		"data": [{
			"title": "秦观酒兴大发·下楼格--打一诗词句",
			"content": "秦观酒兴大发·下楼格",
			"answer": "多少游春意",
			"type": "shiwenmiyu",
			"type_name": {
				"type": "shiwenmiyu",
				"name": "诗文谜语",
				"desc": "顾名思义,诗文迷指猜诗文的谜语"
			}
		}],
		"first_page_url": "https://v1.alapi.cn/api/riddle?page=1",
		"from": 1,
		"last_page": 574,
		"last_page_url": "https://v1.alapi.cn/api/riddle?page=574",
		"next_page_url": "https://v1.alapi.cn/api/riddle?page=2",
		"path": "https://v1.alapi.cn/api/riddle",
		"per_page": 10,
		"prev_page_url": null,
		"to": 10,
		"total": 5731
	},
	"Author": {
		"name": "Alone88",
		"desc": "由Alone88提供的免费API 服务,官方文档:www.alapi.cn"
	}
}
服务级错误码参照
错误码 说明
500 处理异常
完整教学代码示例
<?php

/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2020/02/01 00:16
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://v1.alapi.cn/api/riddle';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "https://v1.alapi.cn/api/riddle"
)

func main() {
	queryUrl := fmt.Sprintf("%s",APIURL)
	resp, err := http.Get(queryUrl)
	if err != nil {
		log.Println(err)
		return
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(body))
}