huangjiajun пре 2 недеља
родитељ
комит
b8b091ea9f
6 измењених фајлова са 281 додато и 7 уклоњено
  1. +111
    -0
      app/hdl/hdl_qiniuyun.go
  2. +6
    -4
      app/router/router.go
  3. +61
    -0
      docs/docs.go
  4. +61
    -0
      docs/swagger.json
  5. +40
    -0
      docs/swagger.yaml
  6. +2
    -3
      go.mod

+ 111
- 0
app/hdl/hdl_qiniuyun.go Прегледај датотеку

@@ -0,0 +1,111 @@
package hdl

import (
"applet/app/db/implement"
"applet/app/e"
"applet/app/lib/validate"
"applet/app/md"
"applet/app/svc"
"applet/app/utils"
"applet/app/utils/logx"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
qiniu "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/qiniuyun"
"fmt"
"github.com/gin-gonic/gin"
)

// ImgReqUpload
// @Summary 七牛云上传
// @Tags 七牛云
// @Description 七牛云-七牛云上传
// @param Authorization header string false "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.ImgReqUpload true "请求参数"
// @Success 200 {string} "success"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/qiniuyun/upload [POST]
func ImgReqUpload(c *gin.Context) {
var args md.ImgReqUpload
err := c.ShouldBindJSON(&args)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
// 文件名名称

if args.FileSize < 1 || args.FileName == "" {
logx.Warn(err)
e.OutErr(c, e.ERR_INVALID_ARGS)
return
}
scheme := "http"
if c.Request.TLS != nil {
scheme = "https"
}
// 拼装回调地址
callbackUrl := scheme + "://" + c.Request.Host + "/api/qiniuyun/callback?master_id=" + c.GetString("mid")
NewSysCfgDb := implement.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))
stgInfo := NewSysCfgDb.SysCfgFindWithDb(
md2.KEY_CFG_FILE_BUCKET,
md2.KEY_CFG_FILE_HOST,
md2.KEY_CFG_FILE_AK,
md2.KEY_CFG_FILE_SK,
md2.KEY_CFG_FILE_PVD,
md2.KEY_CFG_FILE_REGION,
md2.KEY_CFG_FILE_MAX_SIZE,
md2.KEY_CFG_FILE_EXT,
md2.KEY_CFG_FILE_SCHEME,
md2.KEY_CFG_FILE_AVATAR_THUMBNAIL,
)
if stgInfo == nil {
e.OutErr(c, 400, e.NewErr(400, "配置未设置"))
return
}
res, err := qiniu.ImgReqUpload(stgInfo, "", args.Dir, args.FileName, callbackUrl, args.FileSize)
if err != nil {
e.OutErr(c, 400, err.Error())
return
}
my := utils.SerializeStr(res)
var my1 map[string]interface{}
utils.Unserialize([]byte(my), &my1)
e.OutSuc(c, my1, nil)
return
}
func FileImgCallback(c *gin.Context) {
masterID := c.Query("master_id")
c.Set("mid", masterID)
var args md2.FileCallback
err := c.ShouldBindJSON(&args)

if err != nil {
fmt.Println("七牛云上传回调参数错误:>>>>>>>>>>", err)
e.OutErr(c, 200, e.ERR_INVALID_ARGS)
return
}
res := map[string]interface{}{
"name": args.FileName,
"fname": getFileNameURL(c, args.FileName),
"fsize": args.FileSize,
"provider": args.Provider,
"uid": args.Uid,
"dir_id": args.DirId,
"w": args.Width,
"h": args.Height,
}
e.OutSuc(c, &res, nil)
}

func getFileNameURL(c *gin.Context, filename string) string {
NewSysCfgDb := implement.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))

protocol := NewSysCfgDb.SysCfgGetWithDb("file_bucket_scheme")
domain := NewSysCfgDb.SysCfgGetWithDb("file_bucket_host")
if protocol != "" && domain != "" {
return protocol + "://" + domain + "/" + filename
}
return filename
}

+ 6
- 4
app/router/router.go Прегледај датотеку

