|
@@ -1,14 +1,10 @@
|
|
|
package partial
|
|
package partial
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
|
|
|
|
|
- //sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
|
|
|
|
|
- //sysutils "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
|
|
|
|
|
- //"git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
|
|
|
|
|
sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
|
|
sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
|
|
|
- //__import_packages__
|
|
|
|
|
- "github.com/dchest/captcha"
|
|
|
|
|
- "bytes"
|
|
|
|
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
|
|
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
|
|
|
|
|
+ "strconv"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const captcha_session = "image_captcha"
|
|
const captcha_session = "image_captcha"
|
|
@@ -16,21 +12,28 @@ const captcha_session = "image_captcha"
|
|
|
// _Image
|
|
// _Image
|
|
|
// @Title _Image
|
|
// @Title _Image
|
|
|
// @Description 获取图片验证码
|
|
// @Description 获取图片验证码
|
|
|
|
|
+// @Param w int 图片宽度
|
|
|
|
|
+// @Param h int 图片高度
|
|
|
|
|
+// @Param code string 保存的session编码
|
|
|
// @Success 200 {object} Account
|
|
// @Success 200 {object} Account
|
|
|
// @Failure 403 :id is empty
|
|
// @Failure 403 :id is empty
|
|
|
func Captcha_Image(c *entitys.CtrlContext) {
|
|
func Captcha_Image(c *entitys.CtrlContext) {
|
|
|
- var content bytes.Buffer
|
|
|
|
|
-
|
|
|
|
|
- captchaId := captcha.New()
|
|
|
|
|
|
|
+ width, _ := strconv.Atoi(c.Ctx.Query("w"))
|
|
|
|
|
+ height, _ := strconv.Atoi(c.Ctx.Query("h"))
|
|
|
|
|
+ length, _ := strconv.Atoi(c.Ctx.Query("l"))
|
|
|
|
|
+ captchaKey := captcha_session + c.Ctx.Query("code")
|
|
|
|
|
+ captchaId, image, err := utils.GenerateImageCaptcha(width, height, length)
|
|
|
|
|
|
|
|
- c.Ctx.Set(captcha_session, captchaId)
|
|
|
|
|
-
|
|
|
|
|
- err := captcha.WriteImage(&content, captchaId, 240, 80)
|
|
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
|
|
+ utils.SetSession(c.Ctx, captchaKey, captchaId)
|
|
|
|
|
+ c.Ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
|
+ c.Ctx.Header("Pragma", "no-cache")
|
|
|
|
|
+ c.Ctx.Header("Expires", "0")
|
|
|
c.Ctx.Header("Content-Type", "image/png")
|
|
c.Ctx.Header("Content-Type", "image/png")
|
|
|
- c.Ctx.Writer.Write(content.Bytes())
|
|
|
|
|
|
|
+ c.Ctx.Writer.Write(image.Bytes())
|
|
|
c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
|
|
c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ utils.SetSession(c.Ctx, captchaKey, "")
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -38,17 +41,67 @@ func Captcha_Image(c *entitys.CtrlContext) {
|
|
|
// _Sms
|
|
// _Sms
|
|
|
// @Title _Sms
|
|
// @Title _Sms
|
|
|
// @Description 获取短信验证码
|
|
// @Description 获取短信验证码
|
|
|
-// @Param phone string false "手机号码"
|
|
|
|
|
|
|
+// @Param mobile string false "手机号码"
|
|
|
// @Success 200 {object} Account
|
|
// @Success 200 {object} Account
|
|
|
// @Failure 403 :id is empty
|
|
// @Failure 403 :id is empty
|
|
|
func Captcha_Sms(c *entitys.CtrlContext) {
|
|
func Captcha_Sms(c *entitys.CtrlContext) {
|
|
|
- phone := c.Ctx.Query("phone")
|
|
|
|
|
|
|
+ mobile := c.Ctx.Query("mobile")
|
|
|
|
|
|
|
|
- ret := __none_func_captcha__(phone)
|
|
|
|
|
- if ret {
|
|
|
|
|
- c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
|
|
|
|
|
|
|
+ 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 {
|
|
} else {
|
|
|
- c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
|
|
|
|
|
|
|
+ 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 "手机号码 短信验证码时传"
|
|
|
|
|
+// @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":
|
|
|
|
|
+ captchaKey := captcha_session + c.Ctx.Query("code")
|
|
|
|
|
+ captchaId := utils.GetSession(c.Ctx, captchaKey, "").(string)
|
|
|
|
|
+ check = utils.ImageCaptchaCheck(captcha, captchaId)
|
|
|
|
|
+ if check {
|
|
|
|
|
+ c.Ctx.Set(captchaKey, "")
|
|
|
|
|
+ }
|
|
|
|
|
+ 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})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|