diff --git a/app/constants/common/common.go b/app/constants/common/common.go index a3a296b..fd2c621 100644 --- a/app/constants/common/common.go +++ b/app/constants/common/common.go @@ -1,7 +1,8 @@ package common const ( - TOKEN_PRE = "player_token_" - TOKEN_Admin = "Admin_token_" - ADMIN_V1 = "/admin/api/v1" + TOKEN_PRE = "player_token_" + TOKEN_Admin = "Admin_token_" + ADMIN_V1 = "/admin/api/v1" + FRONT_API_V1 = "/v1" ) diff --git a/app/http/controllers/front/Sm2_Controller.go b/app/http/controllers/front/Sm2Controller.go similarity index 100% rename from app/http/controllers/front/Sm2_Controller.go rename to app/http/controllers/front/Sm2Controller.go diff --git a/app/http/controllers/front/UsersController.go b/app/http/controllers/front/UsersController.go new file mode 100644 index 0000000..d189f7f --- /dev/null +++ b/app/http/controllers/front/UsersController.go @@ -0,0 +1,13 @@ +package front + +import ( + "github.com/gin-gonic/gin" + "qteam/app/http/controllers" + "qteam/app/http/entities/front" + "qteam/app/services" +) + +func XyLogin(c *gin.Context) { + var request = controllers.GetRequest(c).(*front.LoginRequest) + services.XyYouKuLogin(request) +} diff --git a/app/http/entities/front/user.go b/app/http/entities/front/user.go new file mode 100644 index 0000000..da54938 --- /dev/null +++ b/app/http/entities/front/user.go @@ -0,0 +1,28 @@ +package front + +import ( + "qteam/app/models/usersmodel" + "time" +) + +type LoginRequest struct { + Data string `form:"data" validate:"required"` +} + +type XyDecryptData struct { + Mobile string `json:"phone"` + CerNo string `json:"cerNo"` + Time string `json:"time"` +} + +type LoginResponse struct { + Token string `json:"token"` +} + +func (this *XyDecryptData) RequestToDb() (user usersmodel.Users) { + user.Phone = this.Mobile + user.Name = this.Mobile + user.CreateTime = time.Now() + user.UpdateTime = time.Now() + return +} diff --git a/app/http/requestmapping/front.go b/app/http/requestmapping/front.go index 8594e49..071f3b7 100644 --- a/app/http/requestmapping/front.go +++ b/app/http/requestmapping/front.go @@ -1,5 +1,13 @@ package requestmapping +import ( + "qteam/app/constants/common" + "qteam/app/http/entities/front" +) + var FrontRequestMap = map[string]func() interface{}{ "/v1/GenerateSm2Key": func() interface{} { return new(struct{}) }, + + // 兴业银行登录 + common.FRONT_API_V1 + "/xy/login": func() interface{} { return new(front.LoginRequest) }, } diff --git a/app/http/routes/route.go b/app/http/routes/route.go index 7abc1a7..035f220 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -14,8 +14,6 @@ import ( "github.com/gin-gonic/gin" "github.com/qit-team/snow-core/http/middleware" "github.com/qit-team/snow-core/log/logger" - "github.com/swaggo/gin-swagger" - "github.com/swaggo/gin-swagger/swaggerFiles" ) // api路由配置 @@ -46,14 +44,6 @@ func RegisterRoute(router *gin.Engine) { //api版本 v1 := router.Group("/v1", middlewares.ValidateRequest()) { - v1.GET("/GenerateSm2Key", front.GetGenerateSm2Key) + v1.POST("/xy/login", front.XyLogin) } - - router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) - - //router.GET("/hello", controllers.HelloHandler) - //router.GET("/create", controllers.HelloCreateHandler) - //router.GET("/update", controllers.UpdateHandler) - //router.GET("/delete", controllers.DeleteHandler) - //router.GET("/query", controllers.QueryHandler) } diff --git a/app/services/SmService.go b/app/services/Sm2Service.go similarity index 99% rename from app/services/SmService.go rename to app/services/Sm2Service.go index 1e14417..c082df7 100644 --- a/app/services/SmService.go +++ b/app/services/Sm2Service.go @@ -98,7 +98,7 @@ func decryptLoc(publicKeyStr, privateKeyStr, cipherText string) (string, error) if err != nil { fmt.Println(err) } - resultStr := hex.EncodeToString(decrypt) + resultStr := string(decrypt) fmt.Println("解密后的字符串:", resultStr) return resultStr, nil } diff --git a/app/services/UsersService.go b/app/services/UsersService.go new file mode 100644 index 0000000..4185a7c --- /dev/null +++ b/app/services/UsersService.go @@ -0,0 +1,32 @@ +package services + +import ( + "qteam/app/constants/errorcode" + "qteam/app/http/entities/front" + "qteam/app/models/usersmodel" +) + +func XyYouKuLogin(req *front.LoginRequest) (code int, user usersmodel.Users) { + var err error + info := DecryptXyData(req.Data) + if info.Mobile == "" { + code = errorcode.ParamError + return + } + var addUser = false + var session = usersmodel.GetInstance().GetDb().Where("phone = ?", info.Mobile) + _, err = session.Get(&user) + code = errorcode.Success + if user.Id < 1 { + addUser = true + } + if addUser { + user = info.RequestToDb() + _, err = usersmodel.GetInstance().GetDb().Insert(&user) + } + if err != nil { + code = handErr(err) + } + + return code, user +} diff --git a/app/services/XinYeService.go b/app/services/XinYeService.go new file mode 100644 index 0000000..86841a8 --- /dev/null +++ b/app/services/XinYeService.go @@ -0,0 +1,29 @@ +package services + +import ( + "encoding/base64" + "encoding/json" + "fmt" + "qteam/app/http/entities/front" +) + +func DecryptXyData(data string) (info front.XyDecryptData) { + // 解码 + decodedBytes, err := base64.StdEncoding.DecodeString(data) + if err != nil { + fmt.Println("解码错误:", err) + return + } + fmt.Println("解码后的数据:", string(decodedBytes)) + // 使用Hex.EncodeToString将字节切片转换为十六进制字符串 + decrypt, err := SM2Decrypt(string(decodedBytes)) + if err != nil { + return + } + err = json.Unmarshal([]byte(decrypt), &info) + if err != nil { + fmt.Println("解析JSON错误:", err) + return + } + return +} diff --git a/app/services/common.go b/app/services/common.go new file mode 100644 index 0000000..a29c600 --- /dev/null +++ b/app/services/common.go @@ -0,0 +1,15 @@ +package services + +import ( + "qteam/app/constants/errorcode" + "qteam/app/utils" +) + +func handErr(err error) int { + if err != nil { + utils.Log(nil, "sys err", err.Error()) + return errorcode.SystemError + } else { + return errorcode.Success + } +} diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 785b058..2e81a29 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -57,11 +57,11 @@ func Bootstrap(conf *config.Config) (err error) { //注册应用停止时调用的关闭服务 close.MultiRegister(db.Pr, redis.Pr) - ////Register + //Register //_, err = utils.GetNaocosClient().RegisterInstance(vo.RegisterInstanceParam{ // Ip: utils.GetHostIp(), // Port: uint64(conf.Api.Port), - // ServiceName: "snow", + // ServiceName: conf.ServiceName, // GroupName: "group-d", // ClusterName: "cluster-snow", // Weight: 10,