Skip to content

Commit 0bbde66

Browse files
committed
新增了接口示例-验证码接口
1 parent 00a6148 commit 0bbde66

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

index.html

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Date: 2019-12-31 19:21:38
33
* @Author: MemoryShadow
44
* @LastEditors: MemoryShadow
5-
* @LastEditTime: 2020-07-01 16:02:01
5+
* @LastEditTime: 2020-07-01 16:39:14
66
* @Effect: Do not edit
77
-->
88
<!DOCTYPE html>
@@ -53,6 +53,37 @@
5353
XmlHttp.open("GET", "https://memoryshadow.freetzi.com/Template/Public/ToolAPI/?Mode=Ajax&Function=Translate&Query=" + Query, true);
5454
XmlHttp.send();
5555
}
56+
function Get_CaptchaData(Id) {
57+
var XmlHttp = GetXmlHttp();
58+
XmlHttp.onreadystatechange = function () {
59+
// 当响应达成,并且成功的时候,就修改数据
60+
if (XmlHttp.readyState == 4 && XmlHttp.status == 200) {
61+
Data = XmlHttp.responseText;
62+
document.getElementById(Id).Token = JSON.parse(XmlHttp.responseText).Token;
63+
document.getElementById(Id).src = "data:image/png;base64," + JSON.parse(XmlHttp.responseText).CaptchaImgValue;
64+
}
65+
}
66+
XmlHttp.open("GET", "https://memoryshadow.freetzi.com/Template/Public/ToolAPI/?Mode=Ajax&Function=Captcha&OperateMode=GetData&DataType=Json", true);
67+
XmlHttp.send();
68+
}
69+
70+
function Post_CaptchaData(Id, InputValue) {
71+
var XmlHttp = GetXmlHttp();
72+
XmlHttp.onreadystatechange = function () {
73+
// 当响应达成,并且成功的时候,就修改数据
74+
if (XmlHttp.readyState == 4 && XmlHttp.status == 200) {
75+
Data = XmlHttp.responseText;
76+
document.getElementById('Result').innerHTML = (XmlHttp.responseText == "False") ? "验证失败,验证码无效或发生错误" : "验证成功,验证码有效";
77+
// 并且在响应后刷新验证码
78+
Get_CaptchaData('CaptchaImg');
79+
}
80+
}
81+
XmlHttp.open("POST", "https://memoryshadow.freetzi.com/Template/Public/ToolAPI/?Mode=Ajax&Function=Captcha&OperateMode=SubmitData&SubmitType=ConfirmCaptcha", true);
82+
XmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
83+
XmlHttp.send("Token=" + document.getElementById(Id).Token + "&InputValue=" + InputValue);
84+
document.getElementById(Id).placeholder = InputValue;
85+
document.getElementById(Id).value = "";
86+
}
5687
function GetXmlHttp() {
5788
var XmlHttp;
5889
if (window.XMLHttpRequest) {
@@ -68,14 +99,14 @@
6899
CaiHongPi('CaiHongPi');
69100
GetErrorMsg(ErrorCode.value);
70101
Translate(TranslateSource.value);
102+
Get_CaptchaData('CaptchaImg');
71103
}
72104
</script>
73105
</head>
74106

75107
<body onload="Init()">
76-
<a href="https://www.baidu.com">打开百度</a>
77108
<a href="https://github.com/MemoryShadow/MemoryShadow.github.io">打开项目页面</a>
78-
<a href="https://MemoryShadow.freetzi.com">打开支柱官网</a>
109+
<a href="https://MemoryShadow.freetzi.com">打开支持官网</a>
79110
<br />
80111
<hr width="100%" size="1" />
81112
<h3>彩虹屁接口调用示例(感谢<a href="https://shadiao.app/">沙雕APP</a>)<button onclick="CaiHongPi('CaiHongPi');">
@@ -102,6 +133,14 @@ <h3>翻译接口(Google 翻译)</h3>
102133
返回具体内容:
103134
<span id="TranslateResultSource"></span><br />
104135
<hr width="100%" size="1" />
136+
<h3>验证码功能示例</h3>
137+
<img height="40px" width="120px" id="CaptchaImg" onclick="Get_CaptchaData('CaptchaImg')" />
138+
<br />
139+
<input type="text" value=""
140+
onblur="this.placeholder = this.value;this.value = '';Post_CaptchaData('CaptchaImg', this.placeholder);" />
141+
<br />
142+
<span id="Result"></span>
143+
<hr width="100%" size="1" />
105144
</body>
106145

107146
</html>

0 commit comments

Comments
 (0)