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

用户管理

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、获取用户信息

  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;

原文地址:http://www.cnblogs.com/devinlee/p/4282701.html

时间: 2024-10-12 19:35:34

Delphi XE7 用indy开发微信公众平台(7)- 用户管理的相关文章

Delphi XE7 用indy开发微信公众平台所有功能,可刷阅读,可刷赞,可加推广(除微支付)

http://www.cnblogs.com/devinlee/p/4565933.html Delphi XE7 用indy开发微信公众平台所有功能,可刷阅读,可刷赞,可加推广(除微支付) 关注作者的微信公众平台,测试效果 包含微信公众平台的所有功能(除微支付) 示例代码:(如需要全部代码,请加作者微信:Leedege) 复制代码 function UpNews(Num: Integer; AccessToken: String): String; var J: TJSONObject; N:

Delphi XE7 用indy开发微信公众平台(2)- 获取微信服务器IP地址

获取微信服务器IP地址 const ServerIpUrl = 'https://api.weixin.qq.com/cgi-bin/getcallbackip?&access_token=%s'; procedure GetServerList(out List: TStringList; AccessToken: String); var Url: string; J: TJSONObject; temp: String; begin Url := Format(ServerIpUrl, [

Delphi XE7 用indy开发微信公众平台(4)- 接收事件推送

接收事件推送 type TEventType = (subscribe, unsubscribe, SCAN, LOCATION, CLICK, VIEW); function ResponseEvent(M: TMessage; X: IXMLDocument): RawByteString; var event: TEventType; temp, menu: String; begin temp := X.DocumentElement.ChildNodes.Nodes['Event'].

Delphi XE7 用indy开发微信公众平台(4)- 接收普通消息

接收普通消息 type TMsgType = (event, text, image, voice, video, location, link); TMessage = Record ToUserName: String; FromUserName: String; CreateTime: Integer; MsgType: String; end; uses System.SysUtils, System.JSON, TypInfo, Xml.XMLIntf, Xml.XMLDoc, Act

Delphi XE7 用indy开发微信公众平台(6)- 被动回复用户消息

被动回复用户消息 1.回复文本消息 function ReplyText(Msg: TMessage; MsgText: String): RawByteString; var X: IXMLDocument; begin X := NewXMLDocument; try X.Xml.text := TextMsg; X.Active := true; with X.DocumentElement.ChildNodes do begin Nodes['ToUserName'].NodeValue

Delphi XE7 用indy开发微信公众平台(8)- 自定义菜单

自定义菜单创建接口 1.创建菜单 const CreateMenuUrl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s'; function CreateMenus(AccessToken: String): TJSONObject; var Url: string; J: TJSONObject; m1: TJSONObject; m2, m21, m22: TJSONObject; m3, m31, m32,

Delphi XE7 用indy开发微信公众平台(9)- 高级群发接口

高级群发接口 1.上传多媒体文件(这里以上传图片为例) uses IdMultipartFormData; const UpMediaUrl = 'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s'; function UpMedia(AccessToken, MediaType, MediaFile: String): String; var J: TJSONObject; Url: Strin

Delphi XE7 用indy开发微信公众平台(3)- 验证消息真实性

验证消息真实性 uses IdHashSHA, IdGlobal; function SHA1(Input: String): String; begin with TIdHashSHA1.Create do try Result := LowerCase(HashBytesAsHex(TidBytes(Bytesof(Input)))); finally Free; end; end; function CheckSignature(ARequestInfo: TIdHTTPRequestIn

Delphi XE7 用indy开发微信公众平台(1)- 获取access_token、expires_in

获取access_token.expires_in function GetMethod(HTTP: TIdHTTP; Url: String; Max: Integer): String; var RespData: TStringStream; begin RespData := TStringStream.Create('', TEncoding.UTF8); try try HTTP.Get(Url, RespData); HTTP.Request.Referer := Url; Res