Browse Source

wip:绑定手机号

wangshan 4 months ago
parent
commit
d810fae8c2
1 changed files with 24 additions and 4 deletions
  1. 24 4
      src/jfw/modules/subscribepay/src/service/userAccountInfo.go

+ 24 - 4
src/jfw/modules/subscribepay/src/service/userAccountInfo.go

@@ -20,6 +20,7 @@ import (
 	"github.com/gogf/gf/v2/util/gconv"
 
 	. "app.yhyue.com/moapp/jybase/api"
+	jycaptcha "app.yhyue.com/moapp/jybase/captcha"
 	qutil "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/dchest/captcha"
@@ -601,10 +602,29 @@ func (this *UserAccount) PhoneBind() {
 				return nil, fmt.Errorf("已绑定手机号,请勿重复绑定")
 			}
 		}
-		//发送验证码&校验验证码逻辑
-		phoneVerify, err := phoneStep(this.Request, this.Session(), step, phone, code, "bind")
-		if err != nil {
-			return nil, err
+		var (
+			phoneVerify string
+			err         error
+		)
+		captchaKey := this.GetString("captchaKey") //图形验证码key
+		if captchaKey != "" {
+			if strings.TrimSpace(phone) == "" {
+				return nil, fmt.Errorf("手机号异常")
+			}
+			if getPhoneByUserId(userId) != "" {
+				return nil, fmt.Errorf("已绑定手机号,请勿重复绑定")
+			}
+			identCode := this.GetString("identCode") //短信验证码
+			captchaPhone := jy.CheckPhoneIdent(this.Session(), identCode, fmt.Sprintf(jycaptcha.SendCodeKey, captchaKey, phone))
+			if phone != captchaPhone { //验证码不正确
+				return nil, fmt.Errorf("验证码错误")
+			}
+		} else {
+			//发送验证码&校验验证码逻辑
+			phoneVerify, err = phoneStep(this.Request, this.Session(), step, phone, code, "bind")
+			if err != nil {
+				return nil, err
+			}
 		}
 		rData := map[string]interface{}{
 			"state": 1,