Exemple #1
0
 private AccessToken GetAccessToken(string uri)
 {
     SocketHelper socket = new SocketHelper(new Uri(uri));
     string json = socket.Get(true);
     string[] kvs = json.Split(',');
     var acc = new AccessToken()
     {
         Token = kvs[0].Split(':')[1].Trim('"'),
         Expires = kvs[1].Split(':')[1].ToInt(),
         UID = kvs[2].Split(':')[1].TrimEnd('}').ToInt()
     };
     return acc;
 }
Exemple #2
0
        protected string Post(string shortUri, string data=null)
        {
            if (data == null)
            {
                data = string.Empty;
            }            
            data += string.Format("&access_token={0}&client_id={1}", access_token, app_key);
            data = data.Trim();

            SocketHelper socket = new SocketHelper(new Uri(api_host + shortUri));

            string result = socket.Post(data, true);

            return result;
        }
Exemple #3
0
        public BaseApi(string accessToken, string appKey)
        {
            access_token = accessToken;
            app_key = appKey;

            var curr = System.Web.HttpContext.Current;
            if (curr != null)
            {
                clientIP = curr.Request.UserHostAddress;
            }
            else
            {
                try
                {
                    SocketHelper socket = new SocketHelper(new Uri("http://iframe.ip138.com/ic.asp"));
                    string html = socket.Get(true);
                    clientIP = new Regex(@"\[([\d.]+?)\]").Match(html).Groups[1].Value;
                }
                catch
                {
                    clientIP = string.Empty;
                }
            }
        }