Skip to content

Commit 528c535

Browse files
committed
Optimization code
1 parent a0d8e19 commit 528c535

File tree

10 files changed

+71
-251
lines changed

10 files changed

+71
-251
lines changed

rtc/example/example.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<?php
2-
3-
require join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), 'src', 'Rtc_v3.php'));
42
require_once("../../autoload.php");
53

4+
use \Qiniu\Auth;
5+
66
$ak = 'gwd_gV4gPKZZsmEOvAuNU1AcumicmuHooTfu64q5';
77
$sk = 'xxxx';
88

9-
$mac = new QiniuRtc\Mac($ak, $sk);
10-
$client = new QiniuRtc\AppClient($mac);
9+
$auth = new Auth($ak, $sk);
10+
$client = new Qiniu\Rtc\AppClient($auth);
1111
$hub = 'lfxlive';
1212
$title = 'lfxl';
1313
try {
1414
//创建app
1515
$resp = $client->createApp($hub, $title, $maxUsers);
1616
print_r($resp);exit;
1717
// 获取app状态
18-
$resp = $client->getApp('dgbg9ym9p');
18+
$resp = $client->getApp('dgbo3e8f6');
1919
print_r($resp);exit;
2020
//修改app状态
2121
$mergePublishRtmp = null;
2222
$mergePublishRtmp['enable'] = true;
2323
$resp = $client->UpdateApp('dgbgljsxp', $hub, $title, $maxUsers, $mergePublishRtmp);
2424
print_r($resp);exit;
2525
//删除app
26-
$resp = $client->deleteApp('dgbgljsxp');
26+
$resp = $client->deleteApp('dgbo8p9nm');
2727
print_r($resp);exit;
2828
//获取房间连麦的成员
2929
$resp=$client->getappUserNum("dgbfvvzid", 'lfxl');
@@ -35,7 +35,7 @@
3535
$resp=$client->listRooms("dgbfvvzid", 'lfx', null, null);
3636
print_r($resp);exit;
3737
//鉴权的有效时间: 1个小时.
38-
$resp = $client->appToken("dgbfvvzid", "lfxl", '1111', (time()+3600), 'user');
38+
$resp = $client->appToken("dgbng7v36", "lfxl", '1111', (time()+3600), 'user');
3939
print_r($resp);exit;
4040
} catch (\Exception $e) {
4141
echo "Error:", $e, "\n";

rtc/src/QiniuRtc/Client.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

rtc/src/QiniuRtc/Config.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

rtc/src/QiniuRtc/Mac.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

rtc/src/QiniuRtc/Transport.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

rtc/src/QiniuRtc/Utils.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

rtc/src/Rtc_v3.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Qiniu/Auth.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
final class Auth
77
{
8-
private $accessKey;
9-
private $secretKey;
8+
public $accessKey;
9+
public $secretKey;
1010

1111
public function __construct($accessKey, $secretKey)
1212
{
@@ -22,6 +22,7 @@ public function getAccessKey()
2222
public function sign($data)
2323
{
2424
$hmac = hash_hmac('sha1', $data, $this->secretKey, true);
25+
$aa = $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac);
2526
return $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac);
2627
}
2728

@@ -184,4 +185,31 @@ public function authorizationV2($url, $method, $body = null, $contentType = null
184185
$auth = 'Qiniu ' . $sign;
185186
return array('Authorization' => $auth);
186187
}
188+
189+
public function RtcToken($method, $url, $contentType, $body)
190+
{
191+
$url = parse_url($url);
192+
$data = '';
193+
if (!empty($url['path'])) {
194+
$data = $method . ' ' . $url['path'];
195+
}
196+
if (!empty($url['query'])) {
197+
$data .= '?' . $url['query'];
198+
}
199+
if (!empty($url['host'])) {
200+
$data .= "\nHost: " . $url['host'];
201+
if (isset($url['port'])) {
202+
$data .= ':' . $url['port'];
203+
}
204+
}
205+
if (!empty($contentType)) {
206+
$data .= "\nContent-Type: " . $contentType;
207+
}
208+
$data .= "\n\n";
209+
if (!empty($body)) {
210+
$data .= $body;
211+
}
212+
$sign = $this->sign($data);
213+
return 'Qiniu ' . $sign;
214+
}
187215
}

src/Qiniu/Config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ final class Config
1111
const API_HOST = 'api.qiniu.com';
1212
const RS_HOST = 'rs.qiniu.com'; //RS Host
1313
const UC_HOST = 'https://api.qiniu.com'; //UC Host
14+
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
15+
const RTCAPI_VERSION = 'v3';
1416

1517
// Zone 空间对应的机房
1618
public $zone;

0 commit comments

Comments
 (0)