mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 21:02:25 +08:00
* 企业微信-客户联系-统计管理 * 企业微信-客户联系-统计管理 * 企业微信-客户联系-统计管理 * debug * rollback * debug * debug * 获取用户信息 * token * json.Marshal错误输出 * debug * bugfix * 企业微信-通讯录管理相关接口 * 企业微信-通讯录管理 * 企业微信-通讯录管理 * 企业微信-通讯录管理 * 企业微信-[联系我]方式新增和查询 * 企业微信-[联系我]方式新增和获取 * 企业微信-[联系我]方式更新 * 企业微信-[联系我]方式列表、删除 * json.Marshal错误输出 * 已实现接口bug修改 * 历史接口bugfix * 历史接口bugfix * comment * 企业微信:客户联系-消息推送;素材管理-上传图片 * fix * 企业微信-获取群发记录列表 * 历史接口bugfix * 1.企业微信-客户联系-消息推送-入群欢迎语素材管理 2.企业微信-通讯录管理-成员管理-获取成员ID列表 * golangci-lint * gofmt * 方法访问命名 * 企业微信-批量获取客户详情入参优化 * 企业微信-通讯录管理-标签管理-创建/更新/删除标签 * 请求地址常量无需导出 * 企业微信保持代码风格统一,接口URL不导出 --------- Co-authored-by: wang.yu <wangyu@uniondrug.com> Co-authored-by: markwang <www.wang61@qq.com>
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package material
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/silenceper/wechat/v2/util"
|
||
)
|
||
|
||
const (
|
||
// uploadImgURL 上传图片
|
||
uploadImgURL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
|
||
// uploadTempFile 上传临时素材
|
||
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
|
||
)
|
||
|
||
// UploadImgResponse 上传图片响应
|
||
type UploadImgResponse struct {
|
||
util.CommonError
|
||
URL string `json:"url"`
|
||
}
|
||
|
||
// UploadTempFileResponse 上传临时素材响应
|
||
type UploadTempFileResponse struct {
|
||
util.CommonError
|
||
MediaID string `json:"media_id"`
|
||
CreateAt string `json:"created_at"`
|
||
Type string `json:"type"`
|
||
}
|
||
|
||
// UploadImg 上传图片
|
||
// @see https://developer.work.weixin.qq.com/document/path/90256
|
||
func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) {
|
||
var (
|
||
accessToken string
|
||
err error
|
||
)
|
||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||
return nil, err
|
||
}
|
||
var response []byte
|
||
if response, err = util.PostFile("media", filename, fmt.Sprintf(uploadImgURL, accessToken)); err != nil {
|
||
return nil, err
|
||
}
|
||
result := &UploadImgResponse{}
|
||
if err = util.DecodeWithError(response, result, "UploadImg"); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// UploadTempFile 上传临时素材
|
||
// @see https://developer.work.weixin.qq.com/document/path/90253
|
||
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
|
||
func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempFileResponse, error) {
|
||
var (
|
||
accessToken string
|
||
err error
|
||
)
|
||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||
return nil, err
|
||
}
|
||
var response []byte
|
||
if response, err = util.PostFile("media", filename, fmt.Sprintf(uploadTempFile, accessToken, mediaType)); err != nil {
|
||
return nil, err
|
||
}
|
||
result := &UploadTempFileResponse{}
|
||
if err = util.DecodeWithError(response, result, "UploadTempFile"); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|