OpenApiClient.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. <?php
  2. // This file is auto-generated, don't edit it. Thanks.
  3. namespace Darabonba\OpenApi;
  4. use AlibabaCloud\Credentials\Credential;
  5. use AlibabaCloud\Credentials\Credential\Config;
  6. use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
  7. use AlibabaCloud\Tea\Exception\TeaError;
  8. use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
  9. use AlibabaCloud\Tea\Request;
  10. use AlibabaCloud\Tea\Tea;
  11. use AlibabaCloud\Tea\Utils\Utils;
  12. use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
  13. use AlibabaCloud\Tea\XML\XML;
  14. use Darabonba\GatewaySpi\Models\AttributeMap;
  15. use Darabonba\GatewaySpi\Models\InterceptorContext;
  16. use Darabonba\GatewaySpi\Models\InterceptorContext\configuration;
  17. use Darabonba\GatewaySpi\Models\InterceptorContext\response;
  18. use Darabonba\OpenApi\Models\OpenApiRequest;
  19. use Darabonba\OpenApi\Models\Params;
  20. use Exception;
  21. /**
  22. * This is for OpenApi SDK.
  23. */
  24. class OpenApiClient
  25. {
  26. protected $_endpoint;
  27. protected $_regionId;
  28. protected $_protocol;
  29. protected $_method;
  30. protected $_userAgent;
  31. protected $_endpointRule;
  32. protected $_endpointMap;
  33. protected $_suffix;
  34. protected $_readTimeout;
  35. protected $_connectTimeout;
  36. protected $_httpProxy;
  37. protected $_httpsProxy;
  38. protected $_socks5Proxy;
  39. protected $_socks5NetWork;
  40. protected $_noProxy;
  41. protected $_network;
  42. protected $_productId;
  43. protected $_maxIdleConns;
  44. protected $_endpointType;
  45. protected $_openPlatformEndpoint;
  46. protected $_credential;
  47. protected $_signatureVersion;
  48. protected $_signatureAlgorithm;
  49. protected $_headers;
  50. protected $_spi;
  51. protected $_globalParameters;
  52. /**
  53. * Init client with Config.
  54. *
  55. * @param config config contains the necessary information to create a client
  56. */
  57. public function __construct($config)
  58. {
  59. if (Utils::isUnset($config)) {
  60. throw new TeaError(['code' => 'ParameterMissing', 'message' => "'config' can not be unset"]);
  61. }
  62. if (!Utils::empty_($config->accessKeyId) && !Utils::empty_($config->accessKeySecret)) {
  63. if (!Utils::empty_($config->securityToken)) {
  64. $config->type = 'sts';
  65. } else {
  66. $config->type = 'access_key';
  67. }
  68. $credentialConfig = new Config([
  69. 'accessKeyId' => $config->accessKeyId,
  70. 'type' => $config->type,
  71. 'accessKeySecret' => $config->accessKeySecret,
  72. 'securityToken' => $config->securityToken,
  73. ]);
  74. $this->_credential = new Credential($credentialConfig);
  75. } elseif (!Utils::isUnset($config->credential)) {
  76. $this->_credential = $config->credential;
  77. }
  78. $this->_endpoint = $config->endpoint;
  79. $this->_endpointType = $config->endpointType;
  80. $this->_network = $config->network;
  81. $this->_suffix = $config->suffix;
  82. $this->_protocol = $config->protocol;
  83. $this->_method = $config->method;
  84. $this->_regionId = $config->regionId;
  85. $this->_userAgent = $config->userAgent;
  86. $this->_readTimeout = $config->readTimeout;
  87. $this->_connectTimeout = $config->connectTimeout;
  88. $this->_httpProxy = $config->httpProxy;
  89. $this->_httpsProxy = $config->httpsProxy;
  90. $this->_noProxy = $config->noProxy;
  91. $this->_socks5Proxy = $config->socks5Proxy;
  92. $this->_socks5NetWork = $config->socks5NetWork;
  93. $this->_maxIdleConns = $config->maxIdleConns;
  94. $this->_signatureVersion = $config->signatureVersion;
  95. $this->_signatureAlgorithm = $config->signatureAlgorithm;
  96. $this->_globalParameters = $config->globalParameters;
  97. }
  98. /**
  99. * Encapsulate the request and invoke the network.
  100. *
  101. * @param string $action api name
  102. * @param string $version product version
  103. * @param string $protocol http or https
  104. * @param string $method e.g. GET
  105. * @param string $authType authorization type e.g. AK
  106. * @param string $bodyType response body type e.g. String
  107. * @param OpenApiRequest $request object of OpenApiRequest
  108. * @param RuntimeOptions $runtime which controls some details of call api, such as retry times
  109. *
  110. * @return array the response
  111. *
  112. * @throws TeaError
  113. * @throws Exception
  114. * @throws TeaUnableRetryError
  115. */
  116. public function doRPCRequest($action, $version, $protocol, $method, $authType, $bodyType, $request, $runtime)
  117. {
  118. $request->validate();
  119. $runtime->validate();
  120. $_runtime = [
  121. 'timeouted' => 'retry',
  122. 'readTimeout' => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout),
  123. 'connectTimeout' => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout),
  124. 'httpProxy' => Utils::defaultString($runtime->httpProxy, $this->_httpProxy),
  125. 'httpsProxy' => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy),
  126. 'noProxy' => Utils::defaultString($runtime->noProxy, $this->_noProxy),
  127. 'socks5Proxy' => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy),
  128. 'socks5NetWork' => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork),
  129. 'maxIdleConns' => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns),
  130. 'retry' => [
  131. 'retryable' => $runtime->autoretry,
  132. 'maxAttempts' => Utils::defaultNumber($runtime->maxAttempts, 3),
  133. ],
  134. 'backoff' => [
  135. 'policy' => Utils::defaultString($runtime->backoffPolicy, 'no'),
  136. 'period' => Utils::defaultNumber($runtime->backoffPeriod, 1),
  137. ],
  138. 'ignoreSSL' => $runtime->ignoreSSL,
  139. ];
  140. $_lastRequest = null;
  141. $_lastException = null;
  142. $_now = time();
  143. $_retryTimes = 0;
  144. while (Tea::allowRetry(@$_runtime['retry'], $_retryTimes, $_now)) {
  145. if ($_retryTimes > 0) {
  146. $_backoffTime = Tea::getBackoffTime(@$_runtime['backoff'], $_retryTimes);
  147. if ($_backoffTime > 0) {
  148. Tea::sleep($_backoffTime);
  149. }
  150. }
  151. $_retryTimes = $_retryTimes + 1;
  152. try {
  153. $_request = new Request();
  154. $_request->protocol = Utils::defaultString($this->_protocol, $protocol);
  155. $_request->method = $method;
  156. $_request->pathname = '/';
  157. $_request->query = Tea::merge([
  158. 'Action' => $action,
  159. 'Format' => 'json',
  160. 'Version' => $version,
  161. 'Timestamp' => OpenApiUtilClient::getTimestamp(),
  162. 'SignatureNonce' => Utils::getNonce(),
  163. ], $request->query);
  164. $headers = $this->getRpcHeaders();
  165. if (Utils::isUnset($headers)) {
  166. // endpoint is setted in product client
  167. $_request->headers = [
  168. 'host' => $this->_endpoint,
  169. 'x-acs-version' => $version,
  170. 'x-acs-action' => $action,
  171. 'user-agent' => $this->getUserAgent(),
  172. ];
  173. } else {
  174. $_request->headers = Tea::merge([
  175. 'host' => $this->_endpoint,
  176. 'x-acs-version' => $version,
  177. 'x-acs-action' => $action,
  178. 'user-agent' => $this->getUserAgent(),
  179. ], $headers);
  180. }
  181. if (!Utils::isUnset($request->body)) {
  182. $m = Utils::assertAsMap($request->body);
  183. $tmp = Utils::anyifyMapValue(OpenApiUtilClient::query($m));
  184. $_request->body = Utils::toFormString($tmp);
  185. $_request->headers['content-type'] = 'application/x-www-form-urlencoded';
  186. }
  187. if (!Utils::equalString($authType, 'Anonymous')) {
  188. $accessKeyId = $this->getAccessKeyId();
  189. $accessKeySecret = $this->getAccessKeySecret();
  190. $securityToken = $this->getSecurityToken();
  191. if (!Utils::empty_($securityToken)) {
  192. $_request->query['SecurityToken'] = $securityToken;
  193. }
  194. $_request->query['SignatureMethod'] = 'HMAC-SHA1';
  195. $_request->query['SignatureVersion'] = '1.0';
  196. $_request->query['AccessKeyId'] = $accessKeyId;
  197. $t = null;
  198. if (!Utils::isUnset($request->body)) {
  199. $t = Utils::assertAsMap($request->body);
  200. }
  201. $signedParam = Tea::merge($_request->query, OpenApiUtilClient::query($t));
  202. $_request->query['Signature'] = OpenApiUtilClient::getRPCSignature($signedParam, $_request->method, $accessKeySecret);
  203. }
  204. $_lastRequest = $_request;
  205. $_response = Tea::send($_request, $_runtime);
  206. if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) {
  207. $_res = Utils::readAsJSON($_response->body);
  208. $err = Utils::assertAsMap($_res);
  209. $requestId = self::defaultAny(@$err['RequestId'], @$err['requestId']);
  210. throw new TeaError(['code' => ''.(string) (self::defaultAny(@$err['Code'], @$err['code'])).'', 'message' => 'code: '.(string) ($_response->statusCode).', '.(string) (self::defaultAny(@$err['Message'], @$err['message'])).' request id: '.(string) ($requestId).'', 'data' => $err]);
  211. }
  212. if (Utils::equalString($bodyType, 'binary')) {
  213. $resp = [
  214. 'body' => $_response->body,
  215. 'headers' => $_response->headers,
  216. ];
  217. return $resp;
  218. } elseif (Utils::equalString($bodyType, 'byte')) {
  219. $byt = Utils::readAsBytes($_response->body);
  220. return [
  221. 'body' => $byt,
  222. 'headers' => $_response->headers,
  223. ];
  224. } elseif (Utils::equalString($bodyType, 'string')) {
  225. $str = Utils::readAsString($_response->body);
  226. return [
  227. 'body' => $str,
  228. 'headers' => $_response->headers,
  229. ];
  230. } elseif (Utils::equalString($bodyType, 'json')) {
  231. $obj = Utils::readAsJSON($_response->body);
  232. $res = Utils::assertAsMap($obj);
  233. return [
  234. 'body' => $res,
  235. 'headers' => $_response->headers,
  236. ];
  237. } elseif (Utils::equalString($bodyType, 'array')) {
  238. $arr = Utils::readAsJSON($_response->body);
  239. return [
  240. 'body' => $arr,
  241. 'headers' => $_response->headers,
  242. ];
  243. } else {
  244. return [
  245. 'headers' => $_response->headers,
  246. ];
  247. }
  248. } catch (Exception $e) {
  249. if (!($e instanceof TeaError)) {
  250. $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
  251. }
  252. if (Tea::isRetryable($e)) {
  253. $_lastException = $e;
  254. continue;
  255. }
  256. throw $e;
  257. }
  258. }
  259. throw new TeaUnableRetryError($_lastRequest, $_lastException);
  260. }
  261. /**
  262. * Encapsulate the request and invoke the network.
  263. *
  264. * @param string $action api name
  265. * @param string $version product version
  266. * @param string $protocol http or https
  267. * @param string $method e.g. GET
  268. * @param string $authType authorization type e.g. AK
  269. * @param string $pathname pathname of every api
  270. * @param string $bodyType response body type e.g. String
  271. * @param OpenApiRequest $request object of OpenApiRequest
  272. * @param RuntimeOptions $runtime which controls some details of call api, such as retry times
  273. *
  274. * @return array the response
  275. *
  276. * @throws TeaError
  277. * @throws Exception
  278. * @throws TeaUnableRetryError
  279. */
  280. public function doROARequest($action, $version, $protocol, $method, $authType, $pathname, $bodyType, $request, $runtime)
  281. {
  282. $request->validate();
  283. $runtime->validate();
  284. $_runtime = [
  285. 'timeouted' => 'retry',
  286. 'readTimeout' => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout),
  287. 'connectTimeout' => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout),
  288. 'httpProxy' => Utils::defaultString($runtime->httpProxy, $this->_httpProxy),
  289. 'httpsProxy' => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy),
  290. 'noProxy' => Utils::defaultString($runtime->noProxy, $this->_noProxy),
  291. 'socks5Proxy' => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy),
  292. 'socks5NetWork' => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork),
  293. 'maxIdleConns' => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns),
  294. 'retry' => [
  295. 'retryable' => $runtime->autoretry,
  296. 'maxAttempts' => Utils::defaultNumber($runtime->maxAttempts, 3),
  297. ],
  298. 'backoff' => [
  299. 'policy' => Utils::defaultString($runtime->backoffPolicy, 'no'),
  300. 'period' => Utils::defaultNumber($runtime->backoffPeriod, 1),
  301. ],
  302. 'ignoreSSL' => $runtime->ignoreSSL,
  303. ];
  304. $_lastRequest = null;
  305. $_lastException = null;
  306. $_now = time();
  307. $_retryTimes = 0;
  308. while (Tea::allowRetry(@$_runtime['retry'], $_retryTimes, $_now)) {
  309. if ($_retryTimes > 0) {
  310. $_backoffTime = Tea::getBackoffTime(@$_runtime['backoff'], $_retryTimes);
  311. if ($_backoffTime > 0) {
  312. Tea::sleep($_backoffTime);
  313. }
  314. }
  315. $_retryTimes = $_retryTimes + 1;
  316. try {
  317. $_request = new Request();
  318. $_request->protocol = Utils::defaultString($this->_protocol, $protocol);
  319. $_request->method = $method;
  320. $_request->pathname = $pathname;
  321. $_request->headers = Tea::merge([
  322. 'date' => Utils::getDateUTCString(),
  323. 'host' => $this->_endpoint,
  324. 'accept' => 'application/json',
  325. 'x-acs-signature-nonce' => Utils::getNonce(),
  326. 'x-acs-signature-method' => 'HMAC-SHA1',
  327. 'x-acs-signature-version' => '1.0',
  328. 'x-acs-version' => $version,
  329. 'x-acs-action' => $action,
  330. 'user-agent' => Utils::getUserAgent($this->_userAgent),
  331. ], $request->headers);
  332. if (!Utils::isUnset($request->body)) {
  333. $_request->body = Utils::toJSONString($request->body);
  334. $_request->headers['content-type'] = 'application/json; charset=utf-8';
  335. }
  336. if (!Utils::isUnset($request->query)) {
  337. $_request->query = $request->query;
  338. }
  339. if (!Utils::equalString($authType, 'Anonymous')) {
  340. $accessKeyId = $this->getAccessKeyId();
  341. $accessKeySecret = $this->getAccessKeySecret();
  342. $securityToken = $this->getSecurityToken();
  343. if (!Utils::empty_($securityToken)) {
  344. $_request->headers['x-acs-accesskey-id'] = $accessKeyId;
  345. $_request->headers['x-acs-security-token'] = $securityToken;
  346. }
  347. $stringToSign = OpenApiUtilClient::getStringToSign($_request);
  348. $_request->headers['authorization'] = 'acs '.$accessKeyId.':'.OpenApiUtilClient::getROASignature($stringToSign, $accessKeySecret).'';
  349. }
  350. $_lastRequest = $_request;
  351. $_response = Tea::send($_request, $_runtime);
  352. if (Utils::equalNumber($_response->statusCode, 204)) {
  353. return [
  354. 'headers' => $_response->headers,
  355. ];
  356. }
  357. if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) {
  358. $_res = Utils::readAsJSON($_response->body);
  359. $err = Utils::assertAsMap($_res);
  360. $requestId = self::defaultAny(@$err['RequestId'], @$err['requestId']);
  361. $requestId = self::defaultAny($requestId, @$err['requestid']);
  362. throw new TeaError(['code' => ''.(string) (self::defaultAny(@$err['Code'], @$err['code'])).'', 'message' => 'code: '.(string) ($_response->statusCode).', '.(string) (self::defaultAny(@$err['Message'], @$err['message'])).' request id: '.(string) ($requestId).'', 'data' => $err]);
  363. }
  364. if (Utils::equalString($bodyType, 'binary')) {
  365. $resp = [
  366. 'body' => $_response->body,
  367. 'headers' => $_response->headers,
  368. ];
  369. return $resp;
  370. } elseif (Utils::equalString($bodyType, 'byte')) {
  371. $byt = Utils::readAsBytes($_response->body);
  372. return [
  373. 'body' => $byt,
  374. 'headers' => $_response->headers,
  375. ];
  376. } elseif (Utils::equalString($bodyType, 'string')) {
  377. $str = Utils::readAsString($_response->body);
  378. return [
  379. 'body' => $str,
  380. 'headers' => $_response->headers,
  381. ];
  382. } elseif (Utils::equalString($bodyType, 'json')) {
  383. $obj = Utils::readAsJSON($_response->body);
  384. $res = Utils::assertAsMap($obj);
  385. return [
  386. 'body' => $res,
  387. 'headers' => $_response->headers,
  388. ];
  389. } elseif (Utils::equalString($bodyType, 'array')) {
  390. $arr = Utils::readAsJSON($_response->body);
  391. return [
  392. 'body' => $arr,
  393. 'headers' => $_response->headers,
  394. ];
  395. } else {
  396. return [
  397. 'headers' => $_response->headers,
  398. ];
  399. }
  400. } catch (Exception $e) {
  401. if (!($e instanceof TeaError)) {
  402. $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
  403. }
  404. if (Tea::isRetryable($e)) {
  405. $_lastException = $e;
  406. continue;
  407. }
  408. throw $e;
  409. }
  410. }
  411. throw new TeaUnableRetryError($_lastRequest, $_lastException);
  412. }
  413. /**
  414. * Encapsulate the request and invoke the network with form body.
  415. *
  416. * @param string $action api name
  417. * @param string $version product version
  418. * @param string $protocol http or https
  419. * @param string $method e.g. GET
  420. * @param string $authType authorization type e.g. AK
  421. * @param string $pathname pathname of every api
  422. * @param string $bodyType response body type e.g. String
  423. * @param OpenApiRequest $request object of OpenApiRequest
  424. * @param RuntimeOptions $runtime which controls some details of call api, such as retry times
  425. *
  426. * @return array the response
  427. *
  428. * @throws TeaError
  429. * @throws Exception
  430. * @throws TeaUnableRetryError
  431. */
  432. public function doROARequestWithForm($action, $version, $protocol, $method, $authType, $pathname, $bodyType, $request, $runtime)
  433. {
  434. $request->validate();
  435. $runtime->validate();
  436. $_runtime = [
  437. 'timeouted' => 'retry',
  438. 'readTimeout' => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout),
  439. 'connectTimeout' => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout),
  440. 'httpProxy' => Utils::defaultString($runtime->httpProxy, $this->_httpProxy),
  441. 'httpsProxy' => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy),
  442. 'noProxy' => Utils::defaultString($runtime->noProxy, $this->_noProxy),
  443. 'socks5Proxy' => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy),
  444. 'socks5NetWork' => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork),
  445. 'maxIdleConns' => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns),
  446. 'retry' => [
  447. 'retryable' => $runtime->autoretry,
  448. 'maxAttempts' => Utils::defaultNumber($runtime->maxAttempts, 3),
  449. ],
  450. 'backoff' => [
  451. 'policy' => Utils::defaultString($runtime->backoffPolicy, 'no'),
  452. 'period' => Utils::defaultNumber($runtime->backoffPeriod, 1),
  453. ],
  454. 'ignoreSSL' => $runtime->ignoreSSL,
  455. ];
  456. $_lastRequest = null;
  457. $_lastException = null;
  458. $_now = time();
  459. $_retryTimes = 0;
  460. while (Tea::allowRetry(@$_runtime['retry'], $_retryTimes, $_now)) {
  461. if ($_retryTimes > 0) {
  462. $_backoffTime = Tea::getBackoffTime(@$_runtime['backoff'], $_retryTimes);
  463. if ($_backoffTime > 0) {
  464. Tea::sleep($_backoffTime);
  465. }
  466. }
  467. $_retryTimes = $_retryTimes + 1;
  468. try {
  469. $_request = new Request();
  470. $_request->protocol = Utils::defaultString($this->_protocol, $protocol);
  471. $_request->method = $method;
  472. $_request->pathname = $pathname;
  473. $_request->headers = Tea::merge([
  474. 'date' => Utils::getDateUTCString(),
  475. 'host' => $this->_endpoint,
  476. 'accept' => 'application/json',
  477. 'x-acs-signature-nonce' => Utils::getNonce(),
  478. 'x-acs-signature-method' => 'HMAC-SHA1',
  479. 'x-acs-signature-version' => '1.0',
  480. 'x-acs-version' => $version,
  481. 'x-acs-action' => $action,
  482. 'user-agent' => Utils::getUserAgent($this->_userAgent),
  483. ], $request->headers);
  484. if (!Utils::isUnset($request->body)) {
  485. $m = Utils::assertAsMap($request->body);
  486. $_request->body = OpenApiUtilClient::toForm($m);
  487. $_request->headers['content-type'] = 'application/x-www-form-urlencoded';
  488. }
  489. if (!Utils::isUnset($request->query)) {
  490. $_request->query = $request->query;
  491. }
  492. if (!Utils::equalString($authType, 'Anonymous')) {
  493. $accessKeyId = $this->getAccessKeyId();
  494. $accessKeySecret = $this->getAccessKeySecret();
  495. $securityToken = $this->getSecurityToken();
  496. if (!Utils::empty_($securityToken)) {
  497. $_request->headers['x-acs-accesskey-id'] = $accessKeyId;
  498. $_request->headers['x-acs-security-token'] = $securityToken;
  499. }
  500. $stringToSign = OpenApiUtilClient::getStringToSign($_request);
  501. $_request->headers['authorization'] = 'acs '.$accessKeyId.':'.OpenApiUtilClient::getROASignature($stringToSign, $accessKeySecret).'';
  502. }
  503. $_lastRequest = $_request;
  504. $_response = Tea::send($_request, $_runtime);
  505. if (Utils::equalNumber($_response->statusCode, 204)) {
  506. return [
  507. 'headers' => $_response->headers,
  508. ];
  509. }
  510. if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) {
  511. $_res = Utils::readAsJSON($_response->body);
  512. $err = Utils::assertAsMap($_res);
  513. throw new TeaError(['code' => ''.(string) (self::defaultAny(@$err['Code'], @$err['code'])).'', 'message' => 'code: '.(string) ($_response->statusCode).', '.(string) (self::defaultAny(@$err['Message'], @$err['message'])).' request id: '.(string) (self::defaultAny(@$err['RequestId'], @$err['requestId'])).'', 'data' => $err]);
  514. }
  515. if (Utils::equalString($bodyType, 'binary')) {
  516. $resp = [
  517. 'body' => $_response->body,
  518. 'headers' => $_response->headers,
  519. ];
  520. return $resp;
  521. } elseif (Utils::equalString($bodyType, 'byte')) {
  522. $byt = Utils::readAsBytes($_response->body);
  523. return [
  524. 'body' => $byt,
  525. 'headers' => $_response->headers,
  526. ];
  527. } elseif (Utils::equalString($bodyType, 'string')) {
  528. $str = Utils::readAsString($_response->body);
  529. return [
  530. 'body' => $str,
  531. 'headers' => $_response->headers,
  532. ];
  533. } elseif (Utils::equalString($bodyType, 'json')) {
  534. $obj = Utils::readAsJSON($_response->body);
  535. $res = Utils::assertAsMap($obj);
  536. return [
  537. 'body' => $res,
  538. 'headers' => $_response->headers,
  539. ];
  540. } elseif (Utils::equalString($bodyType, 'array')) {
  541. $arr = Utils::readAsJSON($_response->body);
  542. return [
  543. 'body' => $arr,
  544. 'headers' => $_response->headers,
  545. ];
  546. } else {
  547. return [
  548. 'headers' => $_response->headers,
  549. ];
  550. }
  551. } catch (Exception $e) {
  552. if (!($e instanceof TeaError)) {
  553. $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
  554. }
  555. if (Tea::isRetryable($e)) {
  556. $_lastException = $e;
  557. continue;
  558. }
  559. throw $e;
  560. }
  561. }
  562. throw new TeaUnableRetryError($_lastRequest, $_lastException);
  563. }
  564. /**
  565. * Encapsulate the request and invoke the network.
  566. *
  567. * @param Params $params
  568. * @param OpenApiRequest $request object of OpenApiRequest
  569. * @param RuntimeOptions $runtime which controls some details of call api, such as retry times
  570. *
  571. * @return array the response
  572. *
  573. * @throws TeaError
  574. * @throws Exception
  575. * @throws TeaUnableRetryError
  576. */
  577. public function doRequest($params, $request, $runtime)
  578. {
  579. $params->validate();
  580. $request->validate();
  581. $runtime->validate();
  582. $_runtime = [
  583. 'timeouted' => 'retry',
  584. 'readTimeout' => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout),
  585. 'connectTimeout' => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout),
  586. 'httpProxy' => Utils::defaultString($runtime->httpProxy, $this->_httpProxy),
  587. 'httpsProxy' => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy),
  588. 'noProxy' => Utils::defaultString($runtime->noProxy, $this->_noProxy),
  589. 'socks5Proxy' => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy),
  590. 'socks5NetWork' => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork),
  591. 'maxIdleConns' => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns),
  592. 'retry' => [
  593. 'retryable' => $runtime->autoretry,
  594. 'maxAttempts' => Utils::defaultNumber($runtime->maxAttempts, 3),
  595. ],
  596. 'backoff' => [
  597. 'policy' => Utils::defaultString($runtime->backoffPolicy, 'no'),
  598. 'period' => Utils::defaultNumber($runtime->backoffPeriod, 1),
  599. ],
  600. 'ignoreSSL' => $runtime->ignoreSSL,
  601. ];
  602. $_lastRequest = null;
  603. $_lastException = null;
  604. $_now = time();
  605. $_retryTimes = 0;
  606. while (Tea::allowRetry(@$_runtime['retry'], $_retryTimes, $_now)) {
  607. if ($_retryTimes > 0) {
  608. $_backoffTime = Tea::getBackoffTime(@$_runtime['backoff'], $_retryTimes);
  609. if ($_backoffTime > 0) {
  610. Tea::sleep($_backoffTime);
  611. }
  612. }
  613. $_retryTimes = $_retryTimes + 1;
  614. try {
  615. $_request = new Request();
  616. $_request->protocol = Utils::defaultString($this->_protocol, $params->protocol);
  617. $_request->method = $params->method;
  618. $_request->pathname = $params->pathname;
  619. $globalQueries = [];
  620. $globalHeaders = [];
  621. if (!Utils::isUnset($this->_globalParameters)) {
  622. $globalParams = $this->_globalParameters;
  623. if (!Utils::isUnset($globalParams->queries)) {
  624. $globalQueries = $globalParams->queries;
  625. }
  626. if (!Utils::isUnset($globalParams->headers)) {
  627. $globalHeaders = $globalParams->headers;
  628. }
  629. }
  630. $_request->query = Tea::merge($globalQueries, $request->query);
  631. // endpoint is setted in product client
  632. $_request->headers = Tea::merge([
  633. 'host' => $this->_endpoint,
  634. 'x-acs-version' => $params->version,
  635. 'x-acs-action' => $params->action,
  636. 'user-agent' => $this->getUserAgent(),
  637. 'x-acs-date' => OpenApiUtilClient::getTimestamp(),
  638. 'x-acs-signature-nonce' => Utils::getNonce(),
  639. 'accept' => 'application/json',
  640. ], $globalHeaders, $request->headers);
  641. if (Utils::equalString($params->style, 'RPC')) {
  642. $headers = $this->getRpcHeaders();
  643. if (!Utils::isUnset($headers)) {
  644. $_request->headers = Tea::merge($_request->headers, $headers);
  645. }
  646. }
  647. $signatureAlgorithm = Utils::defaultString($this->_signatureAlgorithm, 'ACS3-HMAC-SHA256');
  648. $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash(Utils::toBytes(''), $signatureAlgorithm));
  649. if (!Utils::isUnset($request->stream)) {
  650. $tmp = Utils::readAsBytes($request->stream);
  651. $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash($tmp, $signatureAlgorithm));
  652. $_request->body = $tmp;
  653. $_request->headers['content-type'] = 'application/octet-stream';
  654. } else {
  655. if (!Utils::isUnset($request->body)) {
  656. if (Utils::equalString($params->reqBodyType, 'json')) {
  657. $jsonObj = Utils::toJSONString($request->body);
  658. $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash(Utils::toBytes($jsonObj), $signatureAlgorithm));
  659. $_request->body = $jsonObj;
  660. $_request->headers['content-type'] = 'application/json; charset=utf-8';
  661. } else {
  662. $m = Utils::assertAsMap($request->body);
  663. $formObj = OpenApiUtilClient::toForm($m);
  664. $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash(Utils::toBytes($formObj), $signatureAlgorithm));
  665. $_request->body = $formObj;
  666. $_request->headers['content-type'] = 'application/x-www-form-urlencoded';
  667. }
  668. }
  669. }
  670. $_request->headers['x-acs-content-sha256'] = $hashedRequestPayload;
  671. if (!Utils::equalString($params->authType, 'Anonymous')) {
  672. $authType = $this->getType();
  673. if (Utils::equalString($authType, 'bearer')) {
  674. $bearerToken = $this->getBearerToken();
  675. $_request->headers['x-acs-bearer-token'] = $bearerToken;
  676. } else {
  677. $accessKeyId = $this->getAccessKeyId();
  678. $accessKeySecret = $this->getAccessKeySecret();
  679. $securityToken = $this->getSecurityToken();
  680. if (!Utils::empty_($securityToken)) {
  681. $_request->headers['x-acs-accesskey-id'] = $accessKeyId;
  682. $_request->headers['x-acs-security-token'] = $securityToken;
  683. }
  684. $_request->headers['Authorization'] = OpenApiUtilClient::getAuthorization($_request, $signatureAlgorithm, $hashedRequestPayload, $accessKeyId, $accessKeySecret);
  685. }
  686. }
  687. $_lastRequest = $_request;
  688. $_response = Tea::send($_request, $_runtime);
  689. if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) {
  690. $err = [];
  691. // if (!Utils::isUnset(@$_response->headers['content-type']) && Utils::equalString(@$_response->headers['content-type'], 'text/xml;charset=utf-8')) {
  692. // $_str = Utils::readAsString($_response->body);
  693. // $respMap = XML::parseXml($_str, null);
  694. // $err = Utils::assertAsMap(@$respMap['Error']);
  695. // } else {
  696. // $_res = Utils::readAsJSON($_response->body);
  697. // $err = Utils::assertAsMap($_res);
  698. // }
  699. $_res = Utils::readAsJSON($_response->body);
  700. $err = Utils::assertAsMap($_res);
  701. @$err['statusCode'] = $_response->statusCode;
  702. throw new TeaError(['code' => ''.(string) (self::defaultAny(@$err['Code'], @$err['code'])).'', 'message' => 'code: '.(string) ($_response->statusCode).', '.(string) (self::defaultAny(@$err['Message'], @$err['message'])).' request id: '.(string) (self::defaultAny(@$err['RequestId'], @$err['requestId'])).'', 'data' => $err]);
  703. }
  704. if (Utils::equalString($params->bodyType, 'binary')) {
  705. $resp = [
  706. 'body' => $_response->body,
  707. 'headers' => $_response->headers,
  708. 'statusCode' => $_response->statusCode,
  709. ];
  710. return $resp;
  711. } elseif (Utils::equalString($params->bodyType, 'byte')) {
  712. $byt = Utils::readAsBytes($_response->body);
  713. return [
  714. 'body' => $byt,
  715. 'headers' => $_response->headers,
  716. 'statusCode' => $_response->statusCode,
  717. ];
  718. } elseif (Utils::equalString($params->bodyType, 'string')) {
  719. $str = Utils::readAsString($_response->body);
  720. return [
  721. 'body' => $str,
  722. 'headers' => $_response->headers,
  723. 'statusCode' => $_response->statusCode,
  724. ];
  725. } elseif (Utils::equalString($params->bodyType, 'json')) {
  726. $obj = Utils::readAsJSON($_response->body);
  727. $res = Utils::assertAsMap($obj);
  728. return [
  729. 'body' => $res,
  730. 'headers' => $_response->headers,
  731. 'statusCode' => $_response->statusCode,
  732. ];
  733. } elseif (Utils::equalString($params->bodyType, 'array')) {
  734. $arr = Utils::readAsJSON($_response->body);
  735. return [
  736. 'body' => $arr,
  737. 'headers' => $_response->headers,
  738. 'statusCode' => $_response->statusCode,
  739. ];
  740. } else {
  741. return [
  742. 'headers' => $_response->headers,
  743. 'statusCode' => $_response->statusCode,
  744. ];
  745. }
  746. } catch (Exception $e) {
  747. if (!($e instanceof TeaError)) {
  748. $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
  749. }
  750. if (Tea::isRetryable($e)) {
  751. $_lastException = $e;
  752. continue;
  753. }
  754. throw $e;
  755. }
  756. }
  757. throw new TeaUnableRetryError($_lastRequest, $_lastException);
  758. }
  759. /**
  760. * Encapsulate the request and invoke the network.
  761. *
  762. * @param Params $params
  763. * @param OpenApiRequest $request object of OpenApiRequest
  764. * @param RuntimeOptions $runtime which controls some details of call api, such as retry times
  765. *
  766. * @return array the response
  767. *
  768. * @throws TeaError
  769. * @throws Exception
  770. * @throws TeaUnableRetryError
  771. */
  772. public function execute($params, $request, $runtime)
  773. {
  774. $params->validate();
  775. $request->validate();
  776. $runtime->validate();
  777. $_runtime = [
  778. 'timeouted' => 'retry',
  779. 'readTimeout' => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout),
  780. 'connectTimeout' => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout),
  781. 'httpProxy' => Utils::defaultString($runtime->httpProxy, $this->_httpProxy),
  782. 'httpsProxy' => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy),
  783. 'noProxy' => Utils::defaultString($runtime->noProxy, $this->_noProxy),
  784. 'socks5Proxy' => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy),
  785. 'socks5NetWork' => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork),
  786. 'maxIdleConns' => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns),
  787. 'retry' => [
  788. 'retryable' => $runtime->autoretry,
  789. 'maxAttempts' => Utils::defaultNumber($runtime->maxAttempts, 3),
  790. ],
  791. 'backoff' => [
  792. 'policy' => Utils::defaultString($runtime->backoffPolicy, 'no'),
  793. 'period' => Utils::defaultNumber($runtime->backoffPeriod, 1),
  794. ],
  795. 'ignoreSSL' => $runtime->ignoreSSL,
  796. ];
  797. $_lastRequest = null;
  798. $_lastException = null;
  799. $_now = time();
  800. $_retryTimes = 0;
  801. while (Tea::allowRetry(@$_runtime['retry'], $_retryTimes, $_now)) {
  802. if ($_retryTimes > 0) {
  803. $_backoffTime = Tea::getBackoffTime(@$_runtime['backoff'], $_retryTimes);
  804. if ($_backoffTime > 0) {
  805. Tea::sleep($_backoffTime);
  806. }
  807. }
  808. $_retryTimes = $_retryTimes + 1;
  809. try {
  810. $_request = new Request();
  811. // spi = new Gateway();//Gateway implements SPI,这一步在产品 SDK 中实例化
  812. $headers = $this->getRpcHeaders();
  813. $globalQueries = [];
  814. $globalHeaders = [];
  815. if (!Utils::isUnset($this->_globalParameters)) {
  816. $globalParams = $this->_globalParameters;
  817. if (!Utils::isUnset($globalParams->queries)) {
  818. $globalQueries = $globalParams->queries;
  819. }
  820. if (!Utils::isUnset($globalParams->headers)) {
  821. $globalHeaders = $globalParams->headers;
  822. }
  823. }
  824. $requestContext = new \Darabonba\GatewaySpi\Models\InterceptorContext\request([
  825. 'headers' => Tea::merge($globalHeaders, $request->headers, $headers),
  826. 'query' => Tea::merge($globalQueries, $request->query),
  827. 'body' => $request->body,
  828. 'stream' => $request->stream,
  829. 'hostMap' => $request->hostMap,
  830. 'pathname' => $params->pathname,
  831. 'productId' => $this->_productId,
  832. 'action' => $params->action,
  833. 'version' => $params->version,
  834. 'protocol' => Utils::defaultString($this->_protocol, $params->protocol),
  835. 'method' => Utils::defaultString($this->_method, $params->method),
  836. 'authType' => $params->authType,
  837. 'bodyType' => $params->bodyType,
  838. 'reqBodyType' => $params->reqBodyType,
  839. 'style' => $params->style,
  840. 'credential' => $this->_credential,
  841. 'signatureVersion' => $this->_signatureVersion,
  842. 'signatureAlgorithm' => $this->_signatureAlgorithm,
  843. 'userAgent' => $this->getUserAgent(),
  844. ]);
  845. $configurationContext = new configuration([
  846. 'regionId' => $this->_regionId,
  847. 'endpoint' => Utils::defaultString($request->endpointOverride, $this->_endpoint),
  848. 'endpointRule' => $this->_endpointRule,
  849. 'endpointMap' => $this->_endpointMap,
  850. 'endpointType' => $this->_endpointType,
  851. 'network' => $this->_network,
  852. 'suffix' => $this->_suffix,
  853. ]);
  854. $interceptorContext = new InterceptorContext([
  855. 'request' => $requestContext,
  856. 'configuration' => $configurationContext,
  857. ]);
  858. $attributeMap = new AttributeMap([]);
  859. // 1. spi.modifyConfiguration(context: SPI.InterceptorContext, attributeMap: SPI.AttributeMap);
  860. $this->_spi->modifyConfiguration($interceptorContext, $attributeMap);
  861. // 2. spi.modifyRequest(context: SPI.InterceptorContext, attributeMap: SPI.AttributeMap);
  862. $this->_spi->modifyRequest($interceptorContext, $attributeMap);
  863. $_request->protocol = $interceptorContext->request->protocol;
  864. $_request->method = $interceptorContext->request->method;
  865. $_request->pathname = $interceptorContext->request->pathname;
  866. $_request->query = $interceptorContext->request->query;
  867. $_request->body = $interceptorContext->request->stream;
  868. $_request->headers = $interceptorContext->request->headers;
  869. $_lastRequest = $_request;
  870. $_response = Tea::send($_request, $_runtime);
  871. $responseContext = new response([
  872. 'statusCode' => $_response->statusCode,
  873. 'headers' => $_response->headers,
  874. 'body' => $_response->body,
  875. ]);
  876. $interceptorContext->response = $responseContext;
  877. // 3. spi.modifyResponse(context: SPI.InterceptorContext, attributeMap: SPI.AttributeMap);
  878. $this->_spi->modifyResponse($interceptorContext, $attributeMap);
  879. return [
  880. 'headers' => $interceptorContext->response->headers,
  881. 'statusCode' => $interceptorContext->response->statusCode,
  882. 'body' => $interceptorContext->response->deserializedBody,
  883. ];
  884. } catch (Exception $e) {
  885. if (!($e instanceof TeaError)) {
  886. $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
  887. }
  888. if (Tea::isRetryable($e)) {
  889. $_lastException = $e;
  890. continue;
  891. }
  892. throw $e;
  893. }
  894. }
  895. throw new TeaUnableRetryError($_lastRequest, $_lastException);
  896. }
  897. /**
  898. * @param Params $params
  899. * @param OpenApiRequest $request
  900. * @param RuntimeOptions $runtime
  901. *
  902. * @return array
  903. *
  904. * @throws TeaError
  905. */
  906. public function callApi($params, $request, $runtime)
  907. {
  908. if (Utils::isUnset($params)) {
  909. throw new TeaError(['code' => 'ParameterMissing', 'message' => "'params' can not be unset"]);
  910. }
  911. if (Utils::isUnset($this->_signatureAlgorithm) || !Utils::equalString($this->_signatureAlgorithm, 'v2')) {
  912. return $this->doRequest($params, $request, $runtime);
  913. } elseif (Utils::equalString($params->style, 'ROA') && Utils::equalString($params->reqBodyType, 'json')) {
  914. return $this->doROARequest($params->action, $params->version, $params->protocol, $params->method, $params->authType, $params->pathname, $params->bodyType, $request, $runtime);
  915. } elseif (Utils::equalString($params->style, 'ROA')) {
  916. return $this->doROARequestWithForm($params->action, $params->version, $params->protocol, $params->method, $params->authType, $params->pathname, $params->bodyType, $request, $runtime);
  917. } else {
  918. return $this->doRPCRequest($params->action, $params->version, $params->protocol, $params->method, $params->authType, $params->bodyType, $request, $runtime);
  919. }
  920. }
  921. /**
  922. * Get user agent.
  923. *
  924. * @return string user agent
  925. */
  926. public function getUserAgent()
  927. {
  928. $userAgent = Utils::getUserAgent($this->_userAgent);
  929. return $userAgent;
  930. }
  931. /**
  932. * Get accesskey id by using credential.
  933. *
  934. * @return string accesskey id
  935. */
  936. public function getAccessKeyId()
  937. {
  938. if (Utils::isUnset($this->_credential)) {
  939. return '';
  940. }
  941. $accessKeyId = $this->_credential->getAccessKeyId();
  942. return $accessKeyId;
  943. }
  944. /**
  945. * Get accesskey secret by using credential.
  946. *
  947. * @return string accesskey secret
  948. */
  949. public function getAccessKeySecret()
  950. {
  951. if (Utils::isUnset($this->_credential)) {
  952. return '';
  953. }
  954. $secret = $this->_credential->getAccessKeySecret();
  955. return $secret;
  956. }
  957. /**
  958. * Get security token by using credential.
  959. *
  960. * @return string security token
  961. */
  962. public function getSecurityToken()
  963. {
  964. if (Utils::isUnset($this->_credential)) {
  965. return '';
  966. }
  967. $token = $this->_credential->getSecurityToken();
  968. return $token;
  969. }
  970. /**
  971. * Get bearer token by credential.
  972. *
  973. * @return string bearer token
  974. */
  975. public function getBearerToken()
  976. {
  977. if (Utils::isUnset($this->_credential)) {
  978. return '';
  979. }
  980. $token = $this->_credential->getBearerToken();
  981. return $token;
  982. }
  983. /**
  984. * Get credential type by credential.
  985. *
  986. * @return string credential type e.g. access_key
  987. */
  988. public function getType()
  989. {
  990. if (Utils::isUnset($this->_credential)) {
  991. return '';
  992. }
  993. $authType = $this->_credential->getType();
  994. return $authType;
  995. }
  996. /**
  997. * If inputValue is not null, return it or return defaultValue.
  998. *
  999. * @param mixed $inputValue users input value
  1000. * @param mixed $defaultValue default value
  1001. *
  1002. * @return any the final result
  1003. */
  1004. public static function defaultAny($inputValue, $defaultValue)
  1005. {
  1006. if (Utils::isUnset($inputValue)) {
  1007. return $defaultValue;
  1008. }
  1009. return $inputValue;
  1010. }
  1011. /**
  1012. * If the endpointRule and config.endpoint are empty, throw error.
  1013. *
  1014. * @param \Darabonba\OpenApi\Models\Config $config config contains the necessary information to create a client
  1015. *
  1016. * @return void
  1017. *
  1018. * @throws TeaError
  1019. */
  1020. public function checkConfig($config)
  1021. {
  1022. if (Utils::empty_($this->_endpointRule) && Utils::empty_($config->endpoint)) {
  1023. throw new TeaError(['code' => 'ParameterMissing', 'message' => "'config.endpoint' can not be empty"]);
  1024. }
  1025. }
  1026. /**
  1027. * set RPC header for debug.
  1028. *
  1029. * @param string[] $headers headers for debug, this header can be used only once
  1030. *
  1031. * @return void
  1032. */
  1033. public function setRpcHeaders($headers)
  1034. {
  1035. $this->_headers = $headers;
  1036. }
  1037. /**
  1038. * get RPC header for debug.
  1039. *
  1040. * @return array
  1041. */
  1042. public function getRpcHeaders()
  1043. {
  1044. $headers = $this->_headers;
  1045. $this->_headers = null;
  1046. return $headers;
  1047. }
  1048. }