本文整理匯總了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
}