AccountController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Client\AccountService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * @group 账户管理
  8. *
  9. * 包含登录、注册、账户管理等基础功能
  10. */
  11. class AccountController extends Controller
  12. {
  13. protected AccountService $service;
  14. public function __construct(AccountService $service)
  15. {
  16. $this->service = $service;
  17. }
  18. /**
  19. * 发送验证码
  20. *
  21. * 向指定手机号发送验证码
  22. *
  23. * @bodyParam mobile string required 手机号码. Example: 13800138000
  24. *
  25. * @response {
  26. * "code": 200,
  27. * "message": "验证码发送成功",
  28. * "data": null
  29. * }
  30. */
  31. public function sendVerifyCode(Request $request)
  32. {
  33. $mobile = $request->input('mobile');
  34. return $this->service->sendVerifyCode($mobile);
  35. }
  36. /**
  37. * 用户登录
  38. *
  39. * 使用手机号和验证码登录账户
  40. *
  41. * @bodyParam mobile string required 手机号码. Example: 13800138000
  42. * @bodyParam code string required 验证码. Example: 123456
  43. *
  44. * @response {
  45. * "code": 200,
  46. * "message": "登录成功",
  47. * "data": {
  48. * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  49. * "user": {
  50. * "id": 1,
  51. * "mobile": "13800138000",
  52. * "nickname": "用户昵称"
  53. * }
  54. * }
  55. * }
  56. */
  57. public function login(Request $request)
  58. {
  59. $mobile = $request->input('mobile');
  60. $code = $request->input('code');
  61. return $this->service->login($mobile, $code);
  62. }
  63. /**
  64. * 微信登录
  65. *
  66. * 使用微信openid登录账户
  67. *
  68. * @bodyParam openid string required 微信openid. Example: wx_123456789
  69. *
  70. * @response {
  71. * "code": 200,
  72. * "message": "登录成功",
  73. * "data": {
  74. * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  75. * "user": {
  76. * "id": 1,
  77. * "openid": "wx_123456789",
  78. * "nickname": "微信昵称"
  79. * }
  80. * }
  81. * }
  82. */
  83. public function wxLogin(Request $request)
  84. {
  85. $openid = $request->input('openid');
  86. return $this->service->wxLogin($openid);
  87. }
  88. /**
  89. * 用户退出
  90. *
  91. * 退出当前账户登录状态
  92. *
  93. * @authenticated
  94. *
  95. * @response {
  96. * "code": 200,
  97. * "message": "退出成功",
  98. * "data": null
  99. * }
  100. */
  101. public function logout()
  102. {
  103. return $this->service->logout();
  104. }
  105. /**
  106. * 用户注销
  107. *
  108. * 永久注销当前账户
  109. *
  110. * @authenticated
  111. *
  112. * @response {
  113. * "code": 200,
  114. * "message": "注销成功",
  115. * "data": null
  116. * }
  117. */
  118. public function destroy()
  119. {
  120. return $this->service->deleteAccount();
  121. }
  122. }