浏览代码

feat(直播列表接口):获取直播列表

geek 4 年之前
父节点
当前提交
c2b16d56dd
共有 2 个文件被更改,包括 61 次插入4 次删除
  1. 4 4
      application/common/service/HelperService.php
  2. 57 0
      application/expand/controller/Live.php

+ 4 - 4
application/common/service/HelperService.php

@@ -128,10 +128,10 @@ class HelperService
 
     /**
      * http post请求方法
-     * @param type $orginUrl 请求的url
-     * @param type $param 请求参数
-     * @param type $is_ssl 是否是https的请求
-     * @param type $header 请求头部信息
+     * @param string $orginUrl 请求的url
+     * @param string $param 请求参数
+     * @param boolean $is_ssl 是否是https的请求
+     * @param array $header 请求头部信息
      * @return boolean
      */
     public static function httpPost($orginUrl, $param='',$is_ssl=false,$header=[]) {

+ 57 - 0
application/expand/controller/Live.php

@@ -0,0 +1,57 @@
+<?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]);
+    }
+
+}