Esempio n. 1
0
        public ResponseDto.Root?Call(int num = 10)
        {
            var body = new RequestDto()
            {
                Num = num,
                R18 = 2
            };
            var jsonSerializeSetting = new JsonSerializerSettings
            {
                NullValueHandling    = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore,
                ContractResolver     = new CamelCasePropertyNamesContractResolver()
            };

            string responseStr = null;

            using (var limiter = new LeakyBucketRateLimiter(nameof(SetuAPI), 1))
            {
                if (limiter.CanRequest())
                {
                    responseStr = WebHelper.HttpPost("https://api.lolicon.app/setu/v2", JsonConvert.SerializeObject(body, jsonSerializeSetting),
                                                     WebHelper.WebContentType.Json);
                }
            }

            return(responseStr == null ? null : JsonConvert.DeserializeObject <ResponseDto.Root>(responseStr, jsonSerializeSetting));
        }
Esempio n. 2
0
        /// <summary>
        /// 调用罗马音API
        /// </summary>
        /// <param name="japanese"></param>
        /// <returns></returns>
        public string CallAPI(string japanese)
        {
            if (japanese.IsNullOrWhiteSpace())
            {
                return(null);
            }
            string result;

            using (var limiter = new LeakyBucketRateLimiter(nameof(KouRomajiHelper), 1))
            {
                if (!limiter.CanRequest())
                {
                    this.InheritError(limiter, "发生在" + nameof(KouRomajiHelper) + "中的" + nameof(CallAPI));
                }
                string data = "mode=japanese&q=" + HttpUtility.UrlEncode(japanese);
                result = WebHelper.HttpPost("http://www.kawa.net/works/ajax/romanize/romanize.cgi ", data, WebHelper.WebContentType.General);
            }
            return(result);
        }
Esempio n. 3
0
        public Root CallAPI(string str)
        {
            if (str.IsNullOrWhiteSpace())
            {
                return(null);
            }
            string result;

            using (var limiter = new LeakyBucketRateLimiter(nameof(KouNbnhhsh), 2))
            {
                if (!limiter.CanRequest())
                {
                    this.InheritError(limiter, "发生在" + nameof(KouNbnhhsh) + "中的" + nameof(CallAPI));
                    return(null);
                }
                result = WebHelper.HttpPost("https://lab.magiconch.com/api/nbnhhsh/guess/", "{\"text\":\"" + str + "\"}", WebHelper.WebContentType.Json);
            }

            result = "{\"result\":" + result + "}";
            Root root = JsonConvert.DeserializeObject <Root>(result);

            return(root);
        }