/// <summary>
        /// <summary>
        /// 获取用户的openId
        /// <para>作    者:蔡亚康</para>
        /// <para>创建时间:2019-03-07</para>
        /// </summary>
        /// </summary>
        /// <param name="code">通过小程序获取到的用户登录凭证(有效期五分钟)。</param>
        /// <exception>
        /// 异常ID:4->OPENID获取失败
        /// </exception>
        /// <returns></returns>
        public OpenIdResponse GetOpenId(string code)
        {
            OpenIdResponse result = null;

            try
            {
                HssConfig config = ClientConfigManager.HssConfig;

                Dictionary <string, string> paras = new Dictionary <string, string>();
                paras.Add("appid", config.AppId);
                paras.Add("secret", config.AppSecret);
                paras.Add("js_code", code);
                paras.Add("grant_type", WxConfig.GRANT_TYPE);
                HttpClientRequest request = new HttpClientRequest();
                result = request.Get <OpenIdResponse>(config.JsCode2SessionUrl, paras);
                if (result.ErrCode != WxConfig.RESULT_SUCCESS)
                {
                    throw new BussinessException(ModelType.Hss, 4, result.ErrMsg);
                }
            }
            catch (Exception ex)
            {
                LogWriter.Write(this, ex.Message, LoggerType.Error);
                throw new BussinessException(ModelType.Hss, 4);
            }
            return(result);
        }
Exemple #2
0
        public async Task <MemberProfile> HandleAsync(GetMemberQuery query)
        {
            string url = $"{_memberApiUrl}/v2/members/{query.MemberId}/profile";

            var request = HttpClientRequest.Get(url);

            var response = await _http.ExecuteAsync <MemberProfile>(request);

            if (response != null && response.StatusCode == HttpStatusCode.OK && response.Result != null)
            {
                return(response.Result);
            }

            return(null);
        }
Exemple #3
0
        public async Task <Product> HandleAsync(ProductByIdQuery query)
        {
            var url = $"{_productUrl}/v1/products/{query.ProductId}";

            HttpClientRequest request = HttpClientRequest.Get(url);

            var response = await _httpClient.ExecuteAsync <Product>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(response.Result);
            }

            return(null);
        }
Exemple #4
0
        public async Task <List <Product> > HandleAsync(GetProductsQuery query)
        {
            var url = $"{_productUrl}/v1/products?service={query.Service}";

            var request = HttpClientRequest.Get(url);

            var response = await _http.ExecuteAsync <List <Product> >(request);

            if (response != null && response.StatusCode == HttpStatusCode.OK && response.Result != null)
            {
                return(response.Result);
            }

            return(null);
        }
Exemple #5
0
        public async Task <IEnumerable <Advert> > HandleAsync(AdvertsByMemberIdQuery query)
        {
            IEnumerable <Advert> advert = new List <Advert>();

            string url = $"{_advertApiUrl}/v2/adverts/{query.MemberId}";

            var request = HttpClientRequest.Get(url);

            var response = await _http.ExecuteAsync <List <Advert> >(request);


            if (response != null && response.StatusCode == HttpStatusCode.OK && response.Result != null)
            {
                advert = response.Result;
            }

            return(advert);
        }
Exemple #6
0
        public async Task <IHttpActionResult> GetNews()
        {
            HttpResponseMessage _json = await HttpClientRequest.Get <HttpResponseMessage>(new HttpClientOptions()
            {
                OutPutFormat = OutPutFormat.HttpResponse,
                URL          = new Uri(Url + "&" + NewsAPIKey)
            });

            string dataList = await _json.Content.ReadAsStringAsync();

            Models.NewsAPI newsList = JsonConvert.DeserializeObject <Models.NewsAPI>(dataList);
            return(GetJsonResult(new BaseResponse()
            {
                Message = "News saved successfully",
                ResponseObject = new MiddelLayer.NewsAPI().Insert(newsList.articles),
                StatusCode = 200
            }));
        }
Exemple #7
0
        public async Task InvokeAsync(PipelineContext context, PipelineDelegate next)
        {
            if (context.GetFirst(out Uri uri))
            {
                var response = await HttpClientRequest
                               .Get()
                               .Uri(uri)
                               .InvokeAsync();

                if (response.IsSuccessStatusCode)
                {
                    context.Add(response);
                    await next.Invoke();
                }
                ;
            }
            else
            {
                context.AddNotification(this, "No URI specified");
            }
        }