addOption('user_id','u', InputArgument::OPTIONAL, 'user_id'); $this->addOption('action','a', InputArgument::OPTIONAL, '操作类型'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { $action = $input->getOption('action','login'); if($action == 'login'){ $IM = new \support\OpenImSdk\Client([ 'host' => 'http://127.0.0.1:10002', // OpenIM API地址 'secret' => 'n1e5a6s6m7', // OpenIM密钥 ]); $user_id = $input->getOption('user_id'); if(!$user_id){ return false; } $user = \support\Jwt::direct($user_id); $imToken = $IM->auth->getUserToken(idEncode($user['id']),2); cp('userID:' . $user['id']); cp('nickname:' . $user['nickname']); cp('token:' . $user['token']); cp('imToken:' . $imToken['token']); return 0; } cp('action not exist'); return 0; } }