Esempio n. 1
0
        private static T ApiGet <T>(string url, params string[] param) where T : Model.JsonResult
        {
            var result = HttpClientExtensions.GetString(ApiUrl(url, param)).DeserializeJsonString <T>();

            if (result != null && result.Success)
            {
                return(result);
            }
            throw result?.Error ?? new InvalidCastException("未知返回异常");
        }
Esempio n. 2
0
        private static JToken ApiJTokenGet(string url, params string[] param)
        {
            string result = HttpClientExtensions.GetString(ApiUrl(url, param));
            var    jr     = result.DeserializeJsonString <Model.JsonResult>();

            if (jr != null && jr.Success)
            {
                return(result.ParseToJToken());
            }
            throw jr?.Error ?? new InvalidCastException("未知返回异常");
        }
Esempio n. 3
0
            public static string GetUrl(string access_token, MediaType type, string media_id)
            {
                string url = ApiUrl("/cgi-bin/media/get?access_token={0}&media_id={1}", access_token, media_id);

                if (type == MediaType.News)
                {
                    throw new NotSupportedException("不能下载图文信息");
                }
                else if (type == MediaType.Video)
                {
                    url = HttpClientExtensions.GetString(url).ParseToJToken()["video_url"].ToString();
                }
                return(url);
            }