AccountController.php 3.0 KB

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