Room.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\common\library\wechat\live;
  3. use app\common\library\wechat\WxBase;
  4. /**
  5. * 微信小程序直播接口
  6. * Class Room
  7. * @package app\common\library\wechat\live
  8. */
  9. class Room extends WxBase
  10. {
  11. /**
  12. * 微信小程序直播-获取直播房间列表接口
  13. * api文档: https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/live-player-plugin.html
  14. * @throws \app\common\exception\BaseException
  15. */
  16. public function getLiveRoomList()
  17. {
  18. // 微信接口url
  19. $accessToken = $this->getAccessToken();
  20. $apiUrl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token={$accessToken}";
  21. // 请求参数
  22. $params = $this->jsonEncode(['start' => 0, 'limit' => 100]);
  23. // 执行请求
  24. $result = $this->post($apiUrl, $params);
  25. // 记录日志
  26. $this->doLogs(['describe' => '微信小程序直播-获取直播房间列表接口', 'url' => $apiUrl, 'params' => $params, 'result' => $result]);
  27. // 返回结果
  28. $response = $this->jsonDecode($result);
  29. if (!isset($response['errcode'])) {
  30. $this->error = 'not found errcode';
  31. return false;
  32. }
  33. // 容错: empty room list
  34. if ($response['errcode'] > 1 && $response['errcode'] != 9410000) {
  35. $this->error = $response['errmsg'];
  36. return false;
  37. }
  38. return $response;
  39. }
  40. }