WeixinUserInfoResult.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #region Apache License Version 2.0
  2. /*----------------------------------------------------------------
  3. Copyright 2019 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  5. except in compliance with the License. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software distributed under the
  8. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  9. either express or implied. See the License for the specific language governing permissions
  10. and limitations under the License.
  11. Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
  12. ----------------------------------------------------------------*/
  13. #endregion Apache License Version 2.0
  14. /*----------------------------------------------------------------
  15. Copyright (C) 2019 Senparc
  16. 文件名:WeixinUserInfoResult.cs
  17. 文件功能描述:获取用户信息返回结果
  18. 创建标识:Senparc - 20150211
  19. 修改标识:Senparc - 20150303
  20. 修改描述:整理接口
  21. 修改标识:Senparc - 20180305
  22. 修改描述: v14.10.4 WeixinUserInfoResult添加tagid_list属性(用户被打上的标签ID列表) 感谢@zhouxin9
  23. 修改标识:Senparc - 20181226
  24. 修改描述:v16.6.2 修改 DateTime 为 DateTimeOffset
  25. ----------------------------------------------------------------*/
  26. using Senparc.CO2NET.Helpers;
  27. using Senparc.Weixin.Entities;
  28. using Senparc.Weixin.Helpers;
  29. using System;
  30. namespace Senparc.Weixin.MP.Entities
  31. {
  32. /// <summary>
  33. /// 用户信息
  34. /// </summary>
  35. public class WeixinUserInfoResult : WxJsonResult
  36. {
  37. /// <summary>
  38. /// 用户是否订阅该公众号标识,值为0时,拉取不到其余信息
  39. /// </summary>
  40. public int subscribe { get; set; }
  41. /// <summary>
  42. /// 普通用户的标识,对当前公众号唯一
  43. /// </summary>
  44. public string openid { get; set; }
  45. /// <summary>
  46. /// 用户的昵称
  47. /// </summary>
  48. public string nickname { get; set; }
  49. /// <summary>
  50. /// 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
  51. /// </summary>
  52. public int sex { get; set; }
  53. /// <summary>
  54. /// 用户所在城市
  55. /// </summary>
  56. public string city { get; set; }
  57. /// <summary>
  58. /// 用户所在国家
  59. /// </summary>
  60. public string country { get; set; }
  61. /// <summary>
  62. /// 用户所在省份
  63. /// </summary>
  64. public string province { get; set; }
  65. /// <summary>
  66. /// 用户的语言,zh-CN 简体,zh-TW 繁体,en 英语,默认为zh-CN
  67. /// </summary>
  68. public string language { get; set; }
  69. /// <summary>
  70. /// <para>用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。</para>
  71. /// <para>示例:http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0 </para>
  72. /// </summary>
  73. public string headimgurl { get; set; }
  74. /// <summary>
  75. /// 获取指定大小的用户头像网址
  76. /// </summary>
  77. /// <param name="size">代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像)</param>
  78. /// <returns></returns>
  79. public string GetHeadImageUrl(int size = 0)
  80. {
  81. var url = headimgurl;
  82. if (url == null)
  83. return null;
  84. var tail = "/" + size.ToString("d");
  85. if (url.EndsWith(tail))
  86. return url;
  87. var slashIndex = url.LastIndexOf('/');
  88. if (slashIndex < 0)
  89. return url;
  90. return url.Substring(0, slashIndex) + tail;
  91. }
  92. /// <summary>
  93. /// 用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
  94. /// </summary>
  95. public long subscribe_time { get; set; }
  96. public DateTimeOffset GetSubscribeTime()
  97. {
  98. return DateTimeHelper.GetDateTimeFromXml(subscribe_time);
  99. }
  100. /// <summary>
  101. /// 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段
  102. /// </summary>
  103. public string unionid { get; set; }
  104. /// <summary>
  105. /// 公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
  106. /// </summary>
  107. public string remark { get; set; }
  108. /// <summary>
  109. /// 用户所在的分组ID
  110. /// </summary>
  111. public int groupid { get; set; }
  112. /// <summary>
  113. /// 用户被打上的标签ID列表
  114. /// </summary>
  115. public int[] tagid_list { get; set; }
  116. }
  117. }