代码拉取完成,页面将自动刷新
同步操作将从 ShirDon-廖显东/go验证码合集包 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//++++++++++++++++++++++++++++++++++++++++
//Fighting for great,share generate value!
//Build the best soft by golang,let's go!
//++++++++++++++++++++++++++++++++++++++++
//Author:ShirDon <http://www.shirdon.com>
//Email:[email protected]; [email protected]
//++++++++++++++++++++++++++++++++++++++++
package captchas_with_go
import (
"os"
"testing"
"time"
)
func TestCaptcha(t *testing.T) {
captcha, err := getCaptcha()
if nil != err {
t.Fatalf("getCaptcha Error:%s", err.Error())
}
key, err := captcha.GetKey(4)
if nil != err {
t.Fatalf("GetKey Error:%s", err.Error())
}
captcha.GetImage(key)
captcha.Verify(key, "test")
}
func BenchmarkCaptcha(t *testing.B) {
captcha, err := getCaptcha()
if nil != err {
t.Fatalf("getCaptcha Error:%s", err.Error())
}
for i := 0; i < t.N; i++ {
s, _ := captcha.GetKey(4)
captcha.GetImage(s)
captcha.Verify(s, "ssss")
}
}
func BenchmarkCaptchaInternalAPI(t *testing.B) {
captcha, err := getCaptcha()
if nil != err {
t.Fatalf("getCaptcha Error:%s", err.Error())
}
for i := 0; i < t.N; i++ {
s, _ := captcha.GetKey(4)
captcha.Verify(s, "ssss")
}
}
func BenchmarkCaptchaDrawImage(t *testing.B) {
captcha, err := getCaptcha()
if nil != err {
t.Fatalf("getCaptcha Error:%s", err.Error())
}
for i := 0; i < t.N; i++ {
s, _ := captcha.GetKey(4)
captcha.GetImage(s)
}
}
func getCaptcha() (*Captcha, error) {
wordDict, captchaConfig, imageConfig, filterConfig, storeConfig := loadConfig()
wordmgr, err := CreateWordManagerFromDataFile(wordDict)
captcha, err := CreateCaptcha(wordmgr, captchaConfig, imageConfig, filterConfig, storeConfig)
return captcha, err
}
func loadConfig() (string, *CaptchaConfig, *ImageConfig, *FilterConfig, *StoreConfig) {
pwd, _ := os.Getwd()
data_path := pwd + "/data/"
wordDict := data_path + "en_phrases"
captchaConfig := new(CaptchaConfig)
captchaConfig.LifeTime = 10 * time.Second
imageConfig := new(ImageConfig)
imageConfig.FontFiles = []string{data_path + "zpix.ttf"}
imageConfig.FontSize = 26
imageConfig.Height = 40
imageConfig.Width = 120
filterConfig := new(FilterConfig)
filterConfig.Init()
filterConfig.Filters = []string{"ImageFilterNoiseLine", "ImageFilterNoisePoint", "ImageFilterStrike"}
var filterConfigGroup *FilterConfigGroup
filterConfigGroup = new(FilterConfigGroup)
filterConfigGroup.Init()
filterConfigGroup.SetItem("Num", "5")
filterConfig.SetGroup("ImageFilterNoiseLine", filterConfigGroup)
filterConfigGroup = new(FilterConfigGroup)
filterConfigGroup.Init()
filterConfigGroup.SetItem("Num", "10")
filterConfig.SetGroup("ImageFilterNoisePoint", filterConfigGroup)
filterConfigGroup = new(FilterConfigGroup)
filterConfigGroup.Init()
filterConfigGroup.SetItem("Num", "3")
filterConfig.SetGroup("ImageFilterStrike", filterConfigGroup)
storeConfig := new(StoreConfig)
storeConfig.Engine = STORE_ENGINE_BUILDIN
storeConfig.GcDivisor = 100
storeConfig.GcProbability = 1
return wordDict, captchaConfig, imageConfig, filterConfig, storeConfig
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。