Skip to content

Commit 53bfd3a

Browse files
committed
Merge pull request #117 from longbai/7.0
rename function
2 parents f67af3f + ceea222 commit 53bfd3a

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/Qiniu/Auth.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public function __construct($accessKey, $secretKey)
1414
$this->secretKey = $secretKey;
1515
}
1616

17-
public function token($data)
17+
public function sign($data)
1818
{
1919
$hmac = hash_hmac('sha1', $data, $this->secretKey, true);
2020
return $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac);
2121
}
2222

23-
public function tokenWithData($data)
23+
public function signWithData($data)
2424
{
2525
$data = \Qiniu\base64_urlSafeEncode($data);
26-
return $this->token($data) . ':' . $data;
26+
return $this->sign($data) . ':' . $data;
2727
}
2828

29-
public function tokenOfRequest($urlString, $body, $contentType = null)
29+
public function signRequest($urlString, $body, $contentType = null)
3030
{
3131
$url = parse_url($urlString);
3232
$data = '';
@@ -42,12 +42,12 @@ public function tokenOfRequest($urlString, $body, $contentType = null)
4242
($contentType == 'application/x-www-form-urlencoded') || $contentType == 'application/json') {
4343
$data .= $body;
4444
}
45-
return $this->token($data);
45+
return $this->sign($data);
4646
}
4747

4848
public function verifyCallback($contentType, $originAuthorization, $url, $body)
4949
{
50-
$authorization = 'QBox ' . $this->tokenOfRequest($url, $body, $contentType);
50+
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
5151
return $originAuthorization === $authorization;
5252
}
5353

@@ -63,7 +63,7 @@ public function privateDownloadUrl($baseUrl, $expires = 3600)
6363
}
6464
$baseUrl .= $deadline;
6565

66-
$token = $this->token($baseUrl);
66+
$token = $this->sign($baseUrl);
6767
return "$baseUrl&token=$token";
6868
}
6969

@@ -84,7 +84,7 @@ public function uploadToken(
8484
$args['scope'] = $scope;
8585
$args['deadline'] = $deadline;
8686
$b = json_encode($args);
87-
return $this->tokenWithData($b);
87+
return $this->signWithData($b);
8888
}
8989

9090
private static $policyFields = array(
@@ -132,7 +132,7 @@ private static function copyPolicy($policy, $originPolicy, $strictPolicy)
132132

133133
public function authorization($url, $body = null, $contentType = null)
134134
{
135-
$authorization = 'QBox ' . $this->tokenOfRequest($url, $body, $contentType);
135+
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
136136
return array('Authorization' => $authorization);
137137
}
138138
}

tests/Qiniu/Tests/AuthTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ function time()
2222
class AuthTest extends \PHPUnit_Framework_TestCase
2323
{
2424

25-
public function testToken()
25+
public function testSign()
2626
{
2727
global $dummyAuth;
28-
$token = $dummyAuth->token('test');
28+
$token = $dummyAuth->sign('test');
2929
$this->assertEquals('abcdefghklmnopq:mSNBTR7uS2crJsyFr2Amwv1LaYg=', $token);
3030
}
3131

32-
public function testTokenWithData()
32+
public function testSignWithData()
3333
{
3434
global $dummyAuth;
35-
$token = $dummyAuth->tokenWithData('test');
35+
$token = $dummyAuth->signWithData('test');
3636
$this->assertEquals('abcdefghklmnopq:-jP8eEV9v48MkYiBGs81aDxl60E=:dGVzdA==', $token);
3737
}
3838

39-
public function testTokenOfRequest()
39+
public function testSignRequest()
4040
{
4141
global $dummyAuth;
42-
$token = $dummyAuth->tokenOfRequest('http://www.qiniu.com?go=1', 'test', '');
42+
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', '');
4343
$this->assertEquals('abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y=', $token);
4444
$ctype = 'application/x-www-form-urlencoded';
45-
$token = $dummyAuth->tokenOfRequest('http://www.qiniu.com?go=1', 'test', $ctype);
45+
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', $ctype);
4646
$this->assertEquals($token, 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4=');
4747
}
4848

tests/Qiniu/Tests/HttpTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testGet()
1616
public function testGetQiniu()
1717
{
1818
$response = Client::get('up.qiniu.com');
19-
$this->assertEquals($response->statusCode, 405);
19+
$this->assertEquals(405, $response->statusCode);
2020
$this->assertNotNull($response->body);
2121
$this->assertNotNull($response->xReqId());
2222
$this->assertNotNull($response->xLog());

0 commit comments

Comments
 (0)