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, m33: TJSONObject;
  temp: RawByteString;
begin
  J := TJSONObject.Create;
  try
    Url := Format(CreateMenuUrl, [AccessToken]);
    J.AddPair(‘button‘, TJSONArray.Create);
    with J.GetValue(‘button‘) as TJSONArray do
    begin
      m1 := TJSONObject.Create;
      m1.AddPair(‘type‘, ‘view‘);
      m1.AddPair(‘name‘, ‘微商城‘);
      m1.AddPair(‘url‘, ‘http://wd.koudai.com/?userid=169004500‘);
      Add(m1);

      m2 := TJSONObject.Create;
      m2.AddPair(‘name‘, ‘微会员‘);
      m2.AddPair(‘sub_button‘, TJSONArray.Create);
      with m2.GetValue(‘sub_button‘) as TJSONArray do
      begin
        m21 := TJSONObject.Create;
        m21.AddPair(‘type‘, ‘click‘);
        m21.AddPair(‘name‘, ‘每日签到‘);
        m21.AddPair(‘key‘, ‘m21‘);
        add(m21);

        m22 := TJSONObject.Create;
        m22.AddPair(‘type‘, ‘click‘);
        m22.AddPair(‘name‘, ‘查询积分‘);
        m22.AddPair(‘key‘, ‘m22‘);
        add(m22);
      end;
      Add(m2);

      m3 := TJSONObject.Create;
      m3.AddPair(‘name‘, ‘微服务‘);
      m3.AddPair(‘sub_button‘, TJSONArray.Create);
      with m3.GetValue(‘sub_button‘) as TJSONArray do
      begin
        m31 := TJSONObject.Create;
        m31.AddPair(‘type‘, ‘view‘);
        m31.AddPair(‘name‘, ‘买彩票‘);
        m31.AddPair(‘url‘,
          ‘http://tc.w-caipiao.tenpay.com/m_wx/index.html?showwxpaytitle=1&vb2ctag=4_2062_3_1915‘);
        add(m31);

        m32 := TJSONObject.Create;
        m32.AddPair(‘type‘, ‘view‘);
        m32.AddPair(‘name‘, ‘充话费‘);
        m32.AddPair(‘url‘,
          ‘http://chong.qq.com/mobile/wt_index.shtml#logic.wx.wt.recharge.mobile=mobileRecharge‘);
        add(m32);

        m33 := TJSONObject.Create;
        m33.AddPair(‘type‘, ‘click‘);
        m33.AddPair(‘name‘, ‘听音乐‘);
        m33.AddPair(‘key‘, ‘m33‘);
        add(m33);
      end;
      Add(m3);
    end;
    temp := PostMethod(Url, UTF8Encode(J.ToString), 1);
    Result := TJSONObject.ParseJSONValue(temp) as TJSONObject;
  finally
    J.Free;
  end;
end;

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

时间: 2024-10-12 15:51:57

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

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