public function updateMenu() { import('Org.Wechat.wechat'); $wechat = new Wechat(array('token' => C('WECHAT_TOKEN'), 'encodingaeskey' => C('WECHAT_AES_KEY'), 'appid' => C('WECHAT_APPID'), 'appsecret' => C('WECHAT_APPSECRET'))); if (IS_POST) { $menu = D('Menu')->getMenu(); $result = array(); foreach ($menu as &$val) { $temp = $this->toMenu($val); $sub_menu = D('Menu')->getMenu($val['id']); if (isset($sub_menu[0])) { $t = array(); foreach ($sub_menu as &$sub) { $t[] = $this->toMenu($sub); } $temp['sub_button'] = $t; unset($t); } $result['button'][] = $temp; unset($temp); } $wechat->createMenu($result); } $msg = $wechat->errMsg; if ($msg == 'no access') { $msg = ''; } $this->ajaxReturn(array('msg' => $msg)); }