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: array of TJSONObject;
Url: String;
temp: String;
i: Integer;
readnum, ad: TStringList;
begin
J := TJSONObject.Create;
readnum := TStringList.Create;
ad := TStringList.Create;
ad.LoadFromFile(‘ad.txt‘);
SetLength(N, Num);
try
J.AddPair(‘articles‘, TJSONArray.Create);
with J.GetValue(‘articles‘) as TJSONArray do
for i := 0 to Num - 1 do
begin
temp := TNewsMsg(NewsList.Items[i]^).Content;

if TNewsMsg(NewsList.Items[i]^).AddTop then
temp := TNewsMsg(NewsList.Items[i]^).adTop + temp;

readnum.LoadFromFile(‘readnum.txt‘);
if TNewsMsg(NewsList.Items[i]^).RefreshReadNum then
readnum.Text := StringReplace(readnum.Text, ‘readNum‘,
TNewsMsg(NewsList.Items[i]^).readnum, [rfReplaceAll]);

if TNewsMsg(NewsList.Items[i]^).RefreshLikeNum then
readnum.Text := StringReplace(readnum.Text, ‘likeNum">‘,
TNewsMsg(NewsList.Items[i]^).LikeNum, [rfReplaceAll]);

if TNewsMsg(NewsList.Items[i]^).SourceURL ‘‘ then
readnum.Text := StringReplace(readnum.Text, ‘href=""‘,
Format(‘href="%s"‘, [TNewsMsg(NewsList.Items[i]^).SourceURL]),
[rfReplaceAll]);

temp := temp + readnum.Text;
readnum.Clear;
if TNewsMsg(NewsList.Items[i]^).AddBottom then
temp := temp + ad.Text + TNewsMsg(NewsList.Items[i]^).adBottom;

N[i] := TJSONObject.Create;
N[i].AddPair(‘thumb_media_id‘, UpMedia(AccessToken, ‘image‘,
TNewsMsg(NewsList.Items[i]^).CoverFile));
N[i].AddPair(‘author‘, TNewsMsg(NewsList.Items[i]^).Author);
N[i].AddPair(‘title‘, TNewsMsg(NewsList.Items[i]^).Title);
N[i].AddPair(‘content_source_url‘, ‘‘);
N[i].AddPair(‘content‘, temp);
N[i].AddPair(‘digest‘, TNewsMsg(NewsList.Items[i]^).Digest);
N[i].AddPair(‘show_cover_pic‘, TNewsMsg(NewsList.Items[i]^)
.ShowCover.ToString);
Add(N[i]);
temp := ‘‘;
end;
Url := Format(UpNewsUrl, [AccessToken]);
temp := PostMethod(Url, UTF8Encode(J.ToString), 1);
J := TJSONObject.ParseJSONValue(temp) as TJSONObject;
if J.Count > 0 then
Result := J.GetValue(‘media_id‘).Value;
finally
J.Free;
readnum.Free;
ad.Free;
end;
end;
复制代码
作者微信:Leedege

时间: 2024-12-26 04:25:00

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

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开发微信公众平台(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 R

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