Merge branch 'master' of ssh://10.10.14.176:222/bigdata/dsMin
continuous-integration/drone/push Build is passing Details

# Conflicts:
#	dsSzxy/.idea/workspace.xml
#	dsSzxy/build/dsSzxy
#	dsSzxy/go.sum
master
kgdxpr 4 years ago
commit 4b6ee7e526

@ -0,0 +1,127 @@
package CaptchaController
import (
"dsSzxy/Utils/ConfigUtil"
"fmt"
"gitee.com/aesoper/cache"
"gitee.com/aesoper/cache/redis"
"gitee.com/aesoper/captchaStore"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
"image/color"
"net/http"
"time"
)
// Routers 模块的路由配置
func Routers(r *gin.RouterGroup) {
rr := r.Group("/captchaRelate")
rr.GET("/getCaptcha", getCaptcha)
rr.POST("/verifyCaptcha", verifyCaptcha)
}
// CaptchaResult 存储验证码的结构
type CaptchaResult struct {
Id string `json:"id"`
Base64Blob string `json:"base_64_blob"`
}
// GetOne 生成图形化验证码
func getCaptcha(c *gin.Context) {
id, b64s := CaptMake()
captchaResult := CaptchaResult{
Id: id,
Base64Blob: b64s,
}
c.JSON(http.StatusOK, gin.H{"success": true, "captcha": captchaResult})
return
}
// Verify 验证captcha是否正确
func verifyCaptcha(c *gin.Context) {
id := c.PostForm("id")
capt := c.PostForm("capt")
if id == "" || capt == "" {
c.JSON(http.StatusOK, gin.H{"success": false, "msg": "参数错误!"})
}
if CaptVerify(id, capt) == true {
c.JSON(http.StatusOK, gin.H{"success": true})
} else {
c.JSON(http.StatusOK, gin.H{"success": false})
}
return
}
var store *captchaStore.CustomCaptchaStore
// CaptMake 生成验证码
func CaptMake() (string, string) {
// 生成默认数字
//driver := &base64Captcha.DriverDigit{
// Height: 100,
// Width: 200,
// Length: 4,
// MaxSkew: 1,
// DotCount: 2,
//}
//https://captcha.mojotv.cn/
//四则运算
//driver := &base64Captcha.DriverMath{
// Height: 60,
// Width: 240,
// NoiseCount: 0,
// BgColor: &color.RGBA{
// R: 52,
// G: 56,
// B: 98,
// A: 58,
// },
// Fonts: []string{"wqy-microhei.ttc"},
//}
//driver.ConvertFonts()
//中文
driver := &base64Captcha.DriverChinese{
Height: 50,
Width: 300,
NoiseCount: 0,
ShowLineOptions: 1,
Length: 2,
BgColor: &color.RGBA{
R: 52,
G: 56,
B: 98,
A: 58,
},
Source: "东师理想,大数据,超融合,智慧校园,数字校园,黄海,吴缤,超人气,抗疫情,努力,加油,长春",
Fonts: []string{"wqy-microhei.ttc"},
}
driver.ConvertFonts()
// 生成base64图片
c, err := cache.New(cache.Cfg{
Driver: "redis",
Redis: redis.Options{
Addr: ConfigUtil.RedisIp + ":" + ConfigUtil.RedisPort,
},
})
if err != nil {
fmt.Println("初始化Redis服务器失败:", err)
}
store = captchaStore.NewCustomCaptchaStore(c, time.Minute*5, false)
captcha := base64Captcha.NewCaptcha(driver, store)
// 生成验证码base64字符串
id, b64s, err := captcha.Generate()
if err != nil {
fmt.Println("Register GetCaptchaPhoto get base64Captcha has err:", err)
}
return id, b64s
}
// CaptVerify 验证captcha是否正确
func CaptVerify(id string, capt string) bool {
fmt.Println("id:" + id)
fmt.Println("capt:" + capt)
return store.Verify(id, capt, false)
}

@ -0,0 +1,42 @@
package CaptchaController
import (
"context"
"dsSzxy/Utils/RedisUtil"
"fmt"
"time"
)
var ctx = context.Background()
const CAPTCHA = "captcha:"
type RedisStore struct {
}
// Set set a capt
func (r RedisStore) Set(id string, value string) {
key := CAPTCHA + id
RedisUtil.SET(key, value, time.Minute*2)
}
// Get get a capt
func (r RedisStore) Get(id string, clear bool) string {
key := CAPTCHA + id
val, err := RedisUtil.GET(key)
if err != nil {
fmt.Println(err)
return ""
}
if clear {
RedisUtil.DEL(key)
}
return val
}
// Verify verify a capt
func (r RedisStore) Verify(id, answer string, clear bool) bool {
v := RedisStore{}.Get(id, clear)
return v == answer
}

