/// <summary> /// 传入MediaID,WeChatPublic /// </summary> public WeChatResult Download(MediaParam mediaParam) { var param = new HttpParam { { "access_token", Token.GetAccessToken(mediaParam) }, { "media_id", mediaParam.MediaID } }; var url = string.Format("{0}?{1}", ApiList.MediaGet, param.Format()); var request = HttpHelper.CreateRequest(url); var response = request.GetResponse(); using (var stream = response.GetResponseStream()) { var disposition = response.Headers["Content-disposition"]; if (string.IsNullOrEmpty(disposition)) { var s = new StreamReader(stream, Encoding.UTF8).ReadToEnd(); return(JsonConvert.DeserializeObject <WeChatResult>(s)); } var fs = new FileStream(mediaParam.FilePath, FileMode.OpenOrCreate); try { var buffer = new byte[128 * 1024]; //128K int i; while ((i = stream.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, i); } return(WeChatResult.GetSuccess(mediaParam.FilePath)); } finally { fs.Close(); } } }
/// <summary> /// /// </summary> public MenuException(WeChatResult result) : base(result) { }
/// <summary> /// /// </summary> public WxException(WeChatResult result) { ErrCode = result.ErrCode; ErrMsg = result.ErrMsg; }