Пример #1
0
 public byte[] ConvertJSONToBytes(string json)
 {
     try {
         string url = ERPOldAPIAddress + "/ConvertJSONToBytes/JSON=" + json;
         if (checkURL(url))
         {
             using (DNWebClient webClient = new DNWebClient()) {
                 byte[] res1   = webClient.DownloadData(url);
                 string result = System.Text.Encoding.UTF8.GetString(res1);
                 if (!string.IsNullOrEmpty(result))
                 {
                     XmlDocument xdoc = new XmlDocument();
                     xdoc.LoadXml(result);
                     return(null);
                 }
                 return(null);
             }
         }
     } catch (Exception e) { }
     return(null);
 }
Пример #2
0
 public string GetToken()
 {
     if (!string.IsNullOrEmpty(_token))
     {
         return(_token);
     }
     try {
         if (string.IsNullOrEmpty(ERPOldAPIAddress) || string.IsNullOrEmpty(DNGlobalProperties.Current.ERPAPIMerchentId) || string.IsNullOrEmpty(DNGlobalProperties.Current.ERPAPIUserNumber) || string.IsNullOrEmpty(DNGlobalProperties.Current.ERPAPISecretKey))
         {
             return(_token);
         }
         var url = ERPOldAPIAddress + "/Authenticate/merchantid=" + DNGlobalProperties.Current.ERPAPIMerchentId + "&usernumber=" + DNGlobalProperties.Current.ERPAPIUserNumber + "&secretKey=" + DNGlobalProperties.Current.ERPAPISecretKey + "&format=xml";
         if (checkURL(url))
         {
             using (DNWebClient _myWebClient = new DNWebClient()) {
                 byte[]      res1   = _myWebClient.DownloadData(url);
                 string      result = System.Text.Encoding.UTF8.GetString(res1);
                 XmlDocument xdoc   = new XmlDocument();
                 xdoc.LoadXml(result);
                 XmlNodeList xnod  = xdoc.GetElementsByTagName("Api_key");
                 string      error = "";
                 error = xdoc.GetElementsByTagName("Error").Count > 0 ? xdoc.GetElementsByTagName("Error")[0].InnerText : "";
                 if (!string.IsNullOrWhiteSpace(error))
                 {
                     return(_token);
                 }
                 if (xnod.Count > 0)
                 {
                     if (!string.IsNullOrWhiteSpace(xnod[0].InnerText))
                     {
                         _token = xnod[0].InnerText;
                     }
                 }
             }
         }
     } catch (Exception) {
     }
     return(_token);
 }