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


    用户管理

    原文链接:http://www.cnblogs.com/devinlee/p/4282701.html

    扫下方二维码关注,测试效果

    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;
  • 相关阅读:
    012_py之证书过期监测及域名使用的py列表的并集差集交集
    一些java的书籍
    java之内的工具分享,附带下载链接,方便以后自己寻找
    javascript的 == 与 === 的区别
    论httpclient上传带参数【commons-httpclient和apache httpclient区别】
    java操作小技巧,遇到过的会一直更新,方便查找
    常用jsp include用法,三种include的区别
    mybatis中的#和$的区别
    单例模式
    jQuery获取Select选择的Text和 Value(转)用时比较方便寻找
  • 原文地址:https://www.cnblogs.com/devinlee/p/4282701.html
Copyright © 2020-2023  润新知