all(); $userContext = $this->getUserContext(null); $param['user_id'] = $userContext['loginUser']->id; $param['puser_id'] = $userContext['loginUser']->pid; } public function add(WechatMenuRequest $request) { $param = $this->handelParam($request->validated()); } // 处理参数 private function handelParam($param) { $info = DB::table('miniprogram')->where('id', $param['miniprogram_id'])->first(); if (empty($info)) { WechatMenuService::throwErrMsg("小程序不正确"); } if ($info->status != 1) { WechatMenuService::throwErrMsg("此小程序暂不提供使用"); } if ($info->type != MiniprogramType::WEIXIN->value()) { WechatMenuService::throwErrMsg("关键词回复设置仅支持微信小程序"); } $param['miniprogram_appid'] = $info->appid; $info = DB::table('user_has_miniprograms')->where('uid', $this->getLoginUserId())->where('miniprogram_id', $param['miniprogram_id'])->where('is_enabled', 1)->value('id'); if (empty($info)) { WechatMenuService::throwErrMsg("没有此小程序的使用权限"); } $errs = ""; if (count($param['content']) >3){ WechatMenuService::throwErrMsg("底部菜单不能超过3个"); } $menus = []; foreach ($param['content'] as $val){ $temp = ['name' => $val['name']]; if (getProp($val,'sub_button')){ // 有二级菜单 if (count($val['sub_button']) > 5){ $errs .= getProp($val,'name')."的二级菜单超过5个"; continue ; } foreach ($val['sub_button'] as $sub){ $res = $this->checkMenuItem($sub); } }else{ // 一级菜单 $res = $this->checkMenuItem($sub); } } } private function checkMenuItem($sub) { $type = getProp($sub,'type'); if (!in_array($type,["click",'miniprogram','scancode_waitmsg'])){ return ['status' => 0,'msg' => "类型非法"]; } } public function test(){ $info = WechatOpenPlatformService::getAppInfoById(8); $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($info->component_appid); $openPlatform = WechatOpenPlatformService::buildApplication($componentInfo); $app = $openPlatform->officialAccount($info->authorizer_appid, getProp($info,'authorizer_refresh_token')); unset($appInfo); return $app->menu->list(); } }