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

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

上一篇:微信新版支持读取iPhone M7/M8协处理器运动数据 与好友PK一下运动量吧


下一篇:微信支付的开发流程