tencent_api_resp.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import 'dart:convert';
  2. import 'package:json_annotation/json_annotation.dart';
  3. part 'tencent_api_resp.g.dart';
  4. abstract class TencentApiResp {
  5. const TencentApiResp({
  6. required this.ret,
  7. this.msg,
  8. });
  9. /// 网络请求成功发送至服务器,并且服务器返回数据格式正确
  10. /// 这里包括所请求业务操作失败的情况,例如没有授权等原因导致
  11. static const int RET_SUCCESS = 0;
  12. @JsonKey(
  13. defaultValue: RET_SUCCESS,
  14. )
  15. final int ret;
  16. final String? msg;
  17. bool get isSuccessful => ret == RET_SUCCESS;
  18. Map<String, dynamic> toJson();
  19. @override
  20. String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
  21. }
  22. @JsonSerializable(
  23. explicitToJson: true,
  24. fieldRename: FieldRename.snake,
  25. )
  26. class TencentUserInfoResp extends TencentApiResp {
  27. const TencentUserInfoResp({
  28. required int ret,
  29. String? msg,
  30. this.isLost,
  31. this.nickname,
  32. this.gender,
  33. this.genderType,
  34. this.province,
  35. this.city,
  36. this.year,
  37. this.constellation,
  38. this.figureurl,
  39. this.figureurl1,
  40. this.figureurl2,
  41. this.figureurlQq,
  42. this.figureurlQq1,
  43. this.figureurlQq2,
  44. this.figureurlType,
  45. this.isYellowVip,
  46. this.vip,
  47. this.yellowVipLevel,
  48. this.level,
  49. this.isYellowYearVip,
  50. }) : super(ret: ret, msg: msg);
  51. factory TencentUserInfoResp.fromJson(Map<String, dynamic> json) =>
  52. _$TencentUserInfoRespFromJson(json);
  53. final int? isLost;
  54. final String? nickname;
  55. final String? gender; // 男/女
  56. final int? genderType; // 男/女 - 1
  57. final String? province;
  58. final String? city;
  59. final String? year;
  60. final String? constellation;
  61. final String? figureurl;
  62. @JsonKey(
  63. name: 'figureurl_1',
  64. )
  65. final String? figureurl1;
  66. @JsonKey(
  67. name: 'figureurl_2',
  68. )
  69. final String? figureurl2;
  70. final String? figureurlQq; // 140 * 140
  71. @JsonKey(
  72. name: 'figureurl_qq_1',
  73. )
  74. final String? figureurlQq1; // 大小为40×40像素的QQ头像URL。
  75. @JsonKey(
  76. name: 'figureurl_qq_2',
  77. )
  78. final String?
  79. figureurlQq2; // 大小为100×100像素的QQ头像URL。需要注意,不是所有的用户都拥有QQ的100x100的头像,但40x40像素则是一定会有。
  80. final String? figureurlType;
  81. final String? isYellowVip;
  82. final String? vip;
  83. final String? yellowVipLevel;
  84. final String? level;
  85. final String? isYellowYearVip;
  86. bool get isMale => gender == '男';
  87. bool get isFemale => gender == '女';
  88. String? get headImgUrl {
  89. if (figureurlQq?.isNotEmpty ?? false) {
  90. return figureurlQq;
  91. }
  92. if (figureurlQq2?.isNotEmpty ?? false) {
  93. return figureurlQq2;
  94. }
  95. if (figureurlQq1?.isNotEmpty ?? false) {
  96. return figureurlQq1;
  97. }
  98. if (figureurl2?.isNotEmpty ?? false) {
  99. return figureurl2;
  100. }
  101. if (figureurl1?.isNotEmpty ?? false) {
  102. return figureurl1;
  103. }
  104. return figureurl;
  105. }
  106. @override
  107. Map<String, dynamic> toJson() => _$TencentUserInfoRespToJson(this);
  108. }