1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Text.Json;
- using System.Text.RegularExpressions;
- namespace HelloWorld;
- class Program
- {
- static string[] EXTS = { ".txt", ".json",};
- static string PATTERN = "\'(.+)\':";
- static string IDPATTERN = "ObjectId\\(\"(.+)\"\\)";
- static void Main(string[] args)
- {
- BytePlusAuthTest();
- Console.WriteLine("Press any key...");
- Console.ReadLine();
- }
- private static string accessKey = "AKAPZGNkNGYzZmJiNGVmNDUxNjk0MDM5MmI4NDM5MmY5YmY";
- private static string secretKey = "WkRjNVpEVTBPVEkyTUdJeU5EUTFZems0TURFeU9UZGxOV1JsTURreFpEYw==";
- private static int expirationSeconds = 86400;
- private static void BytePlusAuthTest()
- {
- string method = "POST";
- // The requested path. Not a complete URL
- string uri = "/dataprofile/openapi/v1/751/users/185";
- var exampleQueryParams = new Dictionary<string, string>
- {
- { "set_once", "true" }
- };
- string exampleQueryBodyJson = "{\"name\":\"name\",\"value\":\"zhangsan\"}";
- string authorization = BytePlusAuthUtils.Sign(accessKey, secretKey, expirationSeconds,
- method, uri, exampleQueryParams, exampleQueryBodyJson);
- Console.WriteLine("authorization: " + authorization);
- }
- static void Test1(string[] args) {
- int idx = 0;
- foreach (var item in args)
- {
- Console.WriteLine($"{idx} - {item}");
- if (File.Exists(item)) {
- string ext = Path.GetExtension(item);
- if (EXTS.Contains(ext)) {
- string content = File.ReadAllText(item);
- content = Regex.Replace(content, PATTERN, "\"$1\":");
- content = Regex.Replace(content, IDPATTERN, "\"$1\"");
- if (content != null) {
- WrapperInfo? wrapper = JsonSerializer.Deserialize<WrapperInfo>(content);
- if (wrapper != null) {
- if (wrapper.Cn != null && wrapper.Cn.Length > 0) {
- wrapper.Cn = StringExtension.Decompress(wrapper.Cn);
- }
- if (wrapper.En != null && wrapper.En.Length > 0) {
- wrapper.En = StringExtension.Decompress(wrapper.En);
- }
- Console.WriteLine(wrapper.Cn);
- Console.WriteLine(wrapper.En);
- }
- }
- }
- }
- idx++;
- }
- }
- }
|