Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参数传递 #81

Closed
zhongxiaohang opened this issue Apr 3, 2021 · 1 comment
Closed

参数传递 #81

zhongxiaohang opened this issue Apr 3, 2021 · 1 comment

Comments

@zhongxiaohang
Copy link

您给的实例运行后没有问题,但是我想使用curl命令行的方式向生成或者认证函数传递参数,请问我应该怎么传递

@mojocn
Copy link
Owner

mojocn commented Apr 6, 2021

我这里有一个算术公式example代码,看看是否是你需要的

import (
	"github.com/mojocn/base64Captcha"
	"image/color"
	"time"
)

type Captcha struct {
	Driver base64Captcha.DriverMath
	Store  base64Captcha.Store
}

func NewCaptcha() *Captcha {
	d := base64Captcha.DriverMath{
		Height:          36,
		Width:           240,
		NoiseCount:      0,
		ShowLineOptions: 0, //base64Captcha.OptionShowSlimeLine,//base64Captcha.OptionShowHollowLine | base64Captcha.OptionShowSineLine | base64Captcha.OptionShowSlimeLine,
		BgColor: &color.RGBA{
			R: 0,
			G: 0,
			B: 0,
			A: 0,
		}, //transparent background color
		Fonts: []string{"wqy-microhei.ttc"}, //randomly use all fonts
	}
	d.ConvertFonts() //use all fonts
	return &Captcha{
		Driver: d,
		Store:  base64Captcha.NewMemoryStore(1<<20, time.Second*300),
	}
}

//Generate generates a random id, base64 image string or an error if any
func (c *Captcha) Generate() (id, b64s string, err error) {
	id, content, answer := c.Driver.GenerateIdQuestionAnswer()
	item, err := c.Driver.DrawCaptcha(content)
	if err != nil {
		return "", "", err
	}
	c.Store.Set(id, answer)
	b64s = item.EncodeB64string()
	return
}

//Verify by a given id key and remove the captcha value in store,
//return boolean value.
//if you has multiple captcha instances which share a same store.
//You may want to call `store.Verify` method instead.
func (c *Captcha) Verify(id, answer string, clear bool) (match bool) {
	match = c.Store.Get(id, clear) == answer
	return
}

@mojocn mojocn closed this as completed Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants