Delphi 开发微信公众平台 (一)- 定义数据结构


unit rtcMW.Wechat.Types;


uses Generics.Collections, Rest.Json, System.Json.SerializeHelper, System.Json.Types, System.Json.Serializers;

type TWechatTag = class Id: Integer; Name: string; Count: Integer; end; TWechatIndustryInfo = record public [JsonName('first_class')] FirstClass: string; [JsonName('second_class')] SecondClass: string; end; TWechatIndustryItem = record public [JsonName('primary_industry')] PrimaryIndustry: TWechatIndustryInfo; [JsonName('secondary_industry')] SecondaryIndustry: TWechatIndustryInfo; end; TWechatArticle = record public [JsonName('title')] Title: string; [JsonName('description')] Description: string; [JsonName('url')] URL: string; [JsonName('picurl')] PicURL: string; end; TWechatTags = TArray<TWechatTag>; TWechatIPList = TArray<string>; TWechatOpenIdList = TArray<string>; TWechatQRCodeType = (QR_SCENE, QR_LIMIT_SCENE); TWechatBlacklistAction = (baAdd, baRemove); TWechatTagAction = (taAdd, taRemove); TWechatHeadImageSize = (hi46, hi64, hi96, hi132, hi640); TWechatMediaType = (mtImage, mtVoice, mtVideo, mtThumb); TWechatMessageType = (mtCustomMessage, mtTemplateMessage); TWechatUser = class; TWechatUsers = TArray<TWechatUser>; TWechatUserType = (utNormal, utBlocked); // [JsonSerialize(TJsonMemberSerialization.&Public)] TWechatUser = class private FCountry: string; FCity: string; FProvince: string; FGroupID: Integer; FGropName: string; FHeadimgURL: string; FLanguage: string; FName: string; FOpenid: string; FQRScene: Integer; FQRSceneStr: string; FRemark: string; FSex: Integer; FSubscribe: Integer; FSubscribeScene: string; FSubscribeTime: int64; FTagidList: TArray<Integer>; FUnionID: string; FAccountID: int64; FUserid: int64; FBlocked: Byte; public [JsonName('country')] property Country: string read FCountry write FCountry; [JsonName('province')] property Province: string read FProvince write FProvince; [JsonName('city')] property City: string read FCity write FCity; [JsonName('groupid')] property GroupID: Integer read FGroupID write FGroupID; [JsonName('headimgurl')] property HeadimgURL: string read FHeadimgURL write FHeadimgURL; [JsonName('language')] property Language: string read FLanguage write FLanguage; [JsonName('nickname')] property NickName: string read FName write FName; [JsonName('openid')] property OpenID: String read FOpenid write FOpenid; [JsonName('qr_scene')] property QRScene: Integer read FQRScene write FQRScene; [JsonName('qr_scene_str')] property QRSceneStr: string read FQRSceneStr write FQRSceneStr; [JsonName('remark')] property Remark: string read FRemark write FRemark; [JsonName('sex')] property Sex: Integer read FSex write FSex; [JsonName('subscribe')] property Subscribe: Integer read FSubscribe write FSubscribe; [JsonName('subscribe_scene')] property SubscribeScene: String read FSubscribeScene write FSubscribeScene; [JsonName('subscribe_time')] property SubscribeTime: int64 read FSubscribeTime write FSubscribeTime; [JsonName('tagid_list')] property TagIDList: TArray<Integer> read FTagidList write FTagidList; [JsonName('unionid')] property UnionID: string read FUnionID write FUnionID; [JsonName('account_id')] property AccountID: int64 read FAccountID write FAccountID; [JsonName('userid')] property UserID: int64 read FUserid write FUserid; [JsonName('blocked')] property Blocked: Byte read FBlocked write FBlocked; [JsonName('group_name')] property GroupName: string read FGropName write FGropName; function ToJsonString: string; class function FromJsonString(const AJsonString: string): TWechatUser; end; TWechatAccount = class; TWechatAccounts = TArray<TWechatAccount>; [JsonSerialize(TJsonMemberSerialization.&Public)] TWechatAccount = class private FAccountID: int64; FAppid: string; FAppsecret: string; FToken: string; FEncodingAESKey: string; FPrimaryIndustryID: Integer; FSecondaryIndustryID: Integer; FWechatID: string; FName: string; FServer: string; FExpireTime: TDateTime; FModified: TDateTime; FAccessToken: string; FRemark: string; FAvailable: Byte; public [JsonName('account_id')] property AccountID: int64 read FAccountID write FAccountID; [JsonName('appid')] property AppId: String read FAppid write FAppid; [JsonName('appsecret')] property Appsecret: String read FAppsecret write FAppsecret; [JsonName('token')] property Token: String read FToken write FToken; [JsonName('aes_key')] property AESKey: String read FEncodingAESKey write FEncodingAESKey; [JsonName('access_token')] property AccessToken: String read FAccessToken write FAccessToken; [JsonName('wechat_id')] property WechatID: String read FWechatID write FWechatID; [JsonName('name')] property Name: String read FName write FName; [JsonName('server')] property Server: String read FServer write FServer; [JsonName('modified')] property Modified: TDateTime read FModified write FModified; [JsonName('expire_time')] property ExpireTime: TDateTime read FExpireTime write FExpireTime; [JsonName('remark')] property Remark: String read FRemark write FRemark; [JsonName('primary_industry_id')] property PrimaryIndustryID: Integer read FPrimaryIndustryID write FPrimaryIndustryID; [JsonName('secondary_industry_id')] property SecondaryIndustryID: Integer read FSecondaryIndustryID write FSecondaryIndustryID; property Available: Byte read FAvailable write FAvailable; function ToJsonString: string; class function FromJsonString(const AJsonString: string): TWechatAccount; end; TWechatTemplate = class; TWechatTemplates = TArray<TWechatTemplate>; [JsonSerialize(TJsonMemberSerialization.&Public)] TWechatTemplate = class private FContent: string; FDeputyIndustry: string; FExample: string; FPrimaryIndustry: string; FTemplateId: string; FTitle: string; public [JsonName('content')] property Content: String read FContent write FContent; [JsonName('deputy_industry')] property DeputyIndustry: String read FDeputyIndustry write FDeputyIndustry; [JsonName('example')] property Example: String read FExample write FExample; [JsonName('primary_industry')] property PrimaryIndustry: String read FPrimaryIndustry write FPrimaryIndustry; [JsonName('template_id')] property Id: String read FTemplateId write FTemplateId; [JsonName('title')] property Title: String read FTitle write FTitle; function ToJsonString: string; class function FromJsonString(const AJsonString: string): TWechatTemplate; end; const MediaTypeNames: array [TWechatMediaType] of string = ('image', 'voice', 'video', 'thumb'); SubscribeNames: array [0 .. 1] of string = ('未订阅', '已订阅'); SexNames: array [0 .. 2] of string = ('未知', '', ''); implementation { TWechatUser } function TWechatUser.ToJsonString: string; begin Result := TJson.Object2Json<TWechatUser>(Self); end; class function TWechatUser.FromJsonString(const AJsonString: string): TWechatUser; begin Result := TJson.Json2Object<TWechatUser>(AJsonString); end; { TWechatAccount } class function TWechatAccount.FromJsonString(const AJsonString: string): TWechatAccount; begin Result := TJson.Json2Object<TWechatAccount>(AJsonString); end; function TWechatAccount.ToJsonString: string; begin Result := TJson.Object2Json<TWechatAccount>(Self); end; { TWechatTemplate } function TWechatTemplate.ToJsonString: string; begin Result := TJson.Object2Json<TWechatTemplate>(Self); end; class function TWechatTemplate.FromJsonString(const AJsonString: string): TWechatTemplate; begin Result := TJson.Json2Object<TWechatTemplate>(AJsonString); end; end.

posted @ 2019-05-06 10:28 塞翁失身 阅读(...) 评论(...) 编辑 收藏