1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\expand\controller;
- use app\common\service\HelperService;
- use app\expand\controller\BaseAuth;
- use think\Cache;
- use think\Validate;
- /**
- * Author: luzheng.liu
- * Time: 2020/10/13 14:03
- */
- class Live extends BaseAuth {
- public function __construct() {
- parent::__construct();
- }
- /**
- * 获取直播列表
- */
- public function getLiveList() {
- $params = $this->_params;
- $rule = [
- 'start|开始房间号' => 'require',
- 'limit|数量' => 'require',
- ];
- $validate = new Validate($rule);
- if (!$validate->check($params)) {
- HelperService::returnJson(['code' => '400', 'msg' => $validate->getError(), 'data' => []]);
- }
- Cache::rm('access_token_' . $this->_apiCode);
- $accessToken = Cache::get('access_token_' . $this->_apiCode);
- if (empty($accessToken)) {
- $wx = new WechatJs();
- $accessToken = $wx->getWxToken();
- Cache::set('access_token_' . $this->_apiCode, $accessToken, 300);
- }
- $data = [
- "start" => $params['start'] ?: 0,
- 'limit' => $params['limit'] ?: 10,
- ];
- $roomList = HelperService::httpPost('https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=' . $accessToken, json_encode($data), false);
- $roomList = json_decode($roomList, true);
- if ($roomList['errcode'] === 1) {
- HelperService::returnJson(['code' => '200', 'msg' => '未创建直播间', 'data' => []]);
- }
- $room = [
- 'roomList' => $roomList['room_info'],
- 'total' => $roomList['total']
- ];
- HelperService::returnJson(['code' => '200', 'msg' => 'success', 'data' => $room]);
- }
- }
|