|
5 | 5 | namespace AlibabaCloud\SDK\Cloudauthintl\V20220809; |
6 | 6 |
|
7 | 7 | use AlibabaCloud\Dara\Dara; |
| 8 | +use AlibabaCloud\Dara\Exception\DaraException; |
| 9 | +use AlibabaCloud\Dara\Exception\DaraUnableRetryException; |
8 | 10 | use AlibabaCloud\Dara\Models\FileField; |
9 | 11 | use AlibabaCloud\Dara\Models\RuntimeOptions; |
10 | 12 | use AlibabaCloud\Dara\Request; |
| 13 | +use AlibabaCloud\Dara\RetryPolicy\RetryPolicyContext; |
11 | 14 | use AlibabaCloud\Dara\Util\FormUtil; |
12 | 15 | use AlibabaCloud\Dara\Util\StreamUtil; |
13 | 16 | use AlibabaCloud\Dara\Util\XML; |
@@ -105,48 +108,98 @@ public function __construct($config) |
105 | 108 | } |
106 | 109 |
|
107 | 110 | /** |
108 | | - * @param string $bucketName |
109 | | - * @param mixed[] $form |
| 111 | + * @param string $bucketName |
| 112 | + * @param mixed[] $form |
| 113 | + * @param RuntimeOptions $runtime |
110 | 114 | * |
111 | 115 | * @return mixed[] |
112 | 116 | */ |
113 | | - public function _postOSSObject($bucketName, $form) |
114 | | - { |
115 | | - $_request = new Request(); |
116 | | - $boundary = FormUtil::getBoundary(); |
117 | | - $_request->protocol = 'HTTPS'; |
118 | | - $_request->method = 'POST'; |
119 | | - $_request->pathname = '/'; |
120 | | - $_request->headers = [ |
121 | | - 'host' => '' . @$form['host'], |
122 | | - 'date' => Utils::getDateUTCString(), |
123 | | - 'user-agent' => Utils::getUserAgent(''), |
| 117 | + public function _postOSSObject($bucketName, $form, $runtime) |
| 118 | + { |
| 119 | + $_runtime = [ |
| 120 | + 'key' => '' . ($runtime->key ?: $this->_key), |
| 121 | + 'cert' => '' . ($runtime->cert ?: $this->_cert), |
| 122 | + 'ca' => '' . ($runtime->ca ?: $this->_ca), |
| 123 | + 'readTimeout' => (($runtime->readTimeout ?: $this->_readTimeout) + 0), |
| 124 | + 'connectTimeout' => (($runtime->connectTimeout ?: $this->_connectTimeout) + 0), |
| 125 | + 'httpProxy' => '' . ($runtime->httpProxy ?: $this->_httpProxy), |
| 126 | + 'httpsProxy' => '' . ($runtime->httpsProxy ?: $this->_httpsProxy), |
| 127 | + 'noProxy' => '' . ($runtime->noProxy ?: $this->_noProxy), |
| 128 | + 'socks5Proxy' => '' . ($runtime->socks5Proxy ?: $this->_socks5Proxy), |
| 129 | + 'socks5NetWork' => '' . ($runtime->socks5NetWork ?: $this->_socks5NetWork), |
| 130 | + 'maxIdleConns' => (($runtime->maxIdleConns ?: $this->_maxIdleConns) + 0), |
| 131 | + 'retryOptions' => $this->_retryOptions, |
| 132 | + 'ignoreSSL' => (bool) (($runtime->ignoreSSL ?: false)), |
| 133 | + 'tlsMinVersion' => $this->_tlsMinVersion, |
124 | 134 | ]; |
125 | | - @$_request->headers['content-type'] = 'multipart/form-data; boundary=' . $boundary . ''; |
126 | | - $_request->body = FormUtil::toFileForm($form, $boundary); |
127 | | - $_response = Dara::send($_request); |
128 | | - |
129 | | - $respMap = null; |
130 | | - $bodyStr = StreamUtil::readAsString($_response->body); |
131 | | - if (($_response->statusCode >= 400) && ($_response->statusCode < 600)) { |
132 | | - $respMap = XML::parseXml($bodyStr, null); |
133 | | - $err = @$respMap['Error']; |
134 | | - |
135 | | - throw new ClientException([ |
136 | | - 'code' => '' . @$err['Code'], |
137 | | - 'message' => '' . @$err['Message'], |
138 | | - 'data' => [ |
139 | | - 'httpCode' => $_response->statusCode, |
140 | | - 'requestId' => '' . @$err['RequestId'], |
141 | | - 'hostId' => '' . @$err['HostId'], |
142 | | - ], |
143 | | - ]); |
144 | | - } |
145 | | - |
146 | | - $respMap = XML::parseXml($bodyStr, null); |
147 | 135 |
|
148 | | - return Dara::merge([ |
149 | | - ], $respMap); |
| 136 | + $_retriesAttempted = 0; |
| 137 | + $_lastRequest = null; |
| 138 | + $_lastResponse = null; |
| 139 | + $_context = new RetryPolicyContext([ |
| 140 | + 'retriesAttempted' => $_retriesAttempted, |
| 141 | + ]); |
| 142 | + while (Dara::shouldRetry($_runtime['retryOptions'], $_context)) { |
| 143 | + if ($_retriesAttempted > 0) { |
| 144 | + $_backoffTime = Dara::getBackoffDelay($_runtime['retryOptions'], $_context); |
| 145 | + if ($_backoffTime > 0) { |
| 146 | + Dara::sleep($_backoffTime); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + ++$_retriesAttempted; |
| 151 | + |
| 152 | + try { |
| 153 | + $_request = new Request(); |
| 154 | + $boundary = FormUtil::getBoundary(); |
| 155 | + $_request->protocol = 'HTTPS'; |
| 156 | + $_request->method = 'POST'; |
| 157 | + $_request->pathname = '/'; |
| 158 | + $_request->headers = [ |
| 159 | + 'host' => '' . @$form['host'], |
| 160 | + 'date' => Utils::getDateUTCString(), |
| 161 | + 'user-agent' => Utils::getUserAgent(''), |
| 162 | + ]; |
| 163 | + @$_request->headers['content-type'] = 'multipart/form-data; boundary=' . $boundary . ''; |
| 164 | + $_request->body = FormUtil::toFileForm($form, $boundary); |
| 165 | + $_lastRequest = $_request; |
| 166 | + $_response = Dara::send($_request, $_runtime); |
| 167 | + $_lastResponse = $_response; |
| 168 | + |
| 169 | + $respMap = null; |
| 170 | + $bodyStr = StreamUtil::readAsString($_response->body); |
| 171 | + if (($_response->statusCode >= 400) && ($_response->statusCode < 600)) { |
| 172 | + $respMap = XML::parseXml($bodyStr, null); |
| 173 | + $err = @$respMap['Error']; |
| 174 | + |
| 175 | + throw new ClientException([ |
| 176 | + 'code' => '' . @$err['Code'], |
| 177 | + 'message' => '' . @$err['Message'], |
| 178 | + 'data' => [ |
| 179 | + 'httpCode' => $_response->statusCode, |
| 180 | + 'requestId' => '' . @$err['RequestId'], |
| 181 | + 'hostId' => '' . @$err['HostId'], |
| 182 | + ], |
| 183 | + ]); |
| 184 | + } |
| 185 | + |
| 186 | + $respMap = XML::parseXml($bodyStr, null); |
| 187 | + |
| 188 | + return Dara::merge([ |
| 189 | + ], $respMap); |
| 190 | + } catch (DaraException $e) { |
| 191 | + $_context = new RetryPolicyContext([ |
| 192 | + 'retriesAttempted' => $_retriesAttempted, |
| 193 | + 'lastRequest' => $_lastRequest, |
| 194 | + 'lastResponse' => $_lastResponse, |
| 195 | + 'exception' => $e, |
| 196 | + ]); |
| 197 | + |
| 198 | + continue; |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + throw new DaraUnableRetryException($_context); |
150 | 203 | } |
151 | 204 |
|
152 | 205 | /** |
@@ -1160,7 +1213,7 @@ public function credentialVerifyIntlAdvance($request, $runtime) |
1160 | 1213 | 'file' => $fileObj, |
1161 | 1214 | 'success_action_status' => '201', |
1162 | 1215 | ]; |
1163 | | - $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader); |
| 1216 | + $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader, $runtime); |
1164 | 1217 | $credentialVerifyIntlReq->imageFile = 'http://' . @$authResponseBody['Bucket'] . '.' . @$authResponseBody['Endpoint'] . '/' . @$authResponseBody['ObjectKey'] . ''; |
1165 | 1218 | } |
1166 | 1219 |
|
@@ -1424,7 +1477,7 @@ public function deepfakeDetectIntlStreamAdvance($request, $runtime) |
1424 | 1477 | 'file' => $fileObj, |
1425 | 1478 | 'success_action_status' => '201', |
1426 | 1479 | ]; |
1427 | | - $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader); |
| 1480 | + $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader, $runtime); |
1428 | 1481 | $deepfakeDetectIntlStreamReq->faceFile = 'http://' . @$authResponseBody['Bucket'] . '.' . @$authResponseBody['Endpoint'] . '/' . @$authResponseBody['ObjectKey'] . ''; |
1429 | 1482 | } |
1430 | 1483 |
|
@@ -1731,6 +1784,10 @@ public function docOcrMaxWithOptions($request, $runtime) |
1731 | 1784 | } |
1732 | 1785 |
|
1733 | 1786 | $body = []; |
| 1787 | + if (null !== $request->authorize) { |
| 1788 | + @$body['Authorize'] = $request->authorize; |
| 1789 | + } |
| 1790 | + |
1734 | 1791 | if (null !== $request->docPage) { |
1735 | 1792 | @$body['DocPage'] = $request->docPage; |
1736 | 1793 | } |
|
0 commit comments