| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\common\library\easywechat\wx;
- /**
- * 直播房间
- */
- class LiveRoom extends WxBase
- {
- /**
- * 同步小程序直播房间
- */
- public function syn()
- {
- $apiUrl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=%ACCESS_TOKEN%";
- $params = json_encode(['start' => 0, 'limit' => 100], JSON_UNESCAPED_UNICODE);
- return $this->generl($apiUrl, $params);
- }
- /**
- * 获取小程序直播房间播放记录
- */
- public function getReplay($roomId)
- {
- $apiUrl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=%ACCESS_TOKEN%";
- $params = json_encode(['action' => 'get_replay', 'start' => 0, 'limit' => 100, 'room_id' => $roomId], JSON_UNESCAPED_UNICODE);
- return $this->generl($apiUrl, $params);
- }
- public function generl($apiUrl, $params)
- {
- // 获取 access token 实例
- $accessToken = $this->app->access_token;
- $token = $accessToken->getToken();
- // // 微信接口url
- // $apiUrl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token={$token['access_token']}";
- // // 请求参数
- // $params = json_encode(['start' => 0, 'limit' => 100], JSON_UNESCAPED_UNICODE);
- $apiUrl = str_replace('%ACCESS_TOKEN%', $token['access_token'], $apiUrl);
- // 执行请求
- $result = $this->post($apiUrl, $params);
- // 返回结果
- $response = $this->jsonDecode($result);
- if (!isset($response['errcode'])) {
- $this->error = '请求错误';
- return false;
- }
- if ($response['errcode'] != 0) {
- if($response['errcode'] == '9410000'){
- $this->error = 'empty';
- }else{
- if($response['errcode'] == 40001){
- //防止token过期或更换,重新获取
- $accessToken->getToken(true);
- }
- $this->error = $response['errmsg'];
- }
- return false;
- }
- return $response;
- }
- }
|