// 上传图片 func (this *QQWeibo) Upload(status string, pic io.Reader) (rst *QQWeiboStatus, err error) { // multipart/form-data var bpic bytes.Buffer formdata := multipart.NewWriter(&bpic) formdata.WriteField("oauth_consumer_key", this.AppKey) formdata.WriteField("access_token", this.Token) formdata.WriteField("openid", this.OpenID) formdata.WriteField("clientip", util.GetIP()) formdata.WriteField("format", "json") formdata.WriteField("content", status) picdata, _ := formdata.CreateFormFile("pic", "image.png") io.Copy(picdata, pic) formdata.Close() res, err := http.Post(_TQQ_API_BASE+"add_pic", formdata.FormDataContentType(), &bpic) if err != nil { util.ERROR.Err("Error on call upload :", err) return } defer res.Body.Close() dst := &QQWeiboResult{} json.NewDecoder(res.Body).Decode(dst) if dst.Error != "" { util.ERROR.Err("Error on call upload (Remote):", dst.ErrorCode, ":", dst.Error) return nil, RemoteError(dst.Error) } rst = dst.Data return }
func (this *QQWeibo) postStatus(api string, args *url.Values) (rst *QQWeiboStatus, err error) { // OAuth required args.Set("oauth_consumer_key", this.AppKey) args.Set("access_token", this.Token) args.Set("openid", this.OpenID) args.Set("clientip", util.GetIP()) res, err := http.PostForm(_TQQ_API_BASE+"t/"+api, *args) if err != nil { util.ERROR.Errf("Error on call %s: %v", api, err) return } defer res.Body.Close() dst := &QQWeiboResult{} json.NewDecoder(res.Body).Decode(dst) if dst.Error != "" { util.ERROR.Errf("Error on call %s(Remote): %v : %v", api, dst.ErrorCode, dst.Error) return nil, RemoteError(dst.Error) } rst = dst.Data return }