LoginController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\api\controller\pc;
  12. use app\services\pc\LoginServices;
  13. use crmeb\services\CacheService;
  14. class LoginController
  15. {
  16. protected $services;
  17. public function __construct(LoginServices $services)
  18. {
  19. $this->services = $services;
  20. }
  21. /**
  22. * 获取扫码登陆KEY
  23. * @return mixed
  24. */
  25. public function getLoginKey()
  26. {
  27. $key = md5(time() . uniqid());
  28. $time = time() + 600;
  29. CacheService::set($key, 1, 600);
  30. return app('json')->success(['key' => $key, 'time' => $time]);
  31. }
  32. /**
  33. * 扫码登陆
  34. * @param string $key
  35. * @return mixed
  36. * @throws \Psr\SimpleCache\InvalidArgumentException
  37. */
  38. public function scanLogin(string $key)
  39. {
  40. return app('json')->success($this->services->scanLogin($key));
  41. }
  42. /**
  43. * 开放平台扫码登录
  44. * @return mixed
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function wechatAuth()
  50. {
  51. return app('json')->success($this->services->wechatAuth());
  52. }
  53. /**
  54. * 获取公众平台id
  55. * @return mixed
  56. */
  57. public function getAppid()
  58. {
  59. return app('json')->success([
  60. 'appid' => sys_config('wechat_open_app_id'),
  61. 'version' => get_crmeb_version()
  62. ]);
  63. }
  64. }