Login.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\kefuapi\controller;
  12. use app\Request;
  13. use crmeb\basic\BaseController;
  14. use crmeb\services\CacheService;
  15. use app\services\kefu\LoginServices;
  16. use app\kefuapi\validate\LoginValidate;
  17. use think\facade\App;
  18. /**
  19. * Class Login
  20. * @package app\kefu\controller
  21. */
  22. class Login extends BaseController
  23. {
  24. /**
  25. * Login constructor.
  26. * @param LoginServices $services
  27. */
  28. public function __construct(App $app, LoginServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. protected function initialize()
  34. {
  35. // TODO: Implement initialize() method.
  36. }
  37. /**
  38. * 客服登录
  39. * @param Request $request
  40. * @return mixed
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function login(Request $request)
  46. {
  47. [$account, $password] = $request->postMore([
  48. ['account', ''],
  49. ['password', ''],
  50. ], true);
  51. validate(LoginValidate::class)->check(['account' => $account, 'password' => $password]);
  52. $token = $this->services->authLogin($account, $password);
  53. return app('json')->success(410001, $token);
  54. }
  55. /**
  56. * 开放平台扫码登录
  57. * @return mixed
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function wechatAuth()
  63. {
  64. return app('json')->success($this->services->wechatAuth());
  65. }
  66. /**
  67. * 获取公众平台id
  68. * @return mixed
  69. */
  70. public function getAppid()
  71. {
  72. return app('json')->success([
  73. 'appid' => sys_config('wechat_open_app_id', 'wxc736972a4ca1e2a1'),
  74. 'version' => get_crmeb_version(),
  75. 'site_name' => sys_config('site_name'),
  76. 'copyright' => sys_config('nncnL_crmeb_copyright', ''),
  77. 'copyrightImg' => sys_config('nncnL_crmeb_copyright_image', ''),
  78. ]);
  79. }
  80. /**
  81. * 获取登录唯一code
  82. * @return mixed
  83. */
  84. public function getLoginKey()
  85. {
  86. $key = md5(time() . uniqid());
  87. $time = time() + 600;
  88. CacheService::set($key, 1, 600);
  89. return app('json')->success(['key' => $key, 'time' => $time]);
  90. }
  91. /**
  92. * 验证登录
  93. * @param string $key
  94. * @return mixed
  95. * @throws \Psr\SimpleCache\InvalidArgumentException
  96. * @throws \think\db\exception\DataNotFoundException
  97. * @throws \think\db\exception\DbException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. */
  100. public function scanLogin(string $key)
  101. {
  102. return app('json')->success($this->services->scanLogin($key));
  103. }
  104. }