@ -21,10 +21,7 @@ import (
//模块的路由配置
func Routers(r *gin.RouterGroup) {
rr := r.Group("/imRelate")
rr.POST("/fileUpload", fileUpload)
return
}
func fileUpload(c *gin.Context) {

@ -26,8 +26,6 @@ func Routers(r *gin.RouterGroup) {
rr.GET("/generatePreviewUrl", generatePreviewUrl)
rr.GET("/saveFileInfo", saveFileInfo)
rr.GET("/getFileDownLoadUrl", getFileDownLoadUrl)
return
}
/**
@ -55,9 +53,7 @@ func getFileDownLoadUrl(c *gin.Context) {
storageBucket := resMap["storage_bucket"]
infix := "?response-content-disposition=attachment%3BfileName%2A%3DUTF-8%27%27"
downloadUrl := ConfigUtil.MinioDownloadPrefix + storageBucket + "/" + storageKey + infix + url.QueryEscape(url.QueryEscape(originName))
c.JSON(http.StatusOK, gin.H{"success": true, "download_url": downloadUrl})
}
/**
@ -125,7 +121,6 @@ func saveFileInfo(c *gin.Context) {
RedisUtil.DEL("file_" + id)
c.JSON(http.StatusOK, gin.H{"success": true, "info": "成功!"})
}
/**

@ -5,4 +5,6 @@
| (_| \__ \____) / / > <| |_| |
\__,_|___/_____/___|/_/\_\\__, |
__/ |
|___/
|___/
Created By HuangHai 2021-08-05
http://patorjk.com/software/taag/#p=display&f=Big&t=dsSzxy

@ -1,6 +1,7 @@
package Router
import (
"dsSzxy/Business/CaptchaRelate/CaptchaController"
"dsSzxy/Business/ImRelate/ImRelateController"
"dsSzxy/Business/MinIORelate/MinIORelateController"
"github.com/gin-gonic/gin"
@ -14,5 +15,6 @@ func GinRouter(r *gin.Engine) {
MinIORelateController.Routers(rr)
//IM
ImRelateController.Routers(rr)
//Captcha
CaptchaController.Routers(rr)
}

@ -32,9 +32,8 @@ func main() {
SftpUtil.UploadDirectory(sftpClient, buildPath, ConfigUtil.DistributeRemotePath)
//执行SSH命令行,授权
cli.Run("chmod +x /usr/local/dsMin/dsSzxy/dsSzxy")
cli.Run("chmod +x /usr/local/dsMin/dsSzxy/start.sh")
cli.Run("chmod +x /usr/local/dsMin/dsSzxy/debug.sh")
cli.Run("chmod +x /usr/local/dsMin/dsSzxy/stop.sh")
cli.Run("chmod +x /usr/local/dsMin/dsSzxy/*.sh")
cli.Run("cd /usr/local/dsMin/dsSzxy && dos2unix *.sh")
//启动
cli.Run("cd /usr/local/dsMin/dsSzxy && ./start.sh")
log.Println("通用工具服务上传并启动成功!")

@ -0,0 +1,84 @@
package FileUtil
import (
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
)
/**
2019-12-31
*/
func ReadFileContent(filepath string) string {
file, err := os.Open(filepath)
if err != nil {
log.Print("文件打开失败:", err)
}
defer file.Close()
buf := make([]byte, 12) // 存放文件内容的缓存,相当于中转站
data := make([]byte, 0) // 用来存放文件内容buf读取的内容都会写到data里面去
for {
//无限循环,不断读取
n, err := file.Read(buf)
// 什么时候文件读完呢如果文件读完的话那么err不为nil而是io.EOF
// 所以我们可以进行判断
if err != nil {
//如果err != nil说明出错了但如果还等于io.EOF的话说明读完了因为文件读完err也不为nil。直接break
if err == io.EOF {
break
} else {
//如果错误不是io.EOF的话说明就真的在读取中出现了错误直接panic出来
panic(err)
}
}
//此时文件内容写到buf里面去了写了多少个呢写了n个那么我们再写到data里面去
data = append(data, buf[:n]...)
}
return string(data)
}
/**
2020-01-20
*/
func GetFileSize(filename string) int64 {
var result int64
filepath.Walk(filename, func(path string, f os.FileInfo, err error) error {
result = f.Size()
return nil
})
return result
}
/**
2020-05-16
*/
func WriteFileContent(filename string, content string) {
var d1 = []byte(content)
ioutil.WriteFile(filename, d1, 0666) //写入文件(字节数组)
}
/**
2020-05-20
*/
func PathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}

Binary file not shown.

@ -5,4 +5,6 @@
| (_| \__ \____) / / > <| |_| |
\__,_|___/_____/___|/_/\_\\__, |
__/ |
|___/
|___/
Created By HuangHai 2021-08-05
http://patorjk.com/software/taag/#p=display&f=Big&t=dsSzxy

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,7 @@
go get -u github.com/jteeuwen/go-bindata/...
go-bindata fonts
sed -i "s/package main/package base64Captcha/g" bindata.go
https://github.com/jteeuwen/go-bindata

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<img id="capt" src=""/><br/>
<input id="captvalue" placeholder="请输入验证码"/><br/>
<input type="button" name="save" value="提交" onclick="submit()"/>
<script>
var curCaptId = "";
//得到图形验证码和id
$.ajax({
type: "GET",
url: "/dsSzxy/captchaRelate/getCaptcha",
data: {},
dataType: "JSON",
success: function (result) {
curCaptId = result.captcha.id;
document.getElementById("capt").src = result.captcha.base_64_blob;
}
});
//提交验证码和id
function submit() {
var capt = document.getElementById("captvalue").value;
var postdata = {
"id": curCaptId,
"capt": capt
};
$.ajax({
type: "POST",
url: "/dsSzxy/captchaRelate/verifyCaptcha",
data: postdata,
dataType: "JSON",
success: function (result) {
console.log(result.success);
if (result.success) {
alert("验证成功");
} else {
alert("验证错误!" );
}
}
});
}
</script>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,7 @@
go get -u github.com/jteeuwen/go-bindata/...
go-bindata fonts
sed -i "s/package main/package base64Captcha/g" bindata.go
https://github.com/jteeuwen/go-bindata

Binary file not shown.

@ -3,6 +3,8 @@ module dsSzxy
go 1.16
require (
gitee.com/aesoper/cache v0.0.0-20210525090400-5745f2c3bd94
gitee.com/aesoper/captchaStore v0.0.0-20200527033950-8d788c0d271e
github.com/Chronokeeper/anyxml v0.0.0-20160530174208-54457d8e98c6 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet v2.1.2+incompatible // indirect
@ -10,22 +12,24 @@ require (
github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee // indirect
github.com/agrison/mxj v0.0.0-20160310142625-1269f8afb3b4 // indirect
github.com/bndr/gotabulate v1.1.2 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/disintegration/imaging v1.6.2
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gin-gonic/gin v1.7.2 // indirect
github.com/go-redis/redis v6.15.9+incompatible // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/minio/minio-go/v6 v6.0.57 // indirect
github.com/pkg/sftp v1.13.1 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/gin-gonic/gin v1.7.2
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.0
github.com/mattn/go-sqlite3 v1.14.8 // indirect
github.com/minio/minio-go/v6 v6.0.57
github.com/mojocn/base64Captcha v1.3.1
github.com/pkg/sftp v1.13.1
github.com/satori/go.uuid v1.2.0
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be // indirect
github.com/xormplus/xorm v0.0.0-20210512135344-8123d584d5f5 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
github.com/xormplus/xorm v0.0.0-20210512135344-8123d584d5f5
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/ini.v1 v1.62.0
)

@ -3,21 +3,34 @@ package main
import (
"dsSzxy/Router"
"dsSzxy/Utils"
"dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/FileUtil"
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
// 发布模式
//gin.SetMode(gin.ReleaseMode)
// 显示Logo
configIniFile := "./Config/logo.txt"
if !CommonUtil.Exists(configIniFile) {
configIniFile = "/usr/local/dsMin/dsSzxy/Config/logo.txt"
}
var logo = FileUtil.ReadFileContent(configIniFile)
fmt.Print(logo)
// 开发模式
gin.SetMode(gin.DebugMode)
// 开启gin服务器
r := gin.Default()
//设置静态资源
r.Static("/dsSzxy/static", "./static")
// 使用跨域中间件
r.Use(Utils.Cors())
//主路由
Router.GinRouter(r)
// 监听并在 0.0.0.0:8002 上启动服务
// 监听并在 0.0.0.0:8006 上启动服务
r.Run(":" + ConfigUtil.ServerPort)
}

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<img id="capt" src=""/><br/>
<input id="captvalue" placeholder="请输入验证码"/><br/>
<input type="button" name="save" value="提交" onclick="submit()"/>
<script>
var curCaptId = "";
//得到图形验证码和id
$.ajax({
type: "GET",
url: "/dsSzxy/captchaRelate/getCaptcha",
data: {},
dataType: "JSON",
success: function (result) {
curCaptId = result.captcha.id;
document.getElementById("capt").src = result.captcha.base_64_blob;
}
});
//提交验证码和id
function submit() {
var capt = document.getElementById("captvalue").value;
var postdata = {
"id": curCaptId,
"capt": capt
};
$.ajax({
type: "POST",
url: "/dsSzxy/captchaRelate/verifyCaptcha",
data: postdata,
dataType: "JSON",
success: function (result) {
console.log(result.success);
if (result.success) {
alert("验证成功");
} else {
alert("验证错误!" );
}
}
});
}
</script>
</body>
</html>

@ -9,7 +9,9 @@ go build -gcflags "all=-N -l" -o ./build/dsSzxy main.go
:: 拷贝资源文件
xcopy .\Shell\* .\build\ /y /e /i /q
xcopy .\static\* .\build\static /y /e /i /q
xcopy .\Config\* .\build\Config /y /e /i /q
xcopy .\fonts\* .\build\fonts /y /e /i /q
:: 上传文件
.\WinBuild\Distribute.exe

Loading…
Cancel
Save