Skip to content

Commit

Permalink
Merge pull request #279 from ArtisanCloud/dev/michaelhu
Browse files Browse the repository at this point in the history
Dev/michaelhu
  • Loading branch information
Matrix-X committed Nov 23, 2023
2 parents 6d8dfe0 + bf7628d commit 5280472
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/admin/wechat/officialaccount/media.api
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ service PowerX {

@doc "请求菜单上传链接"
@handler GetOAMedia
post /medias/:mediaId (GetOAMediaRequest) returns (GetOAMediaReply)
get /medias/:mediaId (GetOAMediaRequest) returns (GetOAMediaReply)


@doc "创建菜单"
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package media

import (
"context"

"PowerX/internal/svc"
"PowerX/internal/types"
"context"

"github.com/zeromicro/go-zero/core/logx"
)
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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())
}
Expand Down

0 comments on commit 5280472

Please sign in to comment.