From f769f7ec024b3c8dd22566ff99964079423a3fef Mon Sep 17 00:00:00 2001 From: fantasticbin Date: Tue, 8 Nov 2022 15:45:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=8F=8ARP?= =?UTF-8?q?C=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/TestController.php | 87 ++++++++++++++++++++ app/JsonRpc/UserExternalServiceInterface.php | 8 ++ 2 files changed, 95 insertions(+) create mode 100644 app/Controller/TestController.php diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php new file mode 100644 index 0000000..021cd3d --- /dev/null +++ b/app/Controller/TestController.php @@ -0,0 +1,87 @@ +request->input('page', 1); + $perPage = (int) $this->request->input('per_page', 2); + + // 这里根据 $currentPage 和 $perPage 进行数据查询,以下使用 Collection 代替 + $collection = new Collection([ + ['id' => 1, 'name' => 'Tom'], + ['id' => 2, 'name' => 'Sam'], + ['id' => 3, 'name' => 'Tim'], + ['id' => 4, 'name' => 'Joe'], + ]); + + $users = array_values($collection->forPage($currentPage, $perPage)->toArray()); + + return new Paginator($users, $perPage, $currentPage); + } + + /** + * RPC调用示例 + * + * @return array + */ + public function user_info() + { + return $this->getServiceResult($this->userService->getUserInfo()); + } +} \ No newline at end of file diff --git a/app/JsonRpc/UserExternalServiceInterface.php b/app/JsonRpc/UserExternalServiceInterface.php index a38371e..d582f86 100644 --- a/app/JsonRpc/UserExternalServiceInterface.php +++ b/app/JsonRpc/UserExternalServiceInterface.php @@ -4,6 +4,14 @@ namespace App\JsonRpc; interface UserExternalServiceInterface { + /** + * 获取用户信息 + * + * @param string $name + * @return array + */ + public function getUserInfo(string $name = 'test') : array; + /** * 通过微信授权新建用户 *