2323
2424use aliyun \core \auth \ShaHmac1Signer ;
2525
26- class Client
26+ class Client extends \ aliyun \ core \Client
2727{
2828 /**
2929 * @var string
@@ -45,40 +45,11 @@ class Client
4545 */
4646 public $ _httpClient ;
4747
48- /**
49- * Request constructor.
50- * @param array $config
51- */
52- public function __construct ($ config = [])
48+ public function init ()
5349 {
54- foreach ($ config as $ name => $ value ) {
55- $ this ->{$ name } = $ value ;
56- }
57- $ this ->init ();
58- }
59-
60- public function init (){
6150 $ this ->signer = new ShaHmac1Signer ();
6251 }
6352
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-
8253 /**
8354 * @param array $params
8455 * @return string
@@ -129,5 +100,30 @@ protected function composeUrl($url, array $params = [])
129100 return $ url ;
130101 }
131102
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+ }
132128
133129}
0 commit comments