AuthController.php 3.2 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\api\controller\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\api\controller\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. */
  36. public function mp_auth(Request $request)
  37. {
  38. [$code, $cache_key, $login_type, $spread_spid, $spread_code, $iv, $encryptedData] = $request->postMore([
  39. ['code', ''],
  40. ['cache_key', ''],
  41. ['login_type', ''],
  42. ['spread_spid', 0],
  43. ['spread_code', ''],
  44. ['iv', ''],
  45. ['encryptedData', ''],
  46. ], true);
  47. $token = $this->services->mp_auth($code, $cache_key, $login_type, $spread_spid, $spread_code, $iv, $encryptedData);
  48. if ($token) {
  49. if (isset($token['key']) && $token['key']) {
  50. return app('json')->success(410022, $token);
  51. } else {
  52. return app('json')->success(410001, [
  53. 'userInfo' => $token['userInfo']
  54. ]);
  55. }
  56. } else
  57. return app('json')->fail(410019);
  58. }
  59. /**
  60. * 获取授权logo
  61. * @return mixed
  62. */
  63. public function get_logo()
  64. {
  65. $logo = sys_config('wap_login_logo');
  66. if (strstr($logo, 'http') === false && $logo) $logo = sys_config('site_url') . $logo;
  67. return app('json')->success(['logo_url' => str_replace('\\', '/', $logo)]);
  68. }
  69. /**
  70. * 小程序支付回调
  71. */
  72. public function notify()
  73. {
  74. return $this->services->notify();
  75. }
  76. /**
  77. * 获取小程序订阅消息id
  78. * @return mixed
  79. */
  80. public function temp_ids()
  81. {
  82. return app('json')->success($this->services->tempIds());
  83. }
  84. /**
  85. * 获取小程序直播列表
  86. * @param Request $request
  87. * @param LiveRoomServices $liveRoom
  88. * @return mixed
  89. */
  90. public function live(Request $request, LiveRoomServices $liveRoom)
  91. {
  92. return app('json')->success($liveRoom->userList([]));
  93. }
  94. /**
  95. * 获取直播回放
  96. * @param $id
  97. * @param LiveRoomServices $lvieRoom
  98. * @return mixed
  99. */
  100. public function livePlaybacks($id, LiveRoomServices $lvieRoom)
  101. {
  102. return app('json')->success($lvieRoom->getPlaybacks((int)$id));
  103. }
  104. }