Skip to content

Commit 347dd25

Browse files
committed
Optimization code
1 parent 528c535 commit 347dd25

File tree

3 files changed

+13
-49
lines changed

3 files changed

+13
-49
lines changed

rtc/example/example.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use \Qiniu\Auth;
55

66
$ak = 'gwd_gV4gPKZZsmEOvAuNU1AcumicmuHooTfu64q5';
7-
$sk = 'xxxx';
7+
$sk = '9G4isTkVuj5ITPqH1ajhljJMTc2k4m-hZh5r5ZsK';
88

99
$auth = new Auth($ak, $sk);
1010
$client = new Qiniu\Rtc\AppClient($auth);
@@ -15,15 +15,15 @@
1515
$resp = $client->createApp($hub, $title, $maxUsers);
1616
print_r($resp);exit;
1717
// 获取app状态
18-
$resp = $client->getApp('dgbo3e8f6');
18+
$resp = $client->getApp('dgbrj7ghp');
1919
print_r($resp);exit;
2020
//修改app状态
2121
$mergePublishRtmp = null;
2222
$mergePublishRtmp['enable'] = true;
23-
$resp = $client->UpdateApp('dgbgljsxp', $hub, $title, $maxUsers, $mergePublishRtmp);
23+
$resp = $client->UpdateApp('dgbrj7ghp', $hub, $title, $maxUsers, $mergePublishRtmp);
2424
print_r($resp);exit;
2525
//删除app
26-
$resp = $client->deleteApp('dgbo8p9nm');
26+
$resp = $client->deleteApp('dgbrj7ghp');
2727
print_r($resp);exit;
2828
//获取房间连麦的成员
2929
$resp=$client->getappUserNum("dgbfvvzid", 'lfxl');

src/Qiniu/Auth.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,31 +185,4 @@ public function authorizationV2($url, $method, $body = null, $contentType = null
185185
$auth = 'Qiniu ' . $sign;
186186
return array('Authorization' => $auth);
187187
}
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-
}
215188
}

src/Qiniu/Rtc/AppClient.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,9 @@ public function appToken($appId, $roomName, $userId, $expireAt, $permission)
192192
private function get($url)
193193
{
194194
$cType = null;
195-
$rtcToken = $this->auth->RtcToken("GET", $url, $cType, $body);
196-
$headers = array(
197-
'Content-Type' => $cType,
198-
'Authorization' => $rtcToken,
199-
);
200-
$ret = Client::get($url, $headers);
195+
$rtcToken = $this->auth->authorizationV2($url, "GET", $body, $cType);
196+
$rtcToken['Content-Type'] = $cType;
197+
$ret = Client::get($url, $rtcToken);
201198
if (!$ret->ok()) {
202199
return array(null, new Error($url, $ret));
203200
}
@@ -207,12 +204,9 @@ private function get($url)
207204
private function delete($url)
208205
{
209206
$cType = 'application/json';
210-
$rtcToken = $this->auth->RtcToken("DELETE", $url, $cType, $body);
211-
$headers = array(
212-
'Content-Type' => $cType,
213-
'Authorization' => $rtcToken,
214-
);
215-
$ret = Client::delete($url, $headers);
207+
$rtcToken = $this->auth->authorizationV2($url, "DELETE", $body, $cType);
208+
$rtcToken['Content-Type'] = $cType;
209+
$ret = Client::delete($url, $rtcToken);
216210
if (!$ret->ok()) {
217211
return array(null, new Error($url, $ret));
218212
}
@@ -222,12 +216,9 @@ private function delete($url)
222216
private function post($url, $body)
223217
{
224218
$cType = 'application/json';
225-
$rtcToken = $this->auth->RtcToken("POST", $url, $cType, $body);
226-
$headers = array(
227-
'Content-Type' => $cType,
228-
'Authorization' => $rtcToken,
229-
);
230-
$ret = Client::post($url, $body, $headers);
219+
$rtcToken = $this->auth->authorizationV2($url, "POST", $body, $cType);
220+
$rtcToken['Content-Type'] = $cType;
221+
$ret = Client::post($url, $body, $rtcToken);
231222
if (!$ret->ok()) {
232223
return array(null, new Error($url, $ret));
233224
}

0 commit comments

Comments
 (0)