| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package partial
- import (
- sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
- "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
- "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
- "strconv"
- )
- // _Image
- // @Title _Image
- // @Description 获取图片验证码
- // @Param w int 图片宽度
- // @Param h int 图片高度
- // @Param code string 保存的session编码
- // @Success 200 {object} Account
- // @Failure 403 :id is empty
- func Captcha_Image(c *entitys.CtrlContext) {
- width, _ := strconv.Atoi(c.Ctx.Query("w"))
- height, _ := strconv.Atoi(c.Ctx.Query("h"))
- length, _ := strconv.Atoi(c.Ctx.Query("l"))
- captchaId, image, err := utils.GenerateImageCaptcha(width, height, length)
- if err == nil {
- result := map[string]interface{}{
- "captcha_key": captchaId,
- "captcha_image": image.Bytes(),
- }
- c.Ctx.JSON(200, sysmodel.SysReturn{200, "", result})
- } else {
- c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
- }
- }
- // _Sms
- // @Title _Sms
- // @Description 获取短信验证码
- // @Param mobile string false "手机号码"
- // @Success 200 {object} Account
- // @Failure 403 :id is empty
- func Captcha_Sms(c *entitys.CtrlContext) {
- mobile := c.Ctx.Query("mobile")
- if mobile == "" {
- c.Ctx.JSON(500, sysmodel.SysReturn{500, "mobile is cannot empty", nil})
- return
- }
- data, err := utils.SendSmsCaptcha(mobile)
- if err == nil {
- c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(data)})
- } else {
- c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
- }
- }
- // _Check
- // @Title _Check
- // @Description 校验验证码
- // @Param type int false "验证类型 0:图片验证码 1:短信验证码"
- // @Param captcha string false "验证码"
- // @Param mobile string false "短信验证码的手机号码"
- // @Param key string false "图片验证码的key"
- // @Success 200 {object} Account
- // @Failure 403 :id is empty
- func Captcha_Check(c *entitys.CtrlContext) {
- check_type := c.Ctx.Query("type")
- captcha := c.Ctx.Query("captcha")
- if captcha == "" {
- c.Ctx.JSON(200, sysmodel.SysReturn{200, "验证码不能为空", nil})
- return
- }
- var check = false //校验结果
- switch check_type {
- case "0":
- captchaId := c.Ctx.Query("key")
- if captchaId == "" {
- c.Ctx.JSON(500, sysmodel.SysReturn{500, "验证码key不能为空", nil})
- return
- }
- check = utils.ImageCaptchaCheck(captcha, captchaId)
- case "1":
- mobile := c.Ctx.Query("mobile")
- if mobile == "" {
- c.Ctx.JSON(500, sysmodel.SysReturn{500, "手机号码不能为空", nil})
- return
- }
- check = utils.SmsCaptchaCheck(captcha, mobile)
- default:
- c.Ctx.JSON(500, sysmodel.SysReturn{500, "验证类型错误", nil})
- return
- }
- if check {
- c.Ctx.JSON(200, sysmodel.SysReturn{200, "验证成功", nil})
- } else {
- c.Ctx.JSON(500, sysmodel.SysReturn{500, "验证失败", nil})
- }
- }
- func __none_func_captcha__(params ... interface{}) bool {
- return true
- }
|