账户中心 退出系统
开发文档 资讯·分享 技术交流 会员登录
phpGrace GSCMS 公众号系统
自定义菜单操作

1 获取自定义菜单数据

利用 \phpGrace\tools\graceWeChat\menu 对象的 get() 函数可以获取公众号自定义菜单数据;
<?php
class indexController extends grace{
    public $graceWeChat;
    public function __construct(){
        parent::__construct();
        $this->graceWeChat                  = new \phpGrace\tools\graceWeChat();
    }
    public function index(){
        // 接收消息
        $this->graceWeChat->deBug = true;
        // 查询自定义菜单
        $menuObj = new \phpGrace\tools\graceWeChat\menu($this->graceWeChat);
        $menu    = $menuObj->get();
        $menu    = json_decode($menu);
        p($menu);
    }
}

2 创建自定义菜单

利用 \phpGrace\tools\graceWeChat\menu 对象的 create() 函数可以创建公众号自定义菜单;
官方手册  :
https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html
<?php
class indexController extends grace{
    public $graceWeChat;
    public function __construct(){
        parent::__construct();
        $this->graceWeChat                  = new \phpGrace\tools\graceWeChat();
    }
    public function index(){
        // 接收消息
        $this->graceWeChat->deBug = true;
        // 查询自定义菜单
        $menuObj = new \phpGrace\tools\graceWeChat\menu($this->graceWeChat);
        $menu = '
        {
            "button":
            [
                {    
                    "type":"click",
                    "name":"php编程",
                    "key":"KEY01"
                },
                {
                    "name":"html",
                    "sub_button":
                    [
                        {    
                           "type":"view",
                           "name":"网易",
                           "url":"http://www.163.com/"
                        },
                        {
                           "type":"view",
                           "name":"腾讯",
                           "url":"http://www.qq.com/"
                        }
                    ]
               },
               {
                    "name":"更多",
                    "sub_button":
                    [
                        {
                           "type":"view",
                        "name":"我的..",
                        "url":"http://wx.hcoder.net/demo/my.php"
                        },
                        {
                           "type":"view",
                        "name":"支付..",
                        "url":"http://wx.hcoder.net/demo/pay.php"
                        }
                    ]
               }
            ]
        }';
        $res = $menuObj->create($menu);
        p($res);
    }
}