Program.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Text.Json;
  2. using System.Text.RegularExpressions;
  3. namespace HelloWorld;
  4. class Program
  5. {
  6. static string[] EXTS = { ".txt", ".json",};
  7. static string PATTERN = "\'(.+)\':";
  8. static string IDPATTERN = "ObjectId\\(\"(.+)\"\\)";
  9. static void Main(string[] args)
  10. {
  11. BytePlusAuthTest();
  12. Console.WriteLine("Press any key...");
  13. Console.ReadLine();
  14. }
  15. private static string accessKey = "AKAPZGNkNGYzZmJiNGVmNDUxNjk0MDM5MmI4NDM5MmY5YmY";
  16. private static string secretKey = "WkRjNVpEVTBPVEkyTUdJeU5EUTFZems0TURFeU9UZGxOV1JsTURreFpEYw==";
  17. private static int expirationSeconds = 86400;
  18. private static void BytePlusAuthTest()
  19. {
  20. string method = "POST";
  21. // The requested path. Not a complete URL
  22. string uri = "/dataprofile/openapi/v1/751/users/185";
  23. var exampleQueryParams = new Dictionary<string, string>
  24. {
  25. { "set_once", "true" }
  26. };
  27. string exampleQueryBodyJson = "{\"name\":\"name\",\"value\":\"zhangsan\"}";
  28. string authorization = BytePlusAuthUtils.Sign(accessKey, secretKey, expirationSeconds,
  29. method, uri, exampleQueryParams, exampleQueryBodyJson);
  30. Console.WriteLine("authorization: " + authorization);
  31. }
  32. static void Test1(string[] args) {
  33. int idx = 0;
  34. foreach (var item in args)
  35. {
  36. Console.WriteLine($"{idx} - {item}");
  37. if (File.Exists(item)) {
  38. string ext = Path.GetExtension(item);
  39. if (EXTS.Contains(ext)) {
  40. string content = File.ReadAllText(item);
  41. content = Regex.Replace(content, PATTERN, "\"$1\":");
  42. content = Regex.Replace(content, IDPATTERN, "\"$1\"");
  43. if (content != null) {
  44. WrapperInfo? wrapper = JsonSerializer.Deserialize<WrapperInfo>(content);
  45. if (wrapper != null) {
  46. if (wrapper.Cn != null && wrapper.Cn.Length > 0) {
  47. wrapper.Cn = StringExtension.Decompress(wrapper.Cn);
  48. }
  49. if (wrapper.En != null && wrapper.En.Length > 0) {
  50. wrapper.En = StringExtension.Decompress(wrapper.En);
  51. }
  52. Console.WriteLine(wrapper.Cn);
  53. Console.WriteLine(wrapper.En);
  54. }
  55. }
  56. }
  57. }
  58. idx++;
  59. }
  60. }
  61. }