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("上线失败");
}

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

上一篇:Android支付开发(微信)


下一篇:升讯威微信营销系统开发实践:目录