2016-08-10 9 views
0

私はUWPのためのアプリケーションを書く(C#の)WooCommerce UWP(C#の)

私はウェブサイト上で商業を懇願する接続する必要があります。

私はいくつかのコードを書き、間違いがあります。

メインは.csファイルでは、私はこのコードで、このコード

string ConsumerKey = "ck_f03bbd67e26a96604ddb188dbd63be3d252891ab"; 
     string ConsumerSecret = "cs_f8583f42dd1d75da832574b7ad6e649a0687f88f"; 
     string StoreUrl = "https://www.simplegames.com.ua"; 
     bool Isssl = true; 
     WoocommerceApiClient client2 = new WoocommerceApiClient(ConsumerKey, ConsumerSecret, StoreUrl, Isssl); 
     string orders = client2.GetProducts(); 

を書くには、すべて大丈夫です。

また、接続するクラスがあります。

クラスのコードです。

private static byte[] HashHMAC(byte[] key, byte[] message) 
    { 
     var hash = new HMACSHA256(key); 
     return hash.ComputeHash(message); 
    } 

    private string Hash(string input) 
    { 
     using (SHA1Managed sha1 = new SHA1Managed()) 
     { 
      var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input)); 
      var sb = new StringBuilder(hash.Length * 2); 

      foreach (byte b in hash) 
      { 
       // can be "x2" if you want lowercase 
       sb.Append(b.ToString("X2")); 
      } 

      return sb.ToString(); 
     } 
    } 

    public const string API_ENDPOINT = "wc-api/v1/"; 
    public string ApiUrl { get; set; } 
    public string ConsumerSecret { get; set; } 
    public string ConsumerKey { get; set; } 
    public bool IsSsl { get; set; } 

    public WoocommerceApiClient(string consumerKey, string consumerSecret, string storeUrl, bool isSsl = false) 
    { 
     if (string.IsNullOrEmpty(consumerKey) || string.IsNullOrEmpty(consumerSecret) || 
      string.IsNullOrEmpty(storeUrl)) 
     { 
      throw new ArgumentException("ConsumerKey, consumerSecret and storeUrl are required"); 
     } 
     this.ConsumerKey = consumerKey; 
     this.ConsumerSecret = consumerSecret; 
     this.ApiUrl = storeUrl.TrimEnd('/') + "/" + API_ENDPOINT; 
     this.IsSsl = isSsl; 
    } 

    public string GetAllProducts() 
    { 
     return MakeApiCall("products", new Dictionary<string, string>() { { "filter[limit]", "2000" } }); 
    } 
    public string GetProducts() 
    { 
     return MakeApiCall("products"); 
    } 

    private string MakeApiCall(string endpoint, Dictionary<string, string> parameters = null, string method = "GET") 
    { 
     if (parameters == null) 
     { 
      parameters = new Dictionary<string, string>(); 
     } 
     parameters["oauth_consumer_key"] = this.ConsumerKey; 
     parameters["oauth_timestamp"] = 
      DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds.ToString(); 
     parameters["oauth_timestamp"] = parameters["oauth_timestamp"].Substring(0, 
      parameters["oauth_timestamp"].IndexOf(".")); 
     parameters["oauth_nonce"] = Hash(parameters["oauth_timestamp"]); 
     parameters["oauth_signature_method"] = "HMAC-SHA256"; 
     parameters["oauth_signature"] = GenerateSignature(parameters, method, endpoint); 
     WebClient wc = new WebClient(); 
     StringBuilder sb = new StringBuilder(); 
     foreach (var pair in parameters) 
     { 
      sb.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(pair.Key), HttpUtility.UrlEncode(pair.Value)); 
     } 
     var url = this.ApiUrl + endpoint + "?" + sb.ToString().Substring(1).Replace("%5b", "%5B").Replace("%5d", "%5D"); 
     var result = wc.DownloadString(url); 
     return result; 
    } 

    private string GenerateSignature(Dictionary<string, string> parameters, string method, string endpoint) 
    { 
     var baserequesturi = Regex.Replace(HttpUtility.UrlEncode(this.ApiUrl + endpoint), "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper()); 
     var normalized = NormalizeParameters(parameters); 

     var signingstring = string.Format("{0}&{1}&{2}", method, baserequesturi, 
      string.Join("%26", normalized.OrderBy(x => x.Key).ToList().ConvertAll(x => x.Key + "%3D" + x.Value))); 
     var signature = 
      Convert.ToBase64String(HashHMAC(Encoding.UTF8.GetBytes(this.ConsumerSecret), 
       Encoding.UTF8.GetBytes(signingstring))); 
     Debug.WriteLine(signature); 
     return signature; 
    } 

    private Dictionary<string, string> NormalizeParameters(Dictionary<string, string> parameters) 
    { 
     var result = new Dictionary<string, string>(); 
     foreach (var pair in parameters) 
     { 
      var key = HttpUtility.UrlEncode(HttpUtility.UrlDecode(pair.Key)); 
      key = Regex.Replace(key, "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper()).Replace("%", "%25"); 
      var value = HttpUtility.UrlEncode(HttpUtility.UrlDecode(pair.Value)); 
      value = Regex.Replace(value, "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper()).Replace("%", "%25"); 
      result.Add(key, value); 
     } 
     return result; 
    } 

このエラーがあります。

1) 


    Severity Code Description Project File Line Suppression State 
Error CS0103 The name 'HttpUtility' does not exist in the current context Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 85 Active 

2)Severity Code Description Project File Line Suppression State Error CS1061 'List<KeyValuePair<string, string>>' does not contain a definition for 'ConvertAll' and no extension method 'ConvertAll' accepting a first argument of type 'List<KeyValuePair<string, string>>' could be found (are you missing a using directive or an assembly reference?) Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 98 Active

3) Severity Code Description Project File Line Suppression State 
Error CS0246 The type or namespace name 'HMACSHA256' could not be found (are you missing a using directive or an assembly reference?) Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 18 Active 

