function m__menu_sync() { $menu = menu_list(); $menu_post = array(); foreach ($menu as $a => $b) { $tmpa = array(); $tmpa['name'] = $b['menu_name']; if (count($b['son']) > 0) { $tmpa['sub_button'] = array(); foreach ($b['son'] as $k => $v) { $tmpb = array(); $tmpb['name'] = $v['menu_name']; $tmpb['type'] = $v['menu_type']; if ($v['menu_type'] == 'click') { $tmpb['key'] = $v['menu_key']; } else { $tmpb['url'] = $v['menu_url']; } array_push($tmpa['sub_button'], $tmpb); } } else { $tmpa['type'] = $b['menu_type']; if ($b['menu_type'] == 'click') { $tmpa['key'] = $b['menu_key']; } else { $tmpa['url'] = $b['menu_url']; } } array_push($menu_post, $tmpa); } $post_data = array('button' => $menu_post); $json = helper::json_encode_ch($post_data); //die('1'.$json); $wx = new weixin(); $ret = $wx->menu_create($json); if ($ret['errcode'] == '0') { die('{"code":"0","msg":"同步成功"}'); } else { die('{"code":"' . $ret['errcode'] . '","msg":"同步失败:' . $ret['errmsg'] . ',请重试"}' . $post_data); } }