微信公众号开发,获取用户基本信息可通过以下api获取:
http请求方式: GET https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
返回数据:
{
"subscribe": 1,
"openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
"nickname": "Band",
"sex": 1,
"language": "zh_CN",
"city": "广州",
"province": "广东",
"country": "中国",
"headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4
eMsv84eavHiaiceqxibJxCfHe/0",
"subscribe_time": 1382694957,
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
"remark": "",
"groupid": 0,
"tagid_list":
}
其中subscribe_time为用户关注公众号时间,注意:单位为秒,不是毫秒,要转换为毫秒要乘以1000,这个官网开发文档没有说明。
转换为datetime方法,这里用C#
/// <summary>
/// 时间戳转换为datetime
/// </summary>
/// <param name="timeStamp">微信接口返回时间戳</param>
/// <returns></returns>
private DateTime GetDateTimeWithTimeStamp(long timeStamp)
{
timeStamp=timeStamp*1000;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
DateTime dt = startTime.AddMilliseconds(timeStamp);
return dt;
}