file_prefix_info.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'dart:convert';
  2. import '../funcs.dart';
  3. class FilePrefixInfo {
  4. String name;
  5. String idCard;
  6. String mobile;
  7. int time;
  8. String area;
  9. String wifi;
  10. String userId;
  11. FilePrefixInfo({
  12. this.name = "",
  13. this.idCard = "",
  14. this.mobile = "",
  15. this.time = 0,
  16. this.area = "",
  17. this.wifi = "",
  18. this.userId = "",
  19. });
  20. ///编码
  21. String encode() {
  22. try {
  23. //内容可能太多了,导致录像时崩溃,所以去掉一些不重要的内容
  24. Map<String, dynamic> map = {
  25. "a": name,
  26. "b": idCard,
  27. //"c": mobile,
  28. //"d": time,
  29. "e": area,
  30. "f": wifi,
  31. "g": userId,
  32. };
  33. String str = jsonEncode(map);
  34. //base64里有/,会被认为是文件夹,所以用-替换掉
  35. str = aesEncrypt(str).replaceAll("/", "-");
  36. logd("编码文件前缀信息=$str");
  37. return str;
  38. } catch (e) {
  39. loge("编码文件前缀信息异常", error: e);
  40. }
  41. return "";
  42. }
  43. ///解码
  44. bool decode(String str) {
  45. if (str.isEmpty) {
  46. return false;
  47. }
  48. try {
  49. //base64里有/,会被认为是文件夹,所以用-替换掉
  50. str = str.replaceAll("-", "/");
  51. String decode = aesDecrypt(str);
  52. logd("decode=$decode");
  53. if (decode.isEmpty) {
  54. return false;
  55. }
  56. Map<String, dynamic> json = jsonDecode(decode);
  57. //兼容旧的key
  58. if (json.containsKey("name")) {
  59. name = json["name"];
  60. }
  61. if (json.containsKey("idCard")) {
  62. idCard = json["idCard"];
  63. }
  64. if (json.containsKey("mobile")) {
  65. mobile = json["mobile"];
  66. }
  67. if (json.containsKey("time")) {
  68. time = json["time"];
  69. }
  70. if (json.containsKey("area")) {
  71. area = json["area"];
  72. }
  73. if (json.containsKey("wifi")) {
  74. wifi = json["wifi"];
  75. }
  76. if (json.containsKey("userId")) {
  77. userId = json["userId"];
  78. }
  79. //使用新的key
  80. if (json.containsKey("a")) {
  81. name = json["a"];
  82. }
  83. if (json.containsKey("b")) {
  84. idCard = json["b"];
  85. }
  86. if (json.containsKey("c")) {
  87. mobile = json["c"];
  88. }
  89. if (json.containsKey("d")) {
  90. time = json["d"];
  91. }
  92. if (json.containsKey("e")) {
  93. area = json["e"];
  94. }
  95. if (json.containsKey("f")) {
  96. wifi = json["f"];
  97. }
  98. if (json.containsKey("g")) {
  99. userId = json["g"];
  100. }
  101. return true;
  102. } catch (e) {
  103. loge("解码文件前缀信息异常", error: e);
  104. }
  105. return false;
  106. }
  107. }