微信公众平台——用户管理
微信公众平台——用户管理
用户管理包括获取用户基本信息、获取关注者列表、获取用户地理位置、用户分组管理。
1、获取用户列表
const FansListUrl = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s'; function GetOpenIDList(AccessToken, NextOpenID: String): TStringList; var Url: string; J: TJSONObject; O: TJSONArray; temp: String; begin Result := TStringList.Create; Url := Format(FansListUrl, [AccessToken, NextOpenID]); J := TJSONObject.ParseJSONValue(GetMethod(Url, 1)) as TJSONObject; try if J.Count > 0 then begin Total := J.GetValue('total').Value.ToInteger; Count := J.GetValue('count').Value.ToInteger; Next_OpenID := J.GetValue('next_openid').Value; J := J.GetValue('data') as TJSONObject; if J.Count > 0 then begin O := J.GetValue('openid') as TJSONArray; if O.Count > 0 then begin temp := O.ToString; delete(temp, 1, 1); delete(temp, Length(temp), 1); Result.DelimitedText := temp; end; end; end; finally J.Free; end; end;
2、获取用户信息
function UnixTime(DTime: TDateTime): longint; begin Result := Trunc((DTime - EncodeDate(1970, 1, 1)) * SecsPerDay); end; function DelphiTime(const USec: longint): TDateTime; begin Result := (USec / SecsPerDay) + EncodeDate(1970, 1, 1); end;
TFansInfo = record SubScribe:Byte; OpenID:String; NickName:String; Sex:Byte; City:String; Province:String; Cuntry:String; Language:String; HeadImgUrl:String; SubScribeTime:TDateTime; Remark:String; end; const FansInfoUrl = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN'; function GetFansInfo(OpenID: String): TFansInfo; var Url: string; J: TJSONObject; begin Url := Format(FansInfoUrl, [Access_Token, OpenID]); J := TJSONObject.ParseJSONValue(GetMethod(Url, 1)) as TJSONObject; try if J.Count > 0 then begin Result.SubScribe := J.GetValue('subscribe').Value.ToInteger; Result.OpenID := J.GetValue('openid').Value; Result.NickName := J.GetValue('nickname').Value; Result.Sex := J.GetValue('sex').Value.ToInteger; Result.City := J.GetValue('city').Value; Result.Province := J.GetValue('province').Value; Result.Cuntry := J.GetValue('country').Value; Result.Language := J.GetValue('language').Value; Result.HeadImgUrl := J.GetValue('headimgurl').Value; Result.SubScribeTime := DelphiTime(J.GetValue('subscribe_time') .Value.ToInteger); Result.Remark := J.GetValue('remark').Value; end; finally J.Free; end; end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/8987613.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?