Room.php 1.5 KB

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