zjxpcyc 6 years ago
parent
commit
87c3feeac1
2 changed files with 11 additions and 2 deletions
  1. 2
    0
      controllers/customer/customer.go
  2. 9
    2
      utils/captcha.go

+ 2
- 0
controllers/customer/customer.go View File

@@ -80,6 +80,8 @@ func (c *CustomerController) SignIn() {
80 80
 		if err := utils.ValidCaptcha(phone, captcha); err != nil {
81 81
 			c.ResponseError(err)
82 82
 		}
83
+
84
+		utils.DestoryCaptcha(phone)
83 85
 	}
84 86
 	userMapping := c.Context.Get("userMap").(model.TaUserMapping)
85 87
 	_, err := c.serv.BindWechatUser(&userMapping, phone)

+ 9
- 2
utils/captcha.go View File

@@ -47,6 +47,11 @@ func ValidCaptcha(phone, cap string) error {
47 47
 	return capEngine.ValidCaptcha(phone, cap)
48 48
 }
49 49
 
50
+// DestoryCaptcha 清空验证码
51
+func DestoryCaptcha(phone string) {
52
+	capEngine.DestoryCaptcha(phone)
53
+}
54
+
50 55
 // Random 获取随机数
51 56
 // 连续调用会有随机数不随机问题
52 57
 func (c *CaptchaEngine) Random(length int, phone string) string {
@@ -96,10 +101,12 @@ func (c *CaptchaEngine) ValidCaptcha(phone, cap string) error {
96 101
 		return errors.New("验证码不正确")
97 102
 	}
98 103
 
104
+	return nil
105
+}
106
+
107
+func (c *CaptchaEngine) DestoryCaptcha(phone string) {
99 108
 	// 如果成功, 则注销
100 109
 	delete(c.capList, phone)
101
-
102
-	return nil
103 110
 }
104 111
 
105 112
 func init() {