123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- use app\common\service\HelperService;
- use app\expand\controller\BaseAuth;
- use think\Validate;
- /**
- * Author: luzheng.liu
- * Time: 2020/10/13 14:03
- */
- class Live extends BaseAuth {
- 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' => []]);
- }
- $appId = 'wx68df76aec541062d';
- $appSecret = '415549b10c1ea7aaa62991ed1b26acc0';
- /**
- * $auth = {"access_token":"ACCESS_TOKEN","expires_in":7200}
- */
- $auth = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={{$appId}}&secret={{$appSecret}}
-
- ");
- $auth = json_decode($auth, true);
- if (empty($auth['access_token'])) {
- HelperService::returnJson(['code' => 4000, 'data' => $auth, 'msg' => $auth['errmsg']]);
- }
- $accessToken = $auth['access_token'];
- $data = [
- "start" => 0,
- 'limit' => 10,
- ];
- $rommList = HelperService::httpPost('https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=
- ' . $accessToken, json_encode($data), false, ['Content-Type: application/json; charset=utf-8']);
- $roomList = json_decode($rommList, true);
- if ($rommList['errcode'] === 1) {
- HelperService::returnJson(['code' => '200', 'msg' => '未创建直播间', 'data' => []]);
- }
- $room = [
- 'roomList' => $rommList['room_info'],
- ];
- HelperService::returnJson(['code' => '200', 'msg' => 'success', 'data' => $room]);
- }
- }
|