diff --git a/api/admin/wechat/officialaccount/media.api b/api/admin/wechat/officialaccount/media.api index 9f4dd0eb..8c0b5b1d 100644 --- a/api/admin/wechat/officialaccount/media.api +++ b/api/admin/wechat/officialaccount/media.api @@ -25,7 +25,7 @@ service PowerX { @doc "请求菜单上传链接" @handler GetOAMedia - post /medias/:mediaId (GetOAMediaRequest) returns (GetOAMediaReply) + get /medias/:mediaId (GetOAMediaRequest) returns (GetOAMediaReply) @doc "创建菜单" diff --git a/go.mod b/go.mod index 3143a7df..4942bb38 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.21 //replace github.com/ArtisanCloud/PowerWeChat/v3 => ../../../PowerWechat/PowerWeChat require ( - github.com/ArtisanCloud/PowerLibs/v3 v3.0.15 + github.com/ArtisanCloud/PowerLibs/v3 v3.0.16 github.com/ArtisanCloud/PowerSocialite/v3 v3.0.7 - github.com/ArtisanCloud/PowerWeChat/v3 v3.1.4 + github.com/ArtisanCloud/PowerWeChat/v3 v3.1.13 github.com/Blank-Xu/sql-adapter v0.0.0-20210714092925-0bdd0d548758 github.com/brianvoe/gofakeit/v6 v6.21.0 github.com/casbin/casbin/v2 v2.60.0 @@ -122,5 +122,6 @@ require ( google.golang.org/grpc v1.58.2 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 0577ee74..15aaadca 100644 --- a/go.sum +++ b/go.sum @@ -385,12 +385,12 @@ cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoIS cloud.google.com/go/workflows v1.8.0/go.mod h1:ysGhmEajwZxGn1OhGOGKsTXc5PyxOc0vfKf5Af+to4M= cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT3ujaO/WwSA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/ArtisanCloud/PowerLibs/v3 v3.0.15 h1:EKWDvgu3y6S7OjT3ku7LEF6l5KpIKygBVVnbn2d+lns= -github.com/ArtisanCloud/PowerLibs/v3 v3.0.15/go.mod h1:KBO7ZQGTBjvYTveKY5M4QQpwxuoGBI0V2fZ4xP+TIuM= +github.com/ArtisanCloud/PowerLibs/v3 v3.0.16 h1:LBgAuPIkNKGh0fL/HK4HHSqWuoMIbRtfFVMHwl2cAsc= +github.com/ArtisanCloud/PowerLibs/v3 v3.0.16/go.mod h1:nuUJGlLNKhBmo5nLBqJOuKD2+oDoJkWaqzxxhkLPo5s= github.com/ArtisanCloud/PowerSocialite/v3 v3.0.7 h1:P+erNlErr+X2v7Et+yTWaTfIRhw+HfpAPdvNIEwk9Gw= github.com/ArtisanCloud/PowerSocialite/v3 v3.0.7/go.mod h1:VZQNCvcK/rldF3QaExiSl1gJEAkyc5/I8RLOd3WFZq4= -github.com/ArtisanCloud/PowerWeChat/v3 v3.1.4 h1:2xrbaBcNvnEUjq5IC0T5j+Q+9HFM8ub6KtBNeVbgVP0= -github.com/ArtisanCloud/PowerWeChat/v3 v3.1.4/go.mod h1:N6ATGWtdjvnts0dzbe9AYxQ1aRuA1yuTTabcUTQPFZo= +github.com/ArtisanCloud/PowerWeChat/v3 v3.1.13 h1:AwIrC2ICmdzyCrI2blvVRD6SU98b1c1oJSzqVD1d2iU= +github.com/ArtisanCloud/PowerWeChat/v3 v3.1.13/go.mod h1:i4quVLQxrTJ4Yg5A5ZKvmkH+P+8VP6+2VzJPc3B6qTo= github.com/Blank-Xu/sql-adapter v0.0.0-20210714092925-0bdd0d548758 h1:L4iwZiJYTNirz4Er7Bw2+AVzW8VCpCGYc8luHc3y5lU= github.com/Blank-Xu/sql-adapter v0.0.0-20210714092925-0bdd0d548758/go.mod h1:GlBcPpgzETyqz83HIUFEMobVY38h1fOFXgwpy7T64xE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -639,8 +639,9 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -1692,6 +1693,8 @@ gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaD gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/handler/routes.go b/internal/handler/routes.go index b3ee9de7..ae54fda3 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1586,7 +1586,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Handler: adminwechatofficialaccountmedia.GetOAMediaNewsListHandler(serverCtx), }, { - Method: http.MethodPost, + Method: http.MethodGet, Path: "/medias/:mediaId", Handler: adminwechatofficialaccountmedia.GetOAMediaHandler(serverCtx), }, diff --git a/internal/logic/admin/wechat/officialaccount/media/getoamedialistlogic.go b/internal/logic/admin/wechat/officialaccount/media/getoamedialistlogic.go index 617edc4b..6244d307 100644 --- a/internal/logic/admin/wechat/officialaccount/media/getoamedialistlogic.go +++ b/internal/logic/admin/wechat/officialaccount/media/getoamedialistlogic.go @@ -30,6 +30,7 @@ func (l *GetOAMediaListLogic) GetOAMediaList(req *types.GetOAMediaListRequest) ( if req.Count <= 0 { req.Count = 10 } + req.Offset -= 1 res, err := l.svcCtx.PowerX.WechatOA.App.Material.List(l.ctx, &request.RequestMaterialBatchGetMaterial{ Type: req.MediaType, Offset: req.Offset, diff --git a/internal/logic/admin/wechat/officialaccount/media/getoamedialogic.go b/internal/logic/admin/wechat/officialaccount/media/getoamedialogic.go index c31df024..d0b7259e 100644 --- a/internal/logic/admin/wechat/officialaccount/media/getoamedialogic.go +++ b/internal/logic/admin/wechat/officialaccount/media/getoamedialogic.go @@ -1,10 +1,9 @@ package media import ( - "context" - "PowerX/internal/svc" "PowerX/internal/types" + "context" "github.com/zeromicro/go-zero/core/logx" ) @@ -24,7 +23,10 @@ func NewGetOAMediaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOAM } func (l *GetOAMediaLogic) GetOAMedia(req *types.GetOAMediaRequest) (resp *types.GetOAMediaReply, err error) { - // todo: add your logic here and delete this line - return + res, err := l.svcCtx.PowerX.WechatOA.App.Material.Get(l.ctx, req.MediaId) + + return &types.GetOAMediaReply{ + OAMedia: res, + }, nil } diff --git a/internal/logic/admin/wechat/officialaccount/media/uploadoamedialogic.go b/internal/logic/admin/wechat/officialaccount/media/uploadoamedialogic.go index ca17d888..0aa90008 100644 --- a/internal/logic/admin/wechat/officialaccount/media/uploadoamedialogic.go +++ b/internal/logic/admin/wechat/officialaccount/media/uploadoamedialogic.go @@ -3,6 +3,7 @@ package media import ( "PowerX/internal/logic/admin/mediaresource" "PowerX/internal/types/errorx" + fmt "PowerX/pkg/printx" "context" fmt2 "fmt" "github.com/ArtisanCloud/PowerLibs/v3/object" @@ -34,11 +35,31 @@ func NewUploadOAMediaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upl func (l *UploadOAMediaLogic) UploadOAMedia(r *http.Request) (resp *types.CreateOAMediaReply, err error) { + // 解析表单数据 err = r.ParseMultipartForm(mediaresource.MaxFileSize) if err != nil { return nil, errorx.WithCause(errorx.ErrBadRequest, err.Error()) } + paramValues := r.Form + mediaType := paramValues.Get("type") + fmt.Dump(mediaType) + query := &object.StringMap{} + res := &response.ResponseMaterialAddMaterial{} + if mediaType == "video" { + jsonDescription, err := object.JsonEncode(&object.HashMap{ + "title": paramValues.Get("title"), + "introduction": paramValues.Get("description"), + }) + if err != nil { + return nil, err + } + + query = &object.StringMap{ + "Description": jsonDescription, + } + } + file, _, err := r.FormFile("file") //fmt.Dump(handler.Filename) if err != nil { @@ -55,6 +76,11 @@ func (l *UploadOAMediaLogic) UploadOAMedia(r *http.Request) (resp *types.CreateO // 获取文件的临时目录和文件名 tempDir := os.TempDir() tempFileName := fmt2.Sprintf("%d_*.jpg", time.Now().Unix()) + if mediaType == "video" { + tempFileName = fmt2.Sprintf("%d_*.mp4", time.Now().Unix()) + } else if mediaType == "voice" { + tempFileName = fmt2.Sprintf("%d_*.mp3", time.Now().Unix()) + } // 创建临时文件 tempFile, err := os.CreateTemp(tempDir, tempFileName) @@ -68,9 +94,8 @@ func (l *UploadOAMediaLogic) UploadOAMedia(r *http.Request) (resp *types.CreateO return nil, errorx.WithCause(errorx.ErrBadRequest, "failed to save file") } //fmt.Dump("temp", tempFile.Name(), "end") - paramValues := r.Form - res := &response.ResponseMaterialAddMaterial{} - _, err = l.svcCtx.PowerX.WechatOA.App.Material.Upload(l.ctx, paramValues.Get("type"), tempFile.Name(), &object.StringMap{}, res) + + _, err = l.svcCtx.PowerX.WechatOA.App.Material.Upload(l.ctx, mediaType, tempFile.Name(), query, res) if err != nil { return nil, errorx.WithCause(errorx.ErrBadRequest, err.Error()) }