4) Severity Code Description Project File Line Suppression State 
Error CS0246 The type or namespace name 'SHA1Managed' could not be found (are you missing a using directive or an assembly reference?) Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 24 Active 

5)Severity Code Description Project File Line Suppression State 
Error CS0246 The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?) Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 81 Active 

6)Severity Code Description Project File Line Suppression State 
Error CS1579 foreach statement cannot operate on variables of type '?' because '?' does not contain a public definition for 'GetEnumerator' Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 29 Active 

ヘルプ私はこのエラーを修正してください。

ありがとうございました。私はそれがSystem.Net.WebUtility.HtmlEncode

でこのエラーの修正

1) 


    Severity Code Description Project File Line Suppression State 
Error CS0103 The name 'HttpUtility' does not exist in the current context Milano C:\Users\nemes\Documents\GitHub\Milano_pizza\Milano\WoocommerceApiClient.cs 85 Active 

を見つけたと思う

UPDATE

は、この権利ですか?

答えて

0

.Net暗号化APIは使用できなくなりました。あなたが​​を使用しCryptographicHashクラス

// Create a string that contains the name of the hashing algorithm to use. 
String strAlgName = HashAlgorithmNames.Sha512; 

// Create a HashAlgorithmProvider object. 
HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(strAlgName); 

// Create a CryptographicHash object. This object can be reused to continually 
// hash new messages. 
CryptographicHash objHash = objAlgProv.CreateHash(); 

// Hash message 1. 
String strMsg1 = "This is message 1."; 
IBuffer buffMsg1 = CryptographicBuffer.ConvertStringToBinary(strMsg1, BinaryStringEncoding.Utf16BE); 
objHash.Append(buffMsg1); 
IBuffer buffHash1 = objHash.GetValueAndReset(); 

を使用する必要があります、あなたが簡単にハッシュのバッファを変換することができ、必要なハッシュコードを生成するにはWindows.Security.Cryptography.Core

から入手WinRTのAPIに置き換えられていますbase64または16進文字列。

+0

私のクラスをどのように書き直す必要がありますか? –