官方教程:传送门
网易云盾验证码:
captchaId 需要自己申请,只是玩玩儿的话可以从网易云盾的产品分析出Id
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main(){
engine := gin.Default()
engine.LoadHTMLGlob("templates/*")
engine.GET("/yundun", func(context *gin.Context) {
context.HTML(http.StatusOK, "index.html", gin.H{})
})
engine.Run(":8082")
}
index.html代码
<!DOCTYPE html>
<html lang="en">
<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>
<body>
<div style="margin-top: 300px" id="captcha"></div> <!-- 验证码容器元素 -->
<script src="http://cstaticdun.126.net/load.min.js?t=201903281201"></script>
<!-- 地址中的t参数强烈建议设置为分钟级别时间戳,避免该文件被浏览器长时间缓存 -->
<script>
initNECaptcha({
captchaType: 3, // 文字点选 默认是滑块 具体还有那些可以自己去尝试一下
captchaId: 'a6fe40ace298333b4916c840aa237398', //网易邮箱的Id
element: '#captcha',
mode: 'float',
width: '320px'
}, function onload (instance) {
// 初始化成功后,用户输入对应用户名和密码,以及完成验证后,直接点击登录按钮即可
}, function onerror (err) {
// 验证码初始化失败处理逻辑,例如:提示用户点击按钮重新初始化
})
</script>
</body>
</html>
界面效果:

去掉js中的captchaType:

本文介绍如何在Web应用中集成网易云盾验证码服务,包括Go语言后端配置及前端页面实现。通过实例演示了如何申请验证码ID,并展示了完整的代码实现。

814

被折叠的 条评论
为什么被折叠?



