AuthController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 \think\Response
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @author 吴汐
  38. * @email 442384644@qq.com
  39. * @date 2023/02/24
  40. */
  41. public function mp_auth(Request $request)
  42. {
  43. [$code, $cache_key, $login_type, $spread_spid, $spread_code, $iv, $encryptedData] = $request->postMore([
  44. ['code', ''],
  45. ['cache_key', ''],
  46. ['login_type', ''],
  47. ['spread_spid', 0],
  48. ['spread_code', ''],
  49. ['iv', ''],
  50. ['encryptedData', ''],
  51. ], true);
  52. $token = $this->services->mp_auth($code, $cache_key, $login_type, $spread_spid, $spread_code, $iv, $encryptedData);
  53. if ($token) {
  54. if (isset($token['key']) && $token['key']) {
  55. return app('json')->success(410022, $token);
  56. } else {
  57. return app('json')->success(410001, [
  58. 'userInfo' => $token['userInfo']
  59. ]);
  60. }
  61. } else
  62. return app('json')->fail(410019);
  63. }
  64. /**
  65. * 获取授权logo
  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')->success(['logo_url' => str_replace('\\', '/', $logo)]);
  73. }
  74. /**
  75. * 小程序支付回调
  76. */
  77. public function notify()
  78. {
  79. return $this->services->notify();
  80. }
  81. /**
  82. * 获取小程序订阅消息id
  83. * @return mixed
  84. */
  85. public function temp_ids()
  86. {
  87. return app('json')->success($this->services->tempIds());
  88. }
  89. /**
  90. * 获取小程序直播列表
  91. * @param Request $request
  92. * @param LiveRoomServices $liveRoom
  93. * @return mixed
  94. */
  95. public function live(Request $request, LiveRoomServices $liveRoom)
  96. {
  97. return app('json')->success($liveRoom->userList([]));
  98. }
  99. /**
  100. * 获取直播回放
  101. * @param $id
  102. * @param LiveRoomServices $lvieRoom
  103. * @return mixed
  104. */
  105. public function livePlaybacks($id, LiveRoomServices $lvieRoom)
  106. {
  107. return app('json')->success($lvieRoom->getPlaybacks((int)$id));
  108. }
  109. }