23
23
24
24
use aliyun \core \auth \ShaHmac1Signer ;
25
25
26
- class Client
26
+ class Client extends \ aliyun \ core \Client
27
27
{
28
28
/**
29
29
* @var string
@@ -45,40 +45,11 @@ class Client
45
45
*/
46
46
public $ _httpClient ;
47
47
48
- /**
49
- * Request constructor.
50
- * @param array $config
51
- */
52
- public function __construct ($ config = [])
48
+ public function init ()
53
49
{
54
- foreach ($ config as $ name => $ value ) {
55
- $ this ->{$ name } = $ value ;
56
- }
57
- $ this ->init ();
58
- }
59
-
60
- public function init (){
61
50
$ this ->signer = new ShaHmac1Signer ();
62
51
}
63
52
64
- /**
65
- * 获取Http Client
66
- * @return \GuzzleHttp\Client
67
- */
68
- public function getHttpClient ()
69
- {
70
- if (!is_object ($ this ->_httpClient )) {
71
- $ this ->_httpClient = new \GuzzleHttp \Client ([
72
- 'verify ' => false ,
73
- 'http_errors ' => false ,
74
- 'connect_timeout ' => 3 ,
75
- 'read_timeout ' => 10 ,
76
- 'debug ' => false ,
77
- ]);
78
- }
79
- return $ this ->_httpClient ;
80
- }
81
-
82
53
/**
83
54
* @param array $params
84
55
* @return string
@@ -129,5 +100,30 @@ protected function composeUrl($url, array $params = [])
129
100
return $ url ;
130
101
}
131
102
103
+ /**
104
+ * @param array $parameters
105
+ * @return string
106
+ */
107
+ private function computeSignature ($ parameters )
108
+ {
109
+ ksort ($ parameters );
110
+ $ canonicalizedQueryString = '' ;
111
+ foreach ($ parameters as $ key => $ value ) {
112
+ $ canonicalizedQueryString .= '& ' . $ this ->percentEncode ($ key ) . '= ' . $ this ->percentEncode ($ value );
113
+ }
114
+ $ stringToSign = 'GET&%2F& ' . $ this ->percentencode (substr ($ canonicalizedQueryString , 1 ));
115
+ $ signature = $ this ->signer ->signString ($ stringToSign , $ this ->accessSecret . "& " );
116
+
117
+ return $ signature ;
118
+ }
119
+
120
+ protected function percentEncode ($ str )
121
+ {
122
+ $ res = urlencode ($ str );
123
+ $ res = preg_replace ('/\+/ ' , '%20 ' , $ res );
124
+ $ res = preg_replace ('/\*/ ' , '%2A ' , $ res );
125
+ $ res = preg_replace ('/%7E/ ' , '~ ' , $ res );
126
+ return $ res ;
127
+ }
132
128
133
129
}
0 commit comments