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" "fmt" ) // _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") fmt.Println("--------------> get mobile", mobile) if mobile == "" { c.Ctx.JSON(500, sysmodel.SysReturn{500, "mobile is cannot empty", nil}) return } fmt.Println("--------------> utils.SendSmsCaptcha", mobile) 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 }