/// <summary>
        /// 青岛检票API请求
        /// </summary>
        /// <param name="verify"></param>
        /// <returns></returns>
        public static ApiResult_QD <VerifyTicketResult_QD> VerifyTicket_QD(VerifyTicket_QD verify, string webUrl, TokenStyle token)
        {
            if (verify == null)
            {
                return(ApiResultHelper_QD <VerifyTicketResult_QD> .getFailApiResult("检票参数不正确", null));
            }
            if (string.IsNullOrEmpty(webUrl))
            {
                return(ApiResultHelper_QD <VerifyTicketResult_QD> .getFailApiResult("没有找到管理后台地址,请检查配置文件", null));
            }
            var result = ApiHelper.SendDataToApiService_QD <VerifyTicketResult_QD>(
                string.Format("{0}/api/v1/VerifyTicket", webUrl), "POST", JsonConvert.SerializeObject(verify), token);

            return(result);
        }
        /// <summary>
        /// 青岛登录API请求
        /// </summary>
        /// <param name="verify"></param>
        /// <returns></returns>
        public static ApiResult_QD <AccountInfo> Login_QD(LoginInfo verify, string webUrl, TokenStyle token)
        {
            if (verify == null)
            {
                return(ApiResultHelper_QD <AccountInfo> .getFailApiResult("参数不正确", null));
            }
            if (string.IsNullOrEmpty(webUrl))
            {
                return(ApiResultHelper_QD <AccountInfo> .getFailApiResult("没有找到管理后台地址,请检查配置文件", null));
            }
            var result = ApiHelper.SendDataToApiService_QD <AccountInfo>(
                string.Format("{0}/api/v1/Accounts/login", webUrl), "POST", JsonConvert.SerializeObject(verify), token);

            return(result);
        }
Exemplo n.º 3
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_QD <T> SendDataToApiService_QD <T>(string apiUrl, string requestType, string param, TokenStyle token)
        {
            if (string.IsNullOrEmpty(apiUrl) || string.IsNullOrEmpty(requestType))
            {
                return(ApiResultHelper_QD <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.AllowWriteStreamBuffering = true;//
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
                //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);
                //Header中添加token验证(服务器要求)
                request.Headers.Add("Authorization", token.token_type + " " + token.access_token); //已有token添加入头
                request.ContentType   = "application/json";                                        //已有token使用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_QD <T> >(strJson));
            }
            catch (Exception exception)
            {
                //new Common.LogHelper().WriteLine(exception.ToString());
                return(ApiResultHelper_QD <T> .getFailApiResult(exception.Message, default(T)));
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }