/// <summary>
        /// 获取市民卡持卡人的个人信息
        /// </summary>
        /// <param name="verify"></param>
        /// <returns></returns>
        public static ApiResult <CitizenCardPerson> GetCitizenCardPerson(string cardNo, string webUrl)
        {
            if (string.IsNullOrEmpty(cardNo))
            {
                return(ApiResultHelper <CitizenCardPerson> .getFailApiResult("市民卡号码不能为空", null));
            }
            if (string.IsNullOrEmpty(webUrl))
            {
                return(ApiResultHelper <CitizenCardPerson> .getFailApiResult("没有找到管理后台地址,请检查配置文件", null));
            }

            var gateUrl = ApiHelper.GetTicketGateWayUrl(webUrl);

            if (string.IsNullOrEmpty(gateUrl))
            {
                return(ApiResultHelper <CitizenCardPerson> .getFailApiResult("没有找到前置网关地址", null));
            }

            var result = ApiHelper.SendDataToApiService <CitizenCardPerson>(
                string.Format("{0}citizencard/api/citizencard/getcitizencardperson?cardNo={1}"
                              , gateUrl, System.Uri.EscapeUriString(cardNo))
                , "GET", string.Empty);

            return(result);
        }
示例#2
0
        /// <summary>
        /// 发送数据到Api服务接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="apiUrl"></param>
        /// <param name="requestType"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static ApiResult <T> SendDataToApiService <T>(string apiUrl, string requestType, string param)
        {
            if (string.IsNullOrEmpty(apiUrl) || string.IsNullOrEmpty(requestType))
            {
                return(ApiResultHelper <T> .getFailApiResult("没有找到api接口地址", default(T)));
            }

            string          strJson  = string.Empty;
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;

            try
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                request = WebRequest.Create(apiUrl) as HttpWebRequest;
                //request.ProtocolVersion = HttpVersion.Version11;
                //request.AllowAutoRedirect = true;
                //request.KeepAlive = true;
                //request.Headers.Add("Accept-Language", "zh-cn");
                //request.Accept = "*/*";
                //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0;)";

                byte[] b = Encoding.UTF8.GetBytes(param);
                request.ContentType   = "application/json";
                request.ContentLength = b.Length;
                request.Method        = requestType;
                if (b.Length > 0)
                {
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(b, 0, b.Length);
                        stream.Close();
                    }
                }

                //获取服务器返回的资源
                using (response = request.GetResponse() as HttpWebResponse)                                                     //自动关闭和释放
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"))) //自动关闭和释放
                    {
                        strJson = reader.ReadToEnd();
                        reader.Close();
                    }
                }
                return(JsonConvert.DeserializeObject <ApiResult <T> >(strJson));
            }
            catch (Exception exception)
            {
                //new Common.LogHelper().WriteLine(exception.ToString());
                return(ApiResultHelper <T> .getFailApiResult(exception.Message, default(T)));
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }
        /// <summary>
        /// 大容山检票
        /// </summary>
        /// <param name="verify"></param>
        /// <returns></returns>
        public static ApiResult <selled_ticket> VerifyTicket(VerifyTicket verify, string webUrl)
        {
            if (verify == null)
            {
                return(ApiResultHelper <selled_ticket> .getFailApiResult("检票参数不正确", null));
            }
            if (string.IsNullOrEmpty(webUrl))
            {
                return(ApiResultHelper <selled_ticket> .getFailApiResult("没有找到管理后台地址,请检查配置文件", null));
            }

            var gateUrl = ApiHelper.GetTicketGateWayUrl(webUrl);

            if (string.IsNullOrEmpty(gateUrl))
            {
                return(ApiResultHelper <selled_ticket> .getFailApiResult("没有找到前置网关地址", null));
            }

            var result = ApiHelper.SendDataToApiService <selled_ticket>(
                string.Format("{0}verifyticket/api/verifyticket/verifyticket", gateUrl)
                , "POST", JsonConvert.SerializeObject(verify));

            return(result);
        }