|
@@ -1,10 +1,12 @@
|
|
package front
|
|
package front
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "app.yhyue.com/moapp/jybase/gocaptcha"
|
|
"app.yhyue.com/moapp/jypkg/public"
|
|
"app.yhyue.com/moapp/jypkg/public"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"jy/src/jfw/config"
|
|
"jy/src/jfw/config"
|
|
|
|
+ "log"
|
|
"regexp"
|
|
"regexp"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -12,7 +14,6 @@ import (
|
|
|
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
|
|
|
|
- "app.yhyue.com/moapp/jybase/dchest/captcha"
|
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -34,18 +35,20 @@ func (f *Front) CheckPhoneNum() error {
|
|
}
|
|
}
|
|
|
|
|
|
// 图片验证码
|
|
// 图片验证码
|
|
-func (c *Front) Captcha() error {
|
|
|
|
- id := captcha.NewLen(4) //此id为生成验证码的ID,并不是实际显示的数字,在提交校验时,需要根据此ID进行查询。
|
|
|
|
- c.SetSession("CheckCodeId", id)
|
|
|
|
- //校验时调用以下代码
|
|
|
|
- //ccid,_:=c.GetSession("CheckCodeId").(string)
|
|
|
|
- //captcha.VerifyString(ccid,"用户输入的校验码")//返回bool
|
|
|
|
- w := c.ResponseWriter
|
|
|
|
- w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
- w.Header().Set("Pragma", "no-cache")
|
|
|
|
- w.Header().Set("Expires", "0")
|
|
|
|
- w.Header().Set("Content-Type", "image/png")
|
|
|
|
- return captcha.WriteImage(w, id, 90, 30)
|
|
|
|
|
|
+func (c *Front) Captcha() {
|
|
|
|
+ gocaptcha.Get(c.Session(), "CheckCodeId", c.ResponseWriter, c.Request)
|
|
|
|
+ //return
|
|
|
|
+ //id := captcha.NewLen(4) //此id为生成验证码的ID,并不是实际显示的数字,在提交校验时,需要根据此ID进行查询。
|
|
|
|
+ //c.SetSession("CheckCodeId", id)
|
|
|
|
+ ////校验时调用以下代码
|
|
|
|
+ ////ccid,_:=c.GetSession("CheckCodeId").(string)
|
|
|
|
+ ////captcha.VerifyString(ccid,"用户输入的校验码")//返回bool
|
|
|
|
+ //w := c.ResponseWriter
|
|
|
|
+ //w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
+ //w.Header().Set("Pragma", "no-cache")
|
|
|
|
+ //w.Header().Set("Expires", "0")
|
|
|
|
+ //w.Header().Set("Content-Type", "image/png")
|
|
|
|
+ //return captcha.WriteImage(w, id, 90, 30)
|
|
}
|
|
}
|
|
|
|
|
|
// 发送短信验证
|
|
// 发送短信验证
|
|
@@ -59,7 +62,8 @@ func (f *Front) SendMessage() {
|
|
ccid, _ := getsession["CheckCodeId"].(string)
|
|
ccid, _ := getsession["CheckCodeId"].(string)
|
|
lastSendMsgTime := util.Int64All(getsession["lastSendMsgTime"])
|
|
lastSendMsgTime := util.Int64All(getsession["lastSendMsgTime"])
|
|
//通过图片验证
|
|
//通过图片验证
|
|
- if captcha.VerifyString(ccid, imgCancode) {
|
|
|
|
|
|
+ log.Println(imgCancode, "---", ccid)
|
|
|
|
+ if imgCancode == ccid { //captcha.VerifyString(ccid, imgCancode)
|
|
//当前时间-上次发送时间>60s
|
|
//当前时间-上次发送时间>60s
|
|
if time.Now().Unix()-lastSendMsgTime > 60 {
|
|
if time.Now().Unix()-lastSendMsgTime > 60 {
|
|
if !userIsExists(phoneNum) && phoneReg.MatchString(phoneNum) {
|
|
if !userIsExists(phoneNum) && phoneReg.MatchString(phoneNum) {
|