|
5 | 5 | namespace AlibabaCloud\SDK\Dm\V20151123; |
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; |
@@ -178,48 +181,98 @@ public function __construct($config) |
178 | 181 | } |
179 | 182 |
|
180 | 183 | /** |
181 | | - * @param string $bucketName |
182 | | - * @param mixed[] $form |
| 184 | + * @param string $bucketName |
| 185 | + * @param mixed[] $form |
| 186 | + * @param RuntimeOptions $runtime |
183 | 187 | * |
184 | 188 | * @return mixed[] |
185 | 189 | */ |
186 | | - public function _postOSSObject($bucketName, $form) |
187 | | - { |
188 | | - $_request = new Request(); |
189 | | - $boundary = FormUtil::getBoundary(); |
190 | | - $_request->protocol = 'HTTPS'; |
191 | | - $_request->method = 'POST'; |
192 | | - $_request->pathname = '/'; |
193 | | - $_request->headers = [ |
194 | | - 'host' => '' . @$form['host'], |
195 | | - 'date' => Utils::getDateUTCString(), |
196 | | - 'user-agent' => Utils::getUserAgent(''), |
| 190 | + public function _postOSSObject($bucketName, $form, $runtime) |
| 191 | + { |
| 192 | + $_runtime = [ |
| 193 | + 'key' => '' . ($runtime->key ?: $this->_key), |
| 194 | + 'cert' => '' . ($runtime->cert ?: $this->_cert), |
| 195 | + 'ca' => '' . ($runtime->ca ?: $this->_ca), |
| 196 | + 'readTimeout' => (($runtime->readTimeout ?: $this->_readTimeout) + 0), |
| 197 | + 'connectTimeout' => (($runtime->connectTimeout ?: $this->_connectTimeout) + 0), |
| 198 | + 'httpProxy' => '' . ($runtime->httpProxy ?: $this->_httpProxy), |
| 199 | + 'httpsProxy' => '' . ($runtime->httpsProxy ?: $this->_httpsProxy), |
| 200 | + 'noProxy' => '' . ($runtime->noProxy ?: $this->_noProxy), |
| 201 | + 'socks5Proxy' => '' . ($runtime->socks5Proxy ?: $this->_socks5Proxy), |
| 202 | + 'socks5NetWork' => '' . ($runtime->socks5NetWork ?: $this->_socks5NetWork), |
| 203 | + 'maxIdleConns' => (($runtime->maxIdleConns ?: $this->_maxIdleConns) + 0), |
| 204 | + 'retryOptions' => $this->_retryOptions, |
| 205 | + 'ignoreSSL' => (bool) (($runtime->ignoreSSL ?: false)), |
| 206 | + 'tlsMinVersion' => $this->_tlsMinVersion, |
197 | 207 | ]; |
198 | | - @$_request->headers['content-type'] = 'multipart/form-data; boundary=' . $boundary . ''; |
199 | | - $_request->body = FormUtil::toFileForm($form, $boundary); |
200 | | - $_response = Dara::send($_request); |
201 | 208 |
|
202 | | - $respMap = null; |
203 | | - $bodyStr = StreamUtil::readAsString($_response->body); |
204 | | - if (($_response->statusCode >= 400) && ($_response->statusCode < 600)) { |
205 | | - $respMap = XML::parseXml($bodyStr, null); |
206 | | - $err = @$respMap['Error']; |
| 209 | + $_retriesAttempted = 0; |
| 210 | + $_lastRequest = null; |
| 211 | + $_lastResponse = null; |
| 212 | + $_context = new RetryPolicyContext([ |
| 213 | + 'retriesAttempted' => $_retriesAttempted, |
| 214 | + ]); |
| 215 | + while (Dara::shouldRetry($_runtime['retryOptions'], $_context)) { |
| 216 | + if ($_retriesAttempted > 0) { |
| 217 | + $_backoffTime = Dara::getBackoffDelay($_runtime['retryOptions'], $_context); |
| 218 | + if ($_backoffTime > 0) { |
| 219 | + Dara::sleep($_backoffTime); |
| 220 | + } |
| 221 | + } |
207 | 222 |
|
208 | | - throw new ClientException([ |
209 | | - 'code' => '' . @$err['Code'], |
210 | | - 'message' => '' . @$err['Message'], |
211 | | - 'data' => [ |
212 | | - 'httpCode' => $_response->statusCode, |
213 | | - 'requestId' => '' . @$err['RequestId'], |
214 | | - 'hostId' => '' . @$err['HostId'], |
215 | | - ], |
216 | | - ]); |
217 | | - } |
| 223 | + ++$_retriesAttempted; |
| 224 | + |
| 225 | + try { |
| 226 | + $_request = new Request(); |
| 227 | + $boundary = FormUtil::getBoundary(); |
| 228 | + $_request->protocol = 'HTTPS'; |
| 229 | + $_request->method = 'POST'; |
| 230 | + $_request->pathname = '/'; |
| 231 | + $_request->headers = [ |
| 232 | + 'host' => '' . @$form['host'], |
| 233 | + 'date' => Utils::getDateUTCString(), |
| 234 | + 'user-agent' => Utils::getUserAgent(''), |
| 235 | + ]; |
| 236 | + @$_request->headers['content-type'] = 'multipart/form-data; boundary=' . $boundary . ''; |
| 237 | + $_request->body = FormUtil::toFileForm($form, $boundary); |
| 238 | + $_lastRequest = $_request; |
| 239 | + $_response = Dara::send($_request, $_runtime); |
| 240 | + $_lastResponse = $_response; |
| 241 | + |
| 242 | + $respMap = null; |
| 243 | + $bodyStr = StreamUtil::readAsString($_response->body); |
| 244 | + if (($_response->statusCode >= 400) && ($_response->statusCode < 600)) { |
| 245 | + $respMap = XML::parseXml($bodyStr, null); |
| 246 | + $err = @$respMap['Error']; |
| 247 | + |
| 248 | + throw new ClientException([ |
| 249 | + 'code' => '' . @$err['Code'], |
| 250 | + 'message' => '' . @$err['Message'], |
| 251 | + 'data' => [ |
| 252 | + 'httpCode' => $_response->statusCode, |
| 253 | + 'requestId' => '' . @$err['RequestId'], |
| 254 | + 'hostId' => '' . @$err['HostId'], |
| 255 | + ], |
| 256 | + ]); |
| 257 | + } |
| 258 | + |
| 259 | + $respMap = XML::parseXml($bodyStr, null); |
218 | 260 |
|
219 | | - $respMap = XML::parseXml($bodyStr, null); |
| 261 | + return Dara::merge([ |
| 262 | + ], $respMap); |
| 263 | + } catch (DaraException $e) { |
| 264 | + $_context = new RetryPolicyContext([ |
| 265 | + 'retriesAttempted' => $_retriesAttempted, |
| 266 | + 'lastRequest' => $_lastRequest, |
| 267 | + 'lastResponse' => $_lastResponse, |
| 268 | + 'exception' => $e, |
| 269 | + ]); |
220 | 270 |
|
221 | | - return Dara::merge([ |
222 | | - ], $respMap); |
| 271 | + continue; |
| 272 | + } |
| 273 | + } |
| 274 | + |
| 275 | + throw new DaraUnableRetryException($_context); |
223 | 276 | } |
224 | 277 |
|
225 | 278 | /** |
@@ -5056,7 +5109,7 @@ public function sendValidateFileAdvance($request, $runtime) |
5056 | 5109 | 'file' => $fileObj, |
5057 | 5110 | 'success_action_status' => '201', |
5058 | 5111 | ]; |
5059 | | - $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader); |
| 5112 | + $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader, $runtime); |
5060 | 5113 | $sendValidateFileReq->fileUrl = 'http://' . @$authResponseBody['Bucket'] . '.' . @$authResponseBody['Endpoint'] . '/' . @$authResponseBody['ObjectKey'] . ''; |
5061 | 5114 | } |
5062 | 5115 |
|
@@ -5564,7 +5617,7 @@ public function singleSendMailAdvance($request, $runtime) |
5564 | 5617 | 'file' => $fileObj, |
5565 | 5618 | 'success_action_status' => '201', |
5566 | 5619 | ]; |
5567 | | - $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader); |
| 5620 | + $this->_postOSSObject(@$authResponseBody['Bucket'], $ossHeader, $runtime); |
5568 | 5621 | $tmpObj = @$singleSendMailReq->attachments[$i0]; |
5569 | 5622 | $tmpObj->attachmentUrl = 'http://' . @$authResponseBody['Bucket'] . '.' . @$authResponseBody['Endpoint'] . '/' . @$authResponseBody['ObjectKey'] . ''; |
5570 | 5623 | ++$i0; |
@@ -5789,6 +5842,10 @@ public function validateEmailWithOptions($request, $runtime) |
5789 | 5842 | { |
5790 | 5843 | $request->validate(); |
5791 | 5844 | $query = []; |
| 5845 | + if (null !== $request->checkGraylist) { |
| 5846 | + @$query['CheckGraylist'] = $request->checkGraylist; |
| 5847 | + } |
| 5848 | + |
5792 | 5849 | if (null !== $request->email) { |
5793 | 5850 | @$query['Email'] = $request->email; |
5794 | 5851 | } |
|
0 commit comments