mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-23 14:32:27 +08:00
init commit
This commit is contained in:
65
service/gm-hk4e/controller/gacha_controller.go
Normal file
65
service/gm-hk4e/controller/gacha_controller.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"flswld.com/common/entity/dto"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
UserId uint32 `json:"userId"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
func (c *Controller) gacha(context *gin.Context) {
|
||||
jwtStr := context.Query("jwt")
|
||||
token, err := jwt.ParseWithClaims(jwtStr, new(UserInfo), func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte("flswld"), nil
|
||||
})
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(10005, "验签失败", nil))
|
||||
return
|
||||
}
|
||||
if !token.Valid {
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(10005, "验签失败", nil))
|
||||
return
|
||||
}
|
||||
info, ok := token.Claims.(*UserInfo)
|
||||
if !ok {
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(10005, "验签失败", nil))
|
||||
return
|
||||
}
|
||||
gachaType := context.Query("gachaType")
|
||||
rsp := map[string]any{
|
||||
"uid": info.UserId,
|
||||
"gachaType": gachaType,
|
||||
}
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(0, "成功", rsp))
|
||||
}
|
||||
|
||||
func (c *Controller) gachaDetails(context *gin.Context) {
|
||||
jwtStr := context.Query("jwt")
|
||||
token, err := jwt.ParseWithClaims(jwtStr, new(UserInfo), func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte("flswld"), nil
|
||||
})
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(10005, "验签失败", nil))
|
||||
return
|
||||
}
|
||||
if !token.Valid {
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(10005, "验签失败", nil))
|
||||
return
|
||||
}
|
||||
info, ok := token.Claims.(*UserInfo)
|
||||
if !ok {
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(10005, "验签失败", nil))
|
||||
return
|
||||
}
|
||||
scheduleId := context.Query("scheduleId")
|
||||
rsp := map[string]any{
|
||||
"uid": info.UserId,
|
||||
"scheduleId": scheduleId,
|
||||
}
|
||||
context.JSON(http.StatusOK, dto.NewResponseResult(0, "成功", rsp))
|
||||
}
|
||||
Reference in New Issue
Block a user