Skip to content

Commit 0bad494

Browse files
committed
调用core的签名类
1 parent a65ca98 commit 0bad494

File tree

5 files changed

+80
-134
lines changed

5 files changed

+80
-134
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"require": {
2222
"php": ">=5.5.0",
23-
"guzzlehttp/guzzle": "~6.0"
23+
"aliyunapi/php-aliyun-open-api-core": "~1.0"
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "4.*"

src/Client.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace aliyun\live;
2323

24-
use aliyun\live\auth\ShaHmac1Signer;
24+
use aliyun\core\auth\ShaHmac1Signer;
2525

2626
class Client
2727
{
@@ -39,9 +39,7 @@ class Client
3939
* @var \aliyun\core\auth\SignerInterface 签名算法实例
4040
*/
4141
public $signer;
42-
43-
44-
42+
4543
/**
4644
* @var \GuzzleHttp\Client
4745
*/
@@ -81,7 +79,6 @@ public function getHttpClient()
8179
return $this->_httpClient;
8280
}
8381

84-
8582
/**
8683
* @param array $params
8784
* @return string
@@ -132,29 +129,5 @@ protected function composeUrl($url, array $params = [])
132129
return $url;
133130
}
134131

135-
/**
136-
* @param array $parameters
137-
* @return string
138-
*/
139-
private function computeSignature($parameters)
140-
{
141-
ksort($parameters);
142-
$canonicalizedQueryString = '';
143-
foreach ($parameters as $key => $value) {
144-
$canonicalizedQueryString .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($value);
145-
}
146-
$stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
147-
$signature = $this->signer->signString($stringToSign, $this->accessSecret . "&");
148-
149-
return $signature;
150-
}
151132

152-
protected function percentEncode($str)
153-
{
154-
$res = urlencode($str);
155-
$res = preg_replace('/\+/', '%20', $res);
156-
$res = preg_replace('/\*/', '%2A', $res);
157-
$res = preg_replace('/%7E/', '~', $res);
158-
return $res;
159-
}
160133
}

src/Request.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @link http://www.tintsoft.com/
4+
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd.
5+
* @license http://www.tintsoft.com/license/
6+
*/
7+
namespace aliyun\live;
8+
9+
class Request
10+
{
11+
protected $queryParameters = [
12+
13+
];
14+
15+
public function __construct($p)
16+
{
17+
$this->queryParameters = [
18+
'Format' => 'JSON',
19+
'Version' => '2016-11-01',
20+
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
21+
'SignatureNonce' => uniqid(),
22+
];
23+
}
24+
25+
/**
26+
* 通过__call转发请求
27+
* @param string $name 方法名
28+
* @param array $arguments 参数
29+
* @return
30+
*/
31+
public function __call($name, $arguments)
32+
{
33+
$action = ucfirst($name);
34+
$params = [];
35+
if (is_array($arguments) && !empty($arguments)) {
36+
$params = (array)$arguments[0];
37+
}
38+
$params['Action'] = $action;
39+
return $this->_dispatchRequest($params);
40+
}
41+
42+
/**
43+
* 发起接口请求
44+
* @param array $params 接口参数
45+
* @return
46+
*/
47+
protected function _dispatchRequest($params)
48+
{
49+
50+
}
51+
52+
/**
53+
* @param array $parameters
54+
* @return string
55+
*/
56+
private function computeSignature($parameters)
57+
{
58+
ksort($parameters);
59+
$canonicalizedQueryString = '';
60+
foreach ($parameters as $key => $value) {
61+
$canonicalizedQueryString .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($value);
62+
}
63+
$stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
64+
$signature = $this->signer->signString($stringToSign, $this->accessSecret . "&");
65+
66+
return $signature;
67+
}
68+
69+
protected function percentEncode($str)
70+
{
71+
$res = urlencode($str);
72+
$res = preg_replace('/\+/', '%20', $res);
73+
$res = preg_replace('/\*/', '%2A', $res);
74+
$res = preg_replace('/%7E/', '~', $res);
75+
return $res;
76+
}
77+
}

src/auth/ShaHmac1Signer.php

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

src/auth/SignerInterface.php

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

0 commit comments

Comments
 (0)