Delphi XE7 用indy开发微信公众平台(7)- 用户管理

加我微信:Leedege一起交流Delphi开发经验


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;
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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Devin.Lee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值