新增了获取oss签名
This commit is contained in:
parent
702e482659
commit
6dd6172be9
@ -63,3 +63,29 @@ func (b *Public) GetIndex(c *gin.Context) {
|
|||||||
|
|
||||||
responses.OkWithData(g, c)
|
responses.OkWithData(g, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOssSign 获取oss签名
|
||||||
|
func (b *Public) GetOssSign(c *gin.Context) {
|
||||||
|
publicRequest := requests.PublicRequest{}
|
||||||
|
req := publicRequest.GetOssSign
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取oss签名
|
||||||
|
publicService := service.PublicService{}
|
||||||
|
ossSign, err := publicService.GetOssSign(req.Scene)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.OkWithData(ossSign, c)
|
||||||
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package requests
|
|||||||
|
|
||||||
type PublicRequest struct {
|
type PublicRequest struct {
|
||||||
GetPhoneCode // 获取手机验证码
|
GetPhoneCode // 获取手机验证码
|
||||||
|
GetOssSign // 获取oss签名
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPhoneCode 获取手机验证码
|
// GetPhoneCode 获取手机验证码
|
||||||
@ -9,3 +10,8 @@ type GetPhoneCode struct {
|
|||||||
Phone string `json:"phone" form:"phone" label:"手机号" validate:"required,Mobile"`
|
Phone string `json:"phone" form:"phone" label:"手机号" validate:"required,Mobile"`
|
||||||
Scene int `json:"scene" form:"scene" label:"场景值" validate:"required,number,min=1,max=1"`
|
Scene int `json:"scene" form:"scene" label:"场景值" validate:"required,number,min=1,max=1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOssSign 获取oss签名
|
||||||
|
type GetOssSign struct {
|
||||||
|
Scene int `json:"scene" form:"scene" validate:"required,oneof=1 2 3 4" label:"场景"` // (1:头像 2:证书 3:名片)
|
||||||
|
}
|
||||||
|
|||||||
@ -127,7 +127,12 @@ func publicRouter(r *gin.Engine, api controller.Api) {
|
|||||||
|
|
||||||
// adminRouter 公共路由-验证权限
|
// adminRouter 公共路由-验证权限
|
||||||
func adminRouter(r *gin.Engine, api controller.Api) {
|
func adminRouter(r *gin.Engine, api controller.Api) {
|
||||||
|
// 签名
|
||||||
|
signGroup := r.Group("/sign")
|
||||||
|
{
|
||||||
|
// 获取oss签名
|
||||||
|
signGroup.GET("/oss", api.Public.GetOssSign)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// basicRouter 基础数据-验证权限
|
// basicRouter 基础数据-验证权限
|
||||||
|
|||||||
@ -131,3 +131,19 @@ func (r *PublicService) GetUserIP(h *http.Request) string {
|
|||||||
}
|
}
|
||||||
return h.RemoteAddr
|
return h.RemoteAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOssSign 获取oss签名
|
||||||
|
func (a *PublicService) GetOssSign(scene int) (*aliyun.GetOssSignResponse, error) {
|
||||||
|
var dir string
|
||||||
|
if scene == 1 {
|
||||||
|
dir = dir + "user/avatar/"
|
||||||
|
}
|
||||||
|
|
||||||
|
if dir == "" {
|
||||||
|
return nil, errors.New("获取签名失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成签名
|
||||||
|
ossSign, _ := aliyun.GetOssSign(dir)
|
||||||
|
return ossSign, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user