@@ -52,13 +52,15 @@ func Init() *gin.Engine {
func route(r *gin.RouterGroup) {
r.GET("/test", hdl.Demo)
r.GET("/authorize", hdl.AppletAuthorize)
r.Use(mw.DB) // 以下接口需要用到数据库
r.POST("/qiniuyun/callback", hdl.FileImgCallback) //七牛云回调
r.Use(mw.DB) // 以下接口需要用到数据库
{
r.POST("/login", hdl.Login)
}
r.Use(mw.CheckBody) //body参数转换
r.Use(mw.CheckSign) //签名校验
r.Use(mw.CheckBody) //body参数转换
r.Use(mw.CheckSign) //签名校验
r.POST("/qiniuyun/upload", hdl.ImgReqUpload) //七牛云上传

r.POST("/registerForMedium", hdl.RegisterForMedium)
r.POST("/registerForAgent", hdl.RegisterForAgent)



+ 61
- 0
docs/docs.go Прегледај датотеку

@@ -3169,6 +3169,52 @@ const docTemplate = `{
}
}
},
"/api/qiniuyun/upload": {
"post": {
"description": "七牛云-七牛云上传",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"七牛云"
],
"summary": "七牛云上传",
"parameters": [
{
"type": "string",
"description": "验证参数Bearer和token空格拼接",
"name": "Authorization",
"in": "header"
},
{
"description": "请求参数",
"name": "args",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.ImgReqUpload"
}
}
],
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
},
"400": {
"description": "具体错误",
"schema": {
"$ref": "#/definitions/md.Response"
}
}
}
}
},
"/api/qualification/select/base": {
"get": {
"description": "资质认证-认证下拉框选择内容",
@@ -7197,6 +7243,21 @@ const docTemplate = `{
}
}
},
"md.ImgReqUpload": {
"type": "object",
"properties": {
"dir": {
"type": "string"
},
"file_name": {
"type": "string"
},
"file_size": {
"description": "文件大小, 单位byte",
"type": "integer"
}
}
},
"md.IndexAppListData": {
"type": "object",
"properties": {


+ 61
- 0
docs/swagger.json Прегледај датотеку

@@ -3161,6 +3161,52 @@
}
}
},
"/api/qiniuyun/upload": {
"post": {
"description": "七牛云-七牛云上传",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"七牛云"
],
"summary": "七牛云上传",
"parameters": [
{
"type": "string",
"description": "验证参数Bearer和token空格拼接",
"name": "Authorization",
"in": "header"
},
{
"description": "请求参数",
"name": "args",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.ImgReqUpload"
}
}
],
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
},
"400": {
"description": "具体错误",
"schema": {
"$ref": "#/definitions/md.Response"
}
}
}
}
},
"/api/qualification/select/base": {
"get": {
"description": "资质认证-认证下拉框选择内容",
@@ -7189,6 +7235,21 @@
}
}
},
"md.ImgReqUpload": {
"type": "object",
"properties": {
"dir": {
"type": "string"
},
"file_name": {
"type": "string"
},
"file_size": {
"description": "文件大小, 单位byte",
"type": "integer"
}
}
},
"md.IndexAppListData": {
"type": "object",
"properties": {


+ 40
- 0
docs/swagger.yaml Прегледај датотеку

@@ -1711,6 +1711,16 @@ definitions:
example: 已消耗金额
type: string
type: object
md.ImgReqUpload:
properties:
dir:
type: string
file_name:
type: string
file_size:
description: 文件大小, 单位byte
type: integer
type: object
md.IndexAppListData:
properties:
list:
@@ -4526,6 +4536,36 @@ paths:
summary: 主体资质审核
tags:
- 媒体资质------嘉俊
/api/qiniuyun/upload:
post:
consumes:
- application/json
description: 七牛云-七牛云上传
parameters:
- description: 验证参数Bearer和token空格拼接
in: header
name: Authorization
type: string
- description: 请求参数
in: body
name: args
required: true
schema:
$ref: '#/definitions/md.ImgReqUpload'
produces:
- application/json
responses:
"200":
description: success
schema:
type: string
"400":
description: 具体错误
schema:
$ref: '#/definitions/md.Response'
summary: 七牛云上传
tags:
- 七牛云
/api/qualification/select/base:
get:
consumes:


+ 2
- 3
go.mod Прегледај датотеку

@@ -31,11 +31,12 @@ require (
go.uber.org/zap v1.16.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
xorm.io/xorm v1.3.1
xorm.io/xorm v1.3.2
)

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240830072333-a1980ffb256e
github.com/jinzhu/copier v0.4.0
)

@@ -66,8 +67,6 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo v1.15.0 // indirect
github.com/onsi/gomega v1.10.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/streadway/amqp v1.0.0 // indirect


Loading…
Откажи
Сачувај