Login.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\outapi\controller;
  12. use app\outapi\validate\LoginValidate;
  13. use app\Request;
  14. use think\facade\App;
  15. use app\services\out\OutAccountServices;
  16. /**
  17. * Class Login
  18. * @package app\out\controller
  19. */
  20. class Login extends AuthController
  21. {
  22. /**
  23. * OutAccount constructor.
  24. * @param App $app
  25. * @param OutAccountServices $services
  26. */
  27. public function __construct(App $app, OutAccountServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. protected function initialize()
  33. {
  34. // TODO: Implement initialize() method.
  35. }
  36. /**
  37. * 客服登录
  38. * @param Request $request
  39. * @return mixed
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function getToken(Request $request)
  45. {
  46. [$appid, $appsecret] = $request->postMore([
  47. ['appid', ''],
  48. ['appsecret', ''],
  49. ], true);
  50. $this->validate(['appid' => $appid, 'appsecret' => $appsecret], LoginValidate::class);
  51. $token = $this->services->authLogin($appid, $appsecret);
  52. return app('json')->success(100010, $token);
  53. }
  54. /**
  55. * 刷新token
  56. * @return void
  57. */
  58. public function refreshToken(Request $request)
  59. {
  60. [$token] = $request->postMore([
  61. ['access_token', ''],
  62. ], true);
  63. $token = $this->services->refresh($token);
  64. return app('json')->success(100010, $token);
  65. }
  66. }