本文整理汇总了Golang中github.com/chanxuehong/wechat/v2/mp/core.Client.PostMultipartForm方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.PostMultipartForm方法的具体用法?Golang Client.PostMultipartForm怎么用?Golang Client.PostMultipartForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/chanxuehong/wechat/v2/mp/core.Client
的用法示例。
在下文中一共展示了Client.PostMultipartForm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UploadImageFromReader
// UploadImageFromReader 上传图片到微信服务器, 返回的图片url给其他场景使用, 比如图文消息, 卡卷, POI.
// NOTE: 参数 filename 不是文件路径, 是 multipart/form-data 里面 filename 的值.
func UploadImageFromReader(clt *core.Client, filename string, reader io.Reader) (url string, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token="
var fields = []core.MultipartFormField{
{
IsFile: true,
Name: "media",
FileName: filename,
Value: reader,
},
}
var result struct {
core.Error
URL string `json:"url"`
}
if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
url = result.URL
return
}
示例2: UploadThumbFromReader
// UploadThumbFromReader 上传多媒体缩略图
// NOTE: 参数 filename 不是文件路径, 是 multipart/form-data 里面 filename 的值.
func UploadThumbFromReader(clt *core.Client, filename string, reader io.Reader) (mediaId, url string, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/material/add_material?type=thumb&access_token="
var fields = []core.MultipartFormField{
{
IsFile: true,
Name: "media",
FileName: filename,
Value: reader,
},
}
var result struct {
core.Error
MediaId string `json:"media_id"`
URL string `json:"url"`
}
if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
mediaId = result.MediaId
url = result.URL
return
}
示例3: uploadFromReader
func uploadFromReader(clt *core.Client, mediaType, filename string, reader io.Reader) (info *MediaInfo, err error) {
var incompleteURL = "https://api.weixin.qq.com/cgi-bin/media/upload?type=" + mediaType + "&access_token="
var fields = []core.MultipartFormField{
{
IsFile: true,
Name: "media",
FileName: filename,
Value: reader,
},
}
var result struct {
core.Error
MediaInfo
}
if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
info = &result.MediaInfo
return
}
示例4: addFromReader
func addFromReader(clt *core.Client, filename string, reader io.Reader, _type string) (info ImageInfo, err error) {
var result struct {
core.Error
ImageInfo `json:"data"`
}
var incompleteURL string
if _type != "" {
incompleteURL = "https://api.weixin.qq.com/shakearound/material/add?type=" + url.QueryEscape(_type) +
"&access_token="
} else {
incompleteURL = "https://api.weixin.qq.com/shakearound/material/add?access_token="
}
fields := []core.MultipartFormField{{
IsFile: true,
Name: "media",
FileName: filename,
Value: reader,
}}
if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
info = result.ImageInfo
return
}
示例5: UploadVideoFromReader
// UploadVideoFromReader 上传多媒体缩视频.
// NOTE: 参数 filename 不是文件路径, 是 multipart/form-data 里面 filename 的值.
func UploadVideoFromReader(clt *core.Client, filename string, reader io.Reader, title, introduction string) (mediaId string, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/material/add_material?type=video&access_token="
var description = struct {
Title string `json:"title"`
Introduction string `json:"introduction"`
}{
Title: title,
Introduction: introduction,
}
descriptionBytes, err := json.Marshal(&description)
if err != nil {
return
}
var fields = []core.MultipartFormField{
{
IsFile: true,
Name: "media",
FileName: filename,
Value: reader,
},
{
IsFile: false,
Name: "description",
Value: bytes.NewReader(descriptionBytes),
},
}
var result struct {
core.Error
MediaId string `json:"media_id"`
}
if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
mediaId = result.MediaId
return
}
示例6: UploadHeadImageFromReader
// UploadHeadImageFromReader 上传客服头像.
// NOTE: 参数 filename 不是文件路径, 是 multipart/form-data 里面 filename 的值.
func UploadHeadImageFromReader(clt *core.Client, kfAccount, filename string, reader io.Reader) (err error) {
// TODO
// incompleteURL := "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?kf_account=" +
// url.QueryEscape(kfAccount) + "&access_token="
incompleteURL := "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?kf_account=" +
kfAccount + "&access_token="
var fields = []core.MultipartFormField{{
IsFile: true,
Name: "media",
FileName: filename,
Value: reader,
}}
var result core.Error
if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result
return
}
return
}