Skip to content

Commit ce3eada

Browse files
committed
Optimization code
1 parent fc444c1 commit ce3eada

File tree

3 files changed

+14
-38
lines changed

3 files changed

+14
-38
lines changed

rtc/example/example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
$resp = $client->createApp($hub, $title, $maxUsers);
1616
print_r($resp);exit;
1717
// 获取app状态
18-
$resp = $client->getApp('dgbrj7ghp');
18+
$resp = $client->getApp('dgd330nc2');
1919
print_r($resp);exit;
2020
//修改app状态
2121
$mergePublishRtmp = null;

src/Qiniu/Auth.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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);
2625
return $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac);
2726
}
2827

src/Qiniu/Rtc/AppClient.php

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ public function createApp($hub, $title, $maxUsers = null, $noAutoKickUser = null
3636
$params['noAutoKickUser'] = $noAutoKickUser;
3737
}
3838
$body = json_encode($params);
39-
list($ret, $err) = $this->post($this->_baseURL, $body);
40-
if ($err !== null) {
41-
return $err;
42-
} else {
43-
return $ret;
44-
}
39+
$ret = $this->post($this->_baseURL, $body);
40+
return $ret;
4541
}
4642

4743
/*
@@ -74,12 +70,8 @@ public function updateApp($appId, $hub, $title, $maxUsers = null, $mergePublishR
7470
$params['mergePublishRtmp'] = $mergePublishRtmp;
7571
}
7672
$body = json_encode($params);
77-
list($ret, $err) = $this->post($url, $body);
78-
if ($err !== null) {
79-
return $err;
80-
} else {
81-
return $ret;
82-
}
73+
$ret = $this->post($url, $body);
74+
return $ret;
8375
}
8476

8577
/*
@@ -88,12 +80,8 @@ public function updateApp($appId, $hub, $title, $maxUsers = null, $mergePublishR
8880
public function getApp($appId)
8981
{
9082
$url = $this->_baseURL . '/' . $appId;
91-
list($ret, $err) = $this->get($url);
92-
if ($err !== null) {
93-
return $err;
94-
} else {
95-
return $ret;
96-
}
83+
$ret = $this->get($url);
84+
return $ret;
9785
}
9886

9987
/*
@@ -114,12 +102,8 @@ public function deleteApp($appId)
114102
public function getappUserNum($appId, $roomName)
115103
{
116104
$url = sprintf("%s/%s/rooms/%s/users", $this->_baseURL, $appId, $roomName);
117-
list($ret, $err) = $this->get($url);
118-
if ($err !== null) {
119-
return $err;
120-
} else {
121-
return $ret;
122-
}
105+
$ret = $this->get($url);
106+
return $ret;
123107
}
124108

125109
/*
@@ -160,12 +144,8 @@ public function listRooms($appId, $prefix = null, $offset = null, $limit = null)
160144
} else {
161145
$url = sprintf("%s/%s/rooms", $this->_baseURL, $appId);
162146
}
163-
list($ret, $err) = $this->get($url);
164-
if ($err !== null) {
165-
return $err;
166-
} else {
167-
return $ret;
168-
}
147+
$ret = $this->get($url);
148+
return $ret;
169149
}
170150

171151
/*
@@ -189,9 +169,8 @@ public function appToken($appId, $roomName, $userId, $expireAt, $permission)
189169
return $this->auth->accessKey . ":" . $encodedSign . ":" . $encodedappAccess;
190170
}
191171

192-
private function get($url)
172+
private function get($url, $cType = null)
193173
{
194-
$cType = null;
195174
$rtcToken = $this->auth->authorizationV2($url, "GET", $body, $cType);
196175
$rtcToken['Content-Type'] = $cType;
197176
$ret = Client::get($url, $rtcToken);
@@ -201,9 +180,8 @@ private function get($url)
201180
return array($ret->json(), null);
202181
}
203182

204-
private function delete($url)
183+
private function delete($url, $cType = 'application/json')
205184
{
206-
$cType = 'application/json';
207185
$rtcToken = $this->auth->authorizationV2($url, "DELETE", $body, $cType);
208186
$rtcToken['Content-Type'] = $cType;
209187
$ret = Client::delete($url, $rtcToken);
@@ -213,9 +191,8 @@ private function delete($url)
213191
return array($ret->json(), null);
214192
}
215193

216-
private function post($url, $body)
194+
private function post($url, $body, $cType = 'application/json')
217195
{
218-
$cType = 'application/json';
219196
$rtcToken = $this->auth->authorizationV2($url, "POST", $body, $cType);
220197
$rtcToken['Content-Type'] = $cType;
221198
$ret = Client::post($url, $body, $rtcToken);

0 commit comments

Comments
 (0)