• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

先定义数据类型:

unit rtcMW.Wechat.Types;

interface

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); // https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839 [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.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi代码优化发布时间:2022-07-18
下一篇:
delphi实现自动点击按钮发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap