示例#1
0
文件: add.go 项目: Wang/wechat
func addFromReader(clt *mp.Client, filename string, reader io.Reader, _type string) (info ImageInfo, err error) {
	var result struct {
		mp.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 := []mp.MultipartFormField{{
		ContentType: 0,
		FieldName:   "media",
		FileName:    filename,
		Value:       reader,
	}}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	info = result.ImageInfo
	return
}
示例#2
0
文件: account.go 项目: Wang/wechat
// 上传客服头像.
//  注意参数 filename 不是文件路径, 是指定 multipart/form-data 里面文件名称
func uploadKfHeadImageFromReader(clt *mp.Client, kfAccount, filename string, reader io.Reader) (err error) {
	var result mp.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="
	fields := []mp.MultipartFormField{{
		ContentType: 0,
		FieldName:   "media",
		FileName:    filename,
		Value:       reader,
	}}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}