AuthController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\wechat;
  12. use app\Request;
  13. use app\services\activity\live\LiveRoomServices;
  14. use app\services\wechat\RoutineServices;
  15. /**
  16. * 小程序相关
  17. * Class AuthController
  18. * @package app\controller\api\wechat
  19. */
  20. class AuthController
  21. {
  22. protected $services = NUll;
  23. /**
  24. * AuthController constructor.
  25. * @param RoutineServices $services
  26. */
  27. public function __construct(RoutineServices $services)
  28. {
  29. $this->services = $services;
  30. }
  31. /**
  32. * 小程序授权登录
  33. * @param Request $request
  34. * @return mixed
  35. * @throws \Psr\SimpleCache\InvalidArgumentException
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public function mp_auth(Request $request)
  41. {
  42. [$code, $cache_key, $login_type, $spread_spid, $spread_code, $iv, $encryptedData] = $request->postMore([
  43. ['code', ''],
  44. ['cache_key', ''],
  45. ['login_type', ''],
  46. ['spread_spid', 0],
  47. ['spread_code', ''],
  48. ['iv', ''],
  49. ['encryptedData', ''],
  50. ], true);
  51. $token = $this->services->mp_auth($code, $cache_key, $login_type, $spread_spid, $spread_code, $iv, $encryptedData);
  52. if ($token) {
  53. if (isset($token['key']) && $token['key']) {
  54. return app('json')->successful('授权成功,请绑定手机号', $token);
  55. } else {
  56. return app('json')->successful('登录成功!', [
  57. 'userInfo' => $token['userInfo']
  58. ]);
  59. }
  60. } else
  61. return app('json')->fail('获取用户访问token失败!');
  62. }
  63. /**
  64. * 获取授权logo
  65. * @param Request $request
  66. * @return mixed
  67. */
  68. public function get_logo()
  69. {
  70. $logo = sys_config('wap_login_logo');
  71. if (strstr($logo, 'http') === false && $logo) $logo = sys_config('site_url') . $logo;
  72. return app('json')->successful(['logo_url' => str_replace('\\', '/', $logo)]);
  73. }
  74. /**
  75. * 获取小程序订阅消息id
  76. * @return mixed
  77. */
  78. public function teml_ids()
  79. {
  80. return app('json')->success($this->services->temlIds());
  81. }
  82. /**
  83. * 获取小程序直播列表
  84. * @param Request $request
  85. * @return mixed
  86. */
  87. public function live(Request $request, LiveRoomServices $liveRoom)
  88. {
  89. return app('json')->success($liveRoom->userList([]));
  90. }
  91. /**
  92. * 获取直播回放
  93. * @param $id
  94. * @param LiveRoomServices $lvieRoom
  95. * @return mixed
  96. */
  97. public function livePlaybacks($id, LiveRoomServices $lvieRoom)
  98. {
  99. return app('json')->success($lvieRoom->getPlaybacks((int)$id));
  100. }
  101. }