123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package captcha
- /**
- 1、滑动式
- 2、区域内拖拽滑动式
- 3、旋转式
- 4、中文文本、字母/数字混合 点选
- 5、浅色 中文文本、字母/数字混合 点选
- 6、图形点选
- **/
- import (
- "app.yhyue.com/moapp/jybase/captcha/phoneCache"
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
- "fmt"
- "net/http"
- "strings"
- )
- type (
- GetCaptcha struct {
- W http.ResponseWriter
- R *http.Request
- Sess *httpsession.Session
- Phone string
- }
- CaptRes struct {
- Code int `json:"code"`
- CaptchaKey interface{} `json:"captcha_key"`
- ImageBase64 interface{} `json:"image_base64"`
- TileBase64 interface{} `json:"tile_base64"`
- ThumbBase64 interface{} `json:"thumb_base64"`
- TileWidth interface{} `json:"tile_width"`
- TileHeight interface{} `json:"tile_height"`
- TileX interface{} `json:"tile_x"`
- TileY interface{} `json:"tile_y"`
- ThumbSize int `json:"thumb_size"`
- }
- )
- func InitCaptcha() {
- SlideCaptcha()
- ClickBasicCaptcha()
- ClickShapeCaptcha()
- RotateCaptcha()
- go phoneCache.RunTimedTask()
- }
- func (c *GetCaptcha) GetCaptchaData() (cd CaptRes, err error) {
- if strings.TrimSpace(c.Phone) == "" || !PhoneCheck(c.Phone) {
- err = fmt.Errorf("phone param is empty or incorrect")
- return
- }
- var times int // phoneCache.GetAccessCount(c.Phone)
- switch {
- case times < MiniTimes:
- return c.GetSlideCaptchaData()
- case times < MaxTimes:
- return c.GetRotateCaptchaData()
- default:
- return c.GetClickCaptchaData()
- }
- }
|