/// <summary> /// 向微信公众平台API发送信息的公共方法 /// </summary> /// <param name="urlFormat">API接口地址格式</param> /// <param name="accessToken">微信公众号访问授权AccessToken</param> /// <param name="data">POST提交的数据</param> /// <param name="querys">除了AccessToken还需要传递的其他参数</param> /// <returns></returns> public static T Post <T>(string accessToken, string urlFormat, object data, params string[] querys) { var url = GetApiUrl(urlFormat, accessToken, querys); SerializerHelper serializerHelper = new SerializerHelper(); var jsonString = serializerHelper.GetJsonString(data); using (MemoryStream ms = new MemoryStream()) { var bytes = Encoding.UTF8.GetBytes(jsonString); ms.Write(bytes, 0, bytes.Length); ms.Seek(0, SeekOrigin.Begin); string result = RequestUtility.HttpPost(url, ms, null); return(GetResult <T>(result)); } }
/// <summary> /// 下载文件 /// </summary> /// <param name="urlFormat">API接口地址格式</param> /// <param name="stream">下载的文件流信息</param> /// <param name="querys">需要传递的参数</param> public static void DownloadGet(string urlFormat, Stream stream, params string[] querys) { RequestUtility.DownloadGet(string.Format(urlFormat, querys), stream); }