搜题网站需要一定的html知识,题目答案的来源可以是api接口,也可以是调用自己的数据库。
这里提供一个题库api接口(自己搭建的,服务器比较垃圾,大佬轻点用):
http://api.lyoo.xyz/xiaochengxu/chati.php?w=
w后面加问题就可以返回问题和答案
例如:http://api.lyoo.xyz/xiaochengxu/chati.php?w=中国特色社会主义
给一个搜题网站模版:
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>搜题网站</title>
</head>
<div class="out">
<form method="POST">
<div class="block">
<textarea class="input" id="currInput" placeholder="请在此处粘贴你要查询的题目(无需输入选项)" name="w"></textarea>
</div>
<div class="btn">
<button class="btn1" type="submit">搜索</button>
</div>
<span style="font-size: 18px">
<div class="block">
<div class="ansower">
<?php
$daan = file_get_contents("http://api.lyoo.xyz/xiaochengxu/chati.php?w=".$_POST['w'];
echo $daan;
?>
<span id=\'ansowerid\'></span>
</div>
</div>
</span>
</form>
</div>
<script type="text/javascript" src="canvas-nest.js"></script>
<canvas id="c_n1"></canvas>
</body>
<style>
.out {
margin-top: 5%;
}
.block {
display: flex;
justify-content: center;
}
.col {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.row {
display: flex;
flex-direction: row;
}
.spant {
font-size: 14px;
color: #303133;
}
.input {
display: block;
border: 2px solid blanchedalmond;
resize: none;
width: 78%;
padding: 20px;
color: inherit;
font-size: 1em;
line-height: inherit;
outline: 0;
}
.btn {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.btn1 {
display: flex;
justify-content: center;
background-color: #409EFF;
font-size: 2em;
width: 320px;
}
.ansower {
display: flex;
justify-content: flex-start;
margin-top: 20px;
border-bottom: 2px solid blanchedalmond;
resize: none;
width: 88%;
padding: 2px;
color: inherit;
font-size: 1em;
line-height: inherit;
outline: 0;
height: auto;
}
</style>
搜题公众号可以用微擎等微信第三方开发,其中的自定义接口回复。
自定义接口代码示例:
<?php
$message = $this->message;
$html=file_get_contents("http://api.lyoo.xyz/xiaochengxu/chati.php?w=".$this->message['content']);
return $this->respText($html);
?>
至于搜题接口如何做的。
目前我知道主要有两种主要方式,下次总结。