Пример #1
0
        /// <summary>
        /// 请求语义理解
        /// </summary>
        /// <param name="userName">公众号</param>
        /// <param name="json">请求json数据</param>
        /// <returns>返回语义理解应答;如果请求失败,返回null。</returns>
        private static BaseReply Query(string userName, string json)
        {
            string responseContent = HttpHelper.RequestResponseContent(urlForQuerying, userName, null, httpMethodForQuerying, json);

            if (string.IsNullOrWhiteSpace(responseContent))
            {
                return(null);
            }
            else
            {
                return(BaseReply.ParseObject(JObject.Parse(responseContent)));
            }
        }
Пример #2
0
        internal static BaseReply ParseObject(JObject jo)
        {
            BaseReply reply = new BaseReply();

            reply.Parse(jo);
            if (reply.IsSuccess && reply.type.HasValue)
            {
                switch (reply.type.Value)
                {
                case ServiceTypeEnum.restaurant:
                    reply = Utility.Parse <RestaurantReply>(jo);
                    break;

                case ServiceTypeEnum.map:
                    reply = Utility.Parse <MapReply>(jo);
                    break;

                case ServiceTypeEnum.nearby:
                    reply = Utility.Parse <NearbyReply>(jo);
                    break;

                case ServiceTypeEnum.coupon:
                    reply = Utility.Parse <CouponReply>(jo);
                    break;

                case ServiceTypeEnum.hotel:
                    reply = Utility.Parse <HotelReply>(jo);
                    break;

                case ServiceTypeEnum.travel:
                    reply = Utility.Parse <TravelReply>(jo);
                    break;

                case ServiceTypeEnum.flight:
                    reply = Utility.Parse <FlightReply>(jo);
                    break;

                case ServiceTypeEnum.train:
                    reply = Utility.Parse <TrainReply>(jo);
                    break;

                case ServiceTypeEnum.movie:
                    reply = Utility.Parse <MovieReply>(jo);
                    break;

                case ServiceTypeEnum.music:
                    reply = Utility.Parse <MusicReply>(jo);
                    break;

                case ServiceTypeEnum.video:
                    reply = Utility.Parse <VideoReply>(jo);
                    break;

                case ServiceTypeEnum.novel:
                    reply = Utility.Parse <NovelReply>(jo);
                    break;

                case ServiceTypeEnum.weather:
                    reply = Utility.Parse <WeatherReply>(jo);
                    break;

                case ServiceTypeEnum.stock:
                    reply = Utility.Parse <StockReply>(jo);
                    break;

                case ServiceTypeEnum.remind:
                    reply = Utility.Parse <RemindReply>(jo);
                    break;

                case ServiceTypeEnum.telephone:
                    reply = Utility.Parse <TelephoneReply>(jo);
                    break;

                case ServiceTypeEnum.cookbook:
                    reply = Utility.Parse <CookbookReply>(jo);
                    break;

                case ServiceTypeEnum.baike:
                    reply = Utility.Parse <BaikeReply>(jo);
                    break;

                case ServiceTypeEnum.news:
                    reply = Utility.Parse <NewsReply>(jo);
                    break;

                case ServiceTypeEnum.tv:
                    reply = Utility.Parse <TvReply>(jo);
                    break;

                case ServiceTypeEnum.instruction:
                    reply = Utility.Parse <InstructionReply>(jo);
                    break;

                case ServiceTypeEnum.tv_instruction:
                    reply = Utility.Parse <TvInstructionReply>(jo);
                    break;

                case ServiceTypeEnum.car_instruction:
                    reply = Utility.Parse <CarInstructionReply>(jo);
                    break;

                case ServiceTypeEnum.app:
                    reply = Utility.Parse <AppReply>(jo);
                    break;

                case ServiceTypeEnum.website:
                    reply = Utility.Parse <WebsiteReply>(jo);
                    break;

                case ServiceTypeEnum.search:
                    reply = Utility.Parse <SearchReply>(jo);
                    break;
                }
            }
            return(reply);
        }