18 changed files with 461 additions and 234 deletions
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 504 KiB |
@ -0,0 +1,49 @@ |
|||||
|
package utils |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"github.com/beego/beego/v2/server/web" |
||||
|
"github.com/go-redis/redis" |
||||
|
) |
||||
|
|
||||
|
const ( |
||||
|
REDIS_NETWORK = "tcp" |
||||
|
REDIS_DB = 7 |
||||
|
) |
||||
|
|
||||
|
type RedisClient struct { |
||||
|
} |
||||
|
|
||||
|
func (r RedisClient) GetClient() *redis.Client { |
||||
|
REDIS_HOST, _ := web.AppConfig.String("redisHost") |
||||
|
REDIS_PORT, _ := web.AppConfig.String("redisPort") |
||||
|
REDIS_PASSWORD, _ := web.AppConfig.String("redisPwd") |
||||
|
options := redis.Options{ |
||||
|
Network: REDIS_NETWORK, |
||||
|
Addr: fmt.Sprintf("%s:%s", REDIS_HOST, REDIS_PORT), |
||||
|
Dialer: nil, |
||||
|
OnConnect: nil, |
||||
|
Password: REDIS_PASSWORD, |
||||
|
DB: REDIS_DB, |
||||
|
MaxRetries: 0, |
||||
|
MinRetryBackoff: 0, |
||||
|
MaxRetryBackoff: 0, |
||||
|
DialTimeout: 0, |
||||
|
ReadTimeout: 0, |
||||
|
WriteTimeout: 0, |
||||
|
PoolSize: 0, |
||||
|
MinIdleConns: 0, |
||||
|
MaxConnAge: 0, |
||||
|
PoolTimeout: 0, |
||||
|
IdleTimeout: 0, |
||||
|
IdleCheckFrequency: 0, |
||||
|
TLSConfig: nil, |
||||
|
} |
||||
|
// 新建一个client
|
||||
|
clientRedis := redis.NewClient(&options) |
||||
|
return clientRedis |
||||
|
} |
||||
|
|
||||
|
func (r RedisClient) CloseClient(client *redis.Client) { |
||||
|
defer client.Close() |
||||
|
} |
@ -0,0 +1,66 @@ |
|||||
|
package utils |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"github.com/mojocn/base64Captcha" |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
const CAPTCHA = "captcha:" |
||||
|
|
||||
|
type RedisStore struct { |
||||
|
base64Captcha.Store |
||||
|
} |
||||
|
|
||||
|
var redisObj = new(RedisClient) |
||||
|
|
||||
|
//set a capt
|
||||
|
func (r RedisStore) Set(id string, value string) error { |
||||
|
key := CAPTCHA + id |
||||
|
client := redisObj.GetClient() |
||||
|
_, err := client.Set(key, value, time.Minute*2).Result() |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
redisObj.CloseClient(client) |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
//get a capt
|
||||
|
func (r RedisStore) Get(id string, clear bool) string { |
||||
|
key := CAPTCHA + id |
||||
|
client := redisObj.GetClient() |
||||
|
val, err := client.Get(key).Result() |
||||
|
if err != nil { |
||||
|
fmt.Println(err) |
||||
|
return "" |
||||
|
} |
||||
|
if clear { |
||||
|
client.Del(key) |
||||
|
} |
||||
|
redisObj.CloseClient(client) |
||||
|
return val |
||||
|
} |
||||
|
|
||||
|
//verify a capt
|
||||
|
func (r RedisStore) Verify(id, answer string, clear bool) bool { |
||||
|
v := RedisStore{}.Get(id, clear) |
||||
|
fmt.Println("key:" + id + ";value:" + v + ";answer:" + answer) |
||||
|
return v == answer |
||||
|
} |
||||
|
|
||||
|
//get a capt
|
||||
|
func (r RedisStore) Has(id string) int { |
||||
|
key := CAPTCHA + id |
||||
|
client := redisObj.GetClient() |
||||
|
val, err := client.Get(key).Result() |
||||
|
redisObj.CloseClient(client) |
||||
|
if err != nil { |
||||
|
fmt.Println(err) |
||||
|
return 0 |
||||
|
} |
||||
|
if val == "" { |
||||
|
return 0 |
||||
|
} |
||||
|
return 1 |
||||
|
} |
@ -1,64 +0,0 @@ |
|||||
{{template "header" .}} |
|
||||
<meta name="keywords" content="福利,源码下载,程序部署步骤,码农随笔,个人随笔,博客,个人博客,个人笔记,技术博客,免费云笔记,云笔记,随笔,IT博客,谷歌地图,码农笔录,aiprose"> |
|
||||
<title>福利 - 码农随笔</title> |
|
||||
</head> |
|
||||
<body> |
|
||||
{{template "nav" .}} |
|
||||
<div class="us-root"> |
|
||||
<div style="width: 450px;"> |
|
||||
<p>·项目源码: <a href="https://gitea.aiprose.com/nelson/beeblog" target="_blank">点击查看</a></p> |
|
||||
<p>·项目框架: </p> |
|
||||
<div style="margin-left: 15px"> |
|
||||
<p><span>golang@1.11</span></p> |
|
||||
<p><span>beego@1.7.2 <a href="https://beego.me/" target="_blank">beego官网</a></span></p> |
|
||||
<p><span>vue@2.6.10</span></p> |
|
||||
<p>iviewui@4.20: <a href="https://iviewui.com/" target="_blank">iviewui官网</a></p> |
|
||||
<p>富文本编辑器: <a href="http://www.wangeditor.com/" target="_blank">wangeditor官网</a></p> |
|
||||
<p>数据库: mysql(5.5.60-MariaDB)</p> |
|
||||
</div> |
|
||||
<p>·项目搭建步骤: </p> |
|
||||
<div style="margin-left: 15px"> |
|
||||
<p>1.安装配置golang 最新版本 (开发最好安装一下bee)</p> |
|
||||
<p>2.go get github.com/astaxie/beego</p> |
|
||||
<p>3.go get github.com/go-sql-driver/mysql</p> |
|
||||
<p>4.windows环境需要安装gcc <a href="http://tdm-gcc.tdragon.net/download">gcc下载地址</a></p> |
|
||||
</div> |
|
||||
</div> |
|
||||
<div style="flex: 1"> |
|
||||
<img src="/static/img/alipay.png" alt="" width="320" height="361"> |
|
||||
<img src="/static/img/weixin.png" alt="" width="320" height="361"> |
|
||||
<img src="/static/img/redalipay.png" alt="" height="360"> |
|
||||
</div> |
|
||||
</div> |
|
||||
<div class="footer-container"> |
|
||||
{{template "footer"}} |
|
||||
</div> |
|
||||
</body> |
|
||||
<script> |
|
||||
$(function () { |
|
||||
/*百度收录*/ |
|
||||
var bp = document.createElement('script'); |
|
||||
var curProtocol = window.location.protocol.split(':')[0]; |
|
||||
if (curProtocol === 'https') { |
|
||||
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; |
|
||||
} |
|
||||
else { |
|
||||
bp.src = 'http://push.zhanzhang.baidu.com/push.js'; |
|
||||
} |
|
||||
var s = document.getElementsByTagName("script")[0]; |
|
||||
s.parentNode.insertBefore(bp, s); |
|
||||
|
|
||||
/*360收录*/ |
|
||||
var qihuo = document.createElement('script'); |
|
||||
if (curProtocol === 'https') { |
|
||||
qihuo.src = 'https://jspassport.ssl.qhimg.com/11.0.1.js?d33b14200fa89b7ecd3780341cd234c'; |
|
||||
} |
|
||||
else { |
|
||||
qihuo.src = 'http://js.passport.qihucdn.com/11.0.1.js?d33b14200fa89b7ecd3780341cd234c4'; |
|
||||
} |
|
||||
qihuo.id = "sozz" |
|
||||
var s = document.getElementsByTagName("script")[1]; |
|
||||
s.parentNode.insertBefore(qihuo, s); |
|
||||
}) |
|
||||
</script> |
|
||||
</html> |
|
Loading…
Reference in new issue