tp根据数据库动态创建微信菜单

tp根据数据库动态创建微信菜单

$button = array();
$class = M('ucenter_menu')->limit(3)->select();//取出顶级菜单
foreach ($class as $key => $vo) {
    $button[$key] = array('name'=>$vo['menu_name']);
    $c = M('ucenter_menu')->where(array('pid' => $vo['id']))->limit(5)->select();

    //拼接子菜单
    if ($c != false) {
        foreach ($c as $voo) {
            $button[$key]['sub_button'][] = array(
                'type'  => 'view',
                'name'  => $voo['menu_name'],
                'url'   => $voo['menu_url']
            );
        }
    } else {
        $button[$key]['type'] = 'view';
        $button[$key]['url'] = $vo['menu_url'];
    }
}

$data = compact('button');

$menu = new WeChat($options);
$s = $menu->createMenu($data);

if($s){
    $this->success("上线成功");
}else{
    $this->error("上线失败");
}

posted on 2016-12-13 15:01  跳动的汗水  阅读(258)  评论(0编辑  收藏  举报

导航