public LastMoneyResult invoke(string url, object data = null)
 {
     if (string.IsNullOrEmpty(url))
     {
         return(ActionResult(2101, "url missing."));
     }
     if (url[0] != '/')
     {
         url = '/' + url;
     }
     try {
         string postUrl = string.Format("{0}://{1}:{2}/lastMoney{3}.api", _ssl ? "https" : "http", _host, _port, url);
         string json    = JSON.ToJSON(new { authCode = _authCode, data });
         string code    = null;
         using (Symbol.Net.Downloader downloader = new Symbol.Net.Downloader()) {
             downloader.Headers["Content-Type"] = "appliction/json";
             downloader.Encoding = System.Text.Encoding.UTF8;
             code = downloader.UploadString(postUrl, json);
         }
         return(ActionResult(JSON.ToObject <LastMoneyResult>(code)));
     } catch (System.Exception error) {
         return(ActionResult(1904, error.Message, error.StackTrace));
     }
 }
Example #2
0
        string GetPublicIP()
        {
            string url = _config.showIPUrl;

            if (string.IsNullOrEmpty(url))
            {
                Log?.Warning("get public ip : config.showIPUrl missing.");
                return(null);
            }
            Log?.Info($"get public ip from '{url}'");
            string html = null;

            try {
                using (Symbol.Net.Downloader downloader = new Symbol.Net.Downloader()) {
                    downloader.RetryCount = 0;
                    downloader.Encoding   = System.Text.Encoding.UTF8;
                    html = downloader.DownloadString(url);
                    Log?.Info($"get public ip response:{html}");
                    if (html != null && html.StartsWith("{"))
                    {
                        html = JSON.Parse(html).Path("ip").Convert <string>();
                    }
                }
            } catch (Exception error) {
                Log?.Error(error);
            }
            try {
                if (System.Net.IPAddress.Parse(html) != null)
                {
                    return(html);
                }
            } catch (Exception error) {
                Log?.Error(error);
            }
            return(null);
        }