Ver a proveniência

验证码

tmp
huangjiajun há 6 dias
ascendente
cometimento
e8ff767101
5 ficheiros alterados com 87 adições e 46 eliminações
  1. +23
    -33
      app/hdl/hdl_login.go
  2. +3
    -7
      app/hdl/hdl_user.go
  3. +4
    -4
      app/mw/mw_limiter.go
  4. +55
    -0
      app/svc/svc_sms.go
  5. +2
    -2
      go.mod

+ 23
- 33
app/hdl/hdl_login.go Ver ficheiro

@@ -1,7 +1,6 @@
package hdl

import (
"applet/app/cfg"
"applet/app/db"
"applet/app/e"
"applet/app/lib/validate"
@@ -67,22 +66,20 @@ func SmsSend(c *gin.Context) {
return
}
}
param := map[string]string{
"lot_number": req.LotNumber,
"gen_time": req.GenTime,
"captcha_output": req.CaptchaOutput,
"pass_token": req.PassToken,
}
//校验图形验证码
id, key := svc.AliyunCaptchBase(c)
err = aliyun.AliyunCheckCaptcha(id, key, param)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "图形验证码校验失败"))
return
}
data := svc.AliyunSmsBase(c, req.Type)
//发送短信
err = aliyun.AliyunSendSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, data["aliyun_sms_sign_name"], data["aliyun_sms_code"], "")
//param := map[string]string{
// "lot_number": req.LotNumber,
// "gen_time": req.GenTime,
// "captcha_output": req.CaptchaOutput,
// "pass_token": req.PassToken,
//}
////校验图形验证码
//id, key := svc.AliyunCaptchBase(c)
//err = aliyun.AliyunCheckCaptcha(id, key, param)
//if err != nil {
// e.OutErr(c, 400, e.NewErr(400, "图形验证码校验失败"))
// return
//}
err = svc.CommSmsSend(c, req.Mobile, req.Type)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "发送失败"))
return
@@ -246,9 +243,8 @@ func FindPassword(c *gin.Context) {
e.OutErr(c, 400, e.NewErr(400, "手机号不存在"))
return
}
data := svc.AliyunSmsBase(c, "")
//校验短信
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, req.Code)
err = svc.CommSmsCheck(c, req.Mobile, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
@@ -278,14 +274,11 @@ func Register(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
data := svc.AliyunSmsBase(c, "")
//校验短信
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, req.Code)
if cfg.Prd {
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
}
err = svc.CommSmsCheck(c, req.Mobile, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
}
commReq(c, req)
}
@@ -309,14 +302,11 @@ func WechatRegister(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
data := svc.AliyunSmsBase(c, "")
//校验短信
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, req.Code)
if cfg.Prd {
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
}
err = svc.CommSmsCheck(c, req.Mobile, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
}
if req.WechatCode == "" {
e.OutErr(c, 400, "获取微信信息失败")


+ 3
- 7
app/hdl/hdl_user.go Ver ficheiro

@@ -13,7 +13,6 @@ import (
"applet/app/utils/qrcode"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/baidu"
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
md4 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
@@ -268,9 +267,8 @@ func UpdatePassword(c *gin.Context) {
return
}
user := svc.GetUser(c)
data := svc.AliyunSmsBase(c, "")
//校验短信
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
err = svc.CommSmsCheck(c, user.Phone, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
@@ -301,9 +299,8 @@ func UpdatePasscode(c *gin.Context) {
return
}
user := svc.GetUser(c)
data := svc.AliyunSmsBase(c, "")
//校验短信
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
err = svc.CommSmsCheck(c, user.Phone, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
@@ -442,9 +439,8 @@ func Delete(c *gin.Context) {
return
}
user := svc.GetUser(c)
data := svc.AliyunSmsBase(c, "")
//校验短信
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
err = svc.CommSmsCheck(c, user.Phone, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return


+ 4
- 4
app/mw/mw_limiter.go Ver ficheiro

@@ -16,10 +16,10 @@ func Limiter(c *gin.Context) {
limit := 500 // 限流次数
ttl := 2 // 限流过期时间
ip := utils.GetIP(c.Request)
if ip != "221.4.210.167" {
e.OutErr(c, e.ERR, "系统维护中~")
return
}
//if ip != "221.4.210.167" {
// e.OutErr(c, e.ERR, "系统维护中~")
// return
//}
// 读取token或者ip
token := c.GetHeader("Authorization")
// 判断是否已经超出限额次数


+ 55
- 0
app/svc/svc_sms.go Ver ficheiro

@@ -0,0 +1,55 @@
package svc

import (
"applet/app/e"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/mob"
"errors"
"fmt"
"github.com/gin-gonic/gin"
)

func CommSmsSend(c *gin.Context, mobile, types string) error {
smsPlatform := GetSysCfgStr("sms_platform")
var err error
if smsPlatform == "mob" {
err = mob.MobSms(GetSysCfgStr("mob_key"), mobile, GetSysCfgStr("mob_temple_code"))
if err != nil {
fmt.Println("短信错误:" + err.Error())
return err
}
} else {
data := AliyunSmsBase(c, types)
//发送短信
err = aliyun.AliyunSendSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], mobile, data["aliyun_sms_sign_name"], data["aliyun_sms_code"], "")
if err != nil {
fmt.Println("短信错误:" + err.Error())
return errors.New("发送失败")
}
}
return nil
}

func CommSmsCheck(c *gin.Context, mobile, code string) error {
//校验短信
smsPlatform := GetSysCfgStr("sms_platform")
var err error
var bools bool
if smsPlatform == "mob" {
bools, err = mob.MobSMSCheck(GetSysCfgStr("mob_key"), mobile, code)
if err != nil {
fmt.Println("短信错误:" + err.Error())
return err
}
if bools == false {
return e.NewErr(400, "验证码错误,请重试")
}
} else {
data := AliyunSmsBase(c, "")
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], mobile, code)
if err != nil {
return e.NewErr(400, "验证码错误,请重试")
}
}
return nil
}

+ 2
- 2
go.mod Ver ficheiro

@@ -33,7 +33,7 @@ require (

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241216083317-8f7f975c0482
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241216085945-78fe55637e4b
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241217024021-c647f6414cc9
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
@@ -47,7 +47,7 @@ require (
github.com/google/uuid v1.3.0
github.com/olivere/elastic/v7 v7.0.32
github.com/shopspring/decimal v1.3.1
github.com/tidwall/gjson v1.14.1
github.com/tidwall/gjson v1.18.0
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.34.0
)


Carregando…
Cancelar
Guardar