User.php 813 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class User extends CI_Controller
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->output->set_content_type('application/json');
  9. }
  10. // 访问:GET /api/v1/user/center
  11. public function center()
  12. {
  13. $data = [
  14. 'code' => 200,
  15. 'version' => 'v1',
  16. 'data' => [
  17. 'username' => 'John Doe',
  18. 'email' => 'john@example.com'
  19. ]
  20. ];
  21. $this->output->set_output(json_encode($data));
  22. }
  23. // 访问:POST /api/v1/user/login
  24. public function login()
  25. {
  26. // 从输入流获取JSON数据
  27. $input = json_decode(file_get_contents('php://input'), true);
  28. // 业务逻辑...
  29. }
  30. }