[ 'addon' => 'unishop', 'controller' => $controller, 'action' => $action ], 'controller' => $controller, 'action' => $action, 'get' => $get, 'post' => $post, 'request' => $params, 'header' => $header ]); $obj = new $class($request); $obj->$action(); } catch (HttpResponseException $e) { $data = $e->getResponse(); } } // 输出数据到客户端 if ($data instanceof Response) { $response = $data; } elseif (!is_null($data)) { // 默认自动识别响应输出类型 $type = $request->isAjax() ? Config::get('default_ajax_return') : Config::get('default_return_type'); $response = Response::create($data, $type); } else { $response = Response::create(); } return $response->getData(); } /** * 模拟用户登录 */ public function userLogin() { $contents = $this->request(User::class, 'login',[ 'mobile' => self::$mobile, 'password' => self::$password ]); if ($contents['code'] == 0) { // 模拟发送短信 \app\common\model\Sms::create(['event' => $this->eventRegister, 'mobile' => self::$mobile, 'code' => self::$smsCode, 'ip' => 'phpunit', 'createtime' => time()]); $this->request(User::class, 'register', [ 'captcha' => self::$smsCode, 'mobile' => self::$mobile, 'password' => self::$password, 'username' => self::$username ]); $contents = $this->request(User::class, 'login',[ 'mobile' => self::$mobile, 'password' => self::$password ]); } return $contents; } }