Ejemplo n.º 1
0
        /// <summary>
        /// 请求艺龙接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        private static string RequestInterface <T>(T request, string method)
        {
            var requestContent = new BaseRequestEntity <T>()
            {
                Local = EnumLocal.zh_CN, Version = 1.22, Request = request
            };

            var str = JsonHelper.SerializeObject(requestContent);

            LogHelper.WriteLog("请求信息1:" + str, "ElongHotelInterface");
            DateTime now       = DateTime.Now;
            long     timestamp = ConvertDateTimeInt(now);
            string   sig       = MD5(timestamp + MD5(str + ApiGatewayConfig.APPKEY) + ApiGatewayConfig.SECRETKEY);

            StringBuilder sb = new StringBuilder();

            sb.Append("format=").Append("json").Append("&");
            sb.Append("method=").Append(method).Append("&");
            sb.Append("signature=").Append(sig).Append("&");
            sb.Append("user="******"&");
            sb.Append("timestamp=").Append(timestamp).Append("&");

            str = Uri.EscapeDataString(str);
            sb.Append("data=").Append(str);
            string url = string.Format(ApiGatewayConfig.URL_HTTPS, sb.ToString());

            LogHelper.WriteLog("请求信息2:" + url, "ElongHotelInterface");
            string res = GetHelper.GetUrl(url);

            LogHelper.WriteLog("响应信息:" + res, "ElongHotelInterface");
            return(res);
        }
Ejemplo n.º 2
0
        public static string GetToken()
        {
            var    timeStamp = GetTimeStamp();
            string tokenStr;

            if (AccesTokenTime != 0 && (timeStamp - AccesTokenTime) > 590 && (timeStamp - RefreshTokenTime) < 890)
            {
                tokenStr = GetHelper.GetUrl(ApiGatewayConfig.REFRESH_BASE_URL + "?AID="
                                            + ApiGatewayConfig.AID + "&SID=" + ApiGatewayConfig.SID
                                            + "&refresh_token=" + RefreshToken);
            }
            else
            {
                tokenStr = GetHelper.GetUrl(ApiGatewayConfig.TOKEN_BASE_URL + "?AID="
                                            + ApiGatewayConfig.AID + "&SID=" + ApiGatewayConfig.SID
                                            + "&KEY=" + ApiGatewayConfig.KEY);
            }
            ReturnToken rToken = JsonHelper.DeserializeJsonToObject <ReturnToken>(tokenStr);

            AccessToken      = rToken.Access_Token;
            RefreshToken     = rToken.Refresh_Token;
            AccesTokenTime   = timeStamp;
            RefreshTokenTime = timeStamp;
            return(AccessToken);
        }
Ejemplo n.º 3
0
        public static T GetStatic <T>(string url)
        {
            var res = GetHelper.GetUrl(url, "utf-8");

            res = res.Replace("\n", "");
            res = res.Replace("\r", "");
            //res = res.Replace("?><Result>", "?><ApiResult>");
            //res = res.Substring(0, res.Length - "/Result>".Length) + "/ApiResult>";
            res = Regex.Replace(res, "<\\w+/>", "");
            res = Regex.Replace(res, "<([^>]+)></\\1>", "");

            return(XmlDeserialize <T>(res));
        }