关注作者的微信公众平台,测试效果

包含微信公众平台的所有功能(除微支付)

示例代码:(如需要全部代码,请加作者微信: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

posted on 2015-06-10 14:20  Devin程序园  阅读(2152)  评论(0编辑  收藏  举报