api接口调用实例(response json_encode json)创建展视互动直播间,

来源:互联网 发布:声音编辑软件中文版 编辑:程序博客网 时间:2024/06/05 06:20

一、返回值是一维数组取值的方法


创建展视互动直播间

提交参数创建直播间返回直播间参数,然后取得参数保存到数据库


01.html代码

<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><style>#form_id {    padding: 20px 10px;}.left-box label {    display: inline-block;    width: 230px;    margin-bottom: 5px;    text-align: right;    padding-right: 10px;}</style></head><body>    <div class="left-box"><form id="form_id" action="02.php" method="post"><label for="input_id0">*loginName</label><input name="loginName" type="text" id="input_id0" value="admin@ojysjszwm.com">登录名<br><label for="input_id1">*password</label><input name="password" type="text" id="input_id1" value="888988888">密码<br><label for="input_id23">sec</label><input name="sec" type="text" id="input_id23">true:表示密码是经过加密的<br><br><br><label for="input_id2">*subject</label><input name="subject" type="text" id="input_id2">实时课堂主题<br><label for="input_id3">*startDate</label><input name="startDate" type="text" id="input_id3" value="2017-08-09 23:24:14">开始日期<br><label for="input_id4">invalidDate</label><input name="invalidDate" type="text" id="input_id4">失效时间<br><label for="input_id5">duration</label><input name="duration" type="text" id="input_id5">课堂持续时长(单位为分钟)<br><label for="input_id6">uiMode</label><input name="uiMode" type="text" id="input_id6">Web 端学生界面设置(1 是三分屏, 2是文档/视频为主, 3是两分屏, 4:互动增加)<br><label for="input_id7">uiColor</label><input name="uiColor" type="text" id="input_id7">三分屏颜色选择( blue, default, green),默认是 default<br><label for="input_id8">uiVideo</label><input name="uiVideo" type="text" id="input_id8">uiMode等于 2时候,设置是否视频为主。默认为 false。<br><label for="input_id9">uiWindow</label><input name="uiWindow" type="text" id="input_id9">uiMode等于 2时候,设置是否显示小窗口。默认为 false<br><label for="input_id10">upgrade</label><input name="upgrade" type="text" id="input_id10">是否允许 web 升级到客户端<br><label for="input_id11">teacherToken</label><input name="teacherToken" type="text" id="input_id11">老师加入口令(长度: 6-15)(会自动生成随机数)<br><label for="input_id12">assistantToken</label><input name="assistantToken" type="text" id="input_id12">助教加入口令(长度: 6-15)(会自动生成随机数)<br><label for="input_id13">studentToken</label><input name="studentToken" type="text" id="input_id13">Web端学生加入口令(长度:最大 15)<br><label for="input_id14">studentClientToken</label><input name="studentClientToken" type="text" id="input_id14">客户端学生加入口令<br><label for="input_id15">webJoin</label><input name="webJoin" type="text" id="input_id15" class="baseClass">是否支持Web端学生加入,值为true或者false。默认值为 true<br><label for="input_id16">clientJoin</label><input name="clientJoin" type="text" id="input_id16" class="baseClass">是否支持客户端端学生加入,值为 true或者 false。默认值为 true<br><label for="input_id17">description</label><input name="description" type="text" id="input_id17">课堂介绍 <br><label for="input_id18">scheduleInfo</label><input name="scheduleInfo" type="text" id="input_id18">课程介绍<br><label for="input_id19">speakerInfo</label><input name="speakerInfo" type="text" id="input_id19">老师介绍<br><label for="input_id20">scene</label><input name="scene" type="text" id="input_id20">0:大讲堂, 1:小班课,默认值: 0。<br><label for="input_id21">realtime</label><input name="realtime" type="text" id="input_id21" class="baseClass">true:表示实时的, false:表示非实时的,默认是 false<br><label for="input_id22">maxAttendees</label><input name="maxAttendees" type="text" id="input_id22">课堂最大并发数。只有站点开启指定并发数功能,才能够设置。否则即使传入数据也无效<br>  <p>    <input type="submit" name="submit" id="submit" value="提交">     </p></form></div><!--<form action="http://jysjsz.gensee.com/integration/site/training/room/created" method="post">  <p>    <label for="textfield">实时课堂主题:</label>    <input type="text" name="subject" id="subject" value="测试直播吧">      </p>  <p>    <label for="textfield2">开始日期:</label>    <input type="text" name="startDate" id="startDate" value="<?php echo date('Y-m-d H:i:s',time()) ?>">  </p>    <p>    <label for="textfield2">失效时间:</label>    <input type="text" name="invalidDate" id="invalidDate" value="">  </p>    <p>    <label for="textfield2">登录名:</label>    <input type="text" name="loginName" id="loginName" value="admin@jysjsz.com">  </p>  <p>    <label for="textfield2">密码:</label>    <input type="text" name="password" id="password" value="888888">  </p>  <p>    <input type="submit" name="submit" id="submit" value="提交">     </p>  <p id="resText"></p></form>-->     </body></html>  



02.php代码


 <?php  $subject=$_POST['subject']; $startDate=$_POST['startDate']; $loginName=$_POST['loginName']; $password=$_POST['password'];    //平台提供的接口网址   //展视互动网址获取方法:http://blog.csdn.net/haibo0668/article/details/76978478   $url = "http://xxxxx.gensee.com/integration/site/training/room/created";        $post_data = array (          "subject" => $subject,          "startDate" => $startDate,          "loginName" => $loginName,  "password" => $password        );        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        // 设置请求为post类型        curl_setopt($ch, CURLOPT_POST, 1);        // 添加post数据到请求中        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);        // 执行post请求,获得回复        $response= curl_exec($ch);        curl_close($ch);        echo $response;//$response='{"assistantToken":"789317","clientJoin":true,"code":"0","id":"fFEmw3zBX0","number":"53006601","scene":0,"startDate":1502289830000,"studentClientToken":"927508","studentJoinUrl":"http://jysjsz.gensee.com/training/site/s/53006601","teacherJoinUrl":"http://jysjsz.gensee.com/training/site/r/53006601","teacherToken":"694582","webJoin":true}';//取得返回数组    $jsonStr=$response;//$jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":"SUCCESS"}}'; $arr = json_decode($jsonStr, true); $assistantToken = $arr['assistantToken'];//助教口令$clientJoin = $arr['clientJoin'];//是否允许客户端学生加入$code = $arr['code'];$id = $arr['id'];//SDK ID  实时课堂 ID$number = $arr['number'];//直播间ID$scene = $arr['scene'];//0:大讲堂, 1:小班课$startDate = $arr['startDate'];//开始日期$studentClientToken = $arr['studentClientToken'];//客户端学生加入口令 $studentJoinUrl = $arr['studentJoinUrl'];//学员加入 URL$teacherJoinUrl = $arr['teacherJoinUrl'];//老师和助教加入 URL$teacherToken = $arr['teacherToken'];//老师加入口令$webJoin = $arr['webJoin'];//是否允许 web 端学生加入   // echo "<br>assistantToken=".$assistantToken;?>


二、返回值是二维数组取值的方法


//错误信息提示        if ($response  === FALSE) {          echo "cURL 具体出错信息: " . curl_error($ch);        }$arr = json_decode($response, true);// echo '<pre>';// print_r($arr['coursewares']);// echo '</pre>';     echo $arr['coursewares'][0]['id'];


 echo $arr['coursewares'][0]['id'];


原创粉丝点击