初始化代码
This commit is contained in:
117
application/api/model/AgoraCallback.php
Normal file
117
application/api/model/AgoraCallback.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class AgoraCallback extends Model
|
||||
{
|
||||
|
||||
//封禁用户
|
||||
public function kicking_user($uid, $rid, $time = 1){
|
||||
$config = get_uncache_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];
|
||||
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$curlPost = array(
|
||||
'appid' => $agora_app_id,
|
||||
'cname' => strval($rid),
|
||||
'uid' => $uid,
|
||||
'time' => $time,
|
||||
'privileges' => array(
|
||||
'join_channel'
|
||||
)
|
||||
);
|
||||
|
||||
$postUrl = "https://api.sd-rtn.com/dev/v1/kicking-rule";
|
||||
$curlPost = json_encode($curlPost);
|
||||
$result = $this->agora_post_url($postUrl, $curlPost);
|
||||
if($result['status'] == 'success'){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public function channel_room($rid){
|
||||
$config = get_uncache_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];//cc71b8df2c254c35bc96fbf591b6801f
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
$rid = strval($rid);
|
||||
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$postUrl = 'https://api.sd-rtn.com/dev/v1/channel/user/'.$agora_app_id.'/'.$rid.'/hosts_only';
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
"Authorization:Basic ".$AuthorizationHeader,
|
||||
);
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
// curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);CURLOPT_RETURNTRANSFER
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
$data = json_decode($data, true);
|
||||
|
||||
if($data['success']){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//请求封装方法
|
||||
public function agora_post_url($postUrl, $curlPost){
|
||||
$config = get_uncache_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];
|
||||
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
"Authorization:Basic ".$AuthorizationHeader,
|
||||
);
|
||||
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
if ($data) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
// dump($data);exit;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user