Live.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use app\common\service\HelperService;
  3. use app\expand\controller\BaseAuth;
  4. use think\Validate;
  5. /**
  6. * Author: luzheng.liu
  7. * Time: 2020/10/13 14:03
  8. */
  9. class Live extends BaseAuth {
  10. public function getLiveList() {
  11. $params = $this->_params;
  12. $rule = [
  13. 'start|开始房间号' => 'require',
  14. 'limit|数量' => 'require',
  15. ];
  16. $validate = new Validate($rule);
  17. if (!$validate->check($params)) {
  18. HelperService::returnJson(['code' => '400', 'msg' => $validate->getError(), 'data' => []]);
  19. }
  20. $appId = 'wx68df76aec541062d';
  21. $appSecret = '415549b10c1ea7aaa62991ed1b26acc0';
  22. /**
  23. * $auth = {"access_token":"ACCESS_TOKEN","expires_in":7200}
  24. */
  25. $auth = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={{$appId}}&secret={{$appSecret}}
  26. ");
  27. $auth = json_decode($auth, true);
  28. if (empty($auth['access_token'])) {
  29. HelperService::returnJson(['code' => 4000, 'data' => $auth, 'msg' => $auth['errmsg']]);
  30. }
  31. $accessToken = $auth['access_token'];
  32. $data = [
  33. "start" => 0,
  34. 'limit' => 10,
  35. ];
  36. $rommList = HelperService::httpPost('https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=
  37. ' . $accessToken, json_encode($data), false, ['Content-Type: application/json; charset=utf-8']);
  38. $roomList = json_decode($rommList, true);
  39. if ($rommList['errcode'] === 1) {
  40. HelperService::returnJson(['code' => '200', 'msg' => '未创建直播间', 'data' => []]);
  41. }
  42. $room = [
  43. 'roomList' => $rommList['room_info'],
  44. ];
  45. HelperService::returnJson(['code' => '200', 'msg' => 'success', 'data' => $room]);
  46. }
  47. }