diff --git a/weixin/oa_sdk.go b/weixin/oa_sdk.go index 5551c45..0adb6fe 100644 --- a/weixin/oa_sdk.go +++ b/weixin/oa_sdk.go @@ -115,7 +115,28 @@ func (o *OaSdk) UploadFileByByte(file []byte, ext string) (string, string, error if err != nil { return "", "", err } - res, err := http.Post(UploadOaMedia, writer.FormDataContentType(), body) + token, err := o.getAccessToken() + if err != nil { + return "", "", err + } + postType := "" + if ext == ".jpg" || ext == ".png" || ext == ".gif" || ext == ".jpeg" { + postType = "image" + } else if ext == ".mp4" { + postType = "video" + } else if ext == ".mp3" { + postType = "voice" + } + + if postType == "" { + return "", "", fmt.Errorf("不支持的文件类型") + } + + res, err := http.Post( + fmt.Sprintf("%s?access_token=%s&type=%s", UploadOaMedia, token, postType), + writer.FormDataContentType(), + body, + ) if err != nil { return "", "", err }