EmailCertificationsApi.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <?php
  2. /**
  3. * EmailCertificationsApi
  4. * PHP version 8.1
  5. *
  6. * @category Class
  7. * @package WikipaliApi
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * MINT API
  13. *
  14. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  15. *
  16. * The version of the OpenAPI document: 2026.10.15
  17. * Generated by: https://openapi-generator.tech
  18. * Generator version: 7.25.0
  19. */
  20. /**
  21. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  22. * https://openapi-generator.tech
  23. * Do not edit the class manually.
  24. */
  25. namespace WikipaliApi\Api;
  26. use GuzzleHttp\Client;
  27. use GuzzleHttp\ClientInterface;
  28. use GuzzleHttp\Exception\ConnectException;
  29. use GuzzleHttp\Exception\RequestException;
  30. use GuzzleHttp\Psr7\MultipartStream;
  31. use GuzzleHttp\Psr7\Request;
  32. use GuzzleHttp\RequestOptions;
  33. use Psr\Http\Message\RequestInterface;
  34. use Psr\Http\Message\ResponseInterface;
  35. use WikipaliApi\ApiException;
  36. use WikipaliApi\Configuration;
  37. use WikipaliApi\FormDataProcessor;
  38. use WikipaliApi\HeaderSelector;
  39. use WikipaliApi\ObjectSerializer;
  40. /**
  41. * EmailCertificationsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class EmailCertificationsApi
  49. {
  50. /**
  51. * @var ClientInterface
  52. */
  53. protected $client;
  54. /**
  55. * @var Configuration
  56. */
  57. protected $config;
  58. /**
  59. * @var HeaderSelector
  60. */
  61. protected $headerSelector;
  62. /**
  63. * @var int Host index
  64. */
  65. protected $hostIndex;
  66. /** @var string[] $contentTypes **/
  67. public const contentTypes = [
  68. 'postApiV3EmailCertifications' => [
  69. 'application/json',
  70. ],
  71. ];
  72. /**
  73. * @param ClientInterface $client
  74. * @param Configuration $config
  75. * @param HeaderSelector $selector
  76. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  77. */
  78. public function __construct(
  79. ?ClientInterface $client = null,
  80. ?Configuration $config = null,
  81. ?HeaderSelector $selector = null,
  82. int $hostIndex = 0
  83. ) {
  84. $this->client = $client ?: new Client();
  85. $this->config = $config ?: Configuration::getDefaultConfiguration();
  86. $this->headerSelector = $selector ?: new HeaderSelector();
  87. $this->hostIndex = $hostIndex;
  88. }
  89. /**
  90. * Set the host index
  91. *
  92. * @param int $hostIndex Host index (required)
  93. */
  94. public function setHostIndex($hostIndex): void
  95. {
  96. $this->hostIndex = $hostIndex;
  97. }
  98. /**
  99. * Get the host index
  100. *
  101. * @return int Host index
  102. */
  103. public function getHostIndex()
  104. {
  105. return $this->hostIndex;
  106. }
  107. /**
  108. * @return Configuration
  109. */
  110. public function getConfig()
  111. {
  112. return $this->config;
  113. }
  114. /**
  115. * Operation postApiV3EmailCertifications
  116. *
  117. * 发送注册验证码
  118. *
  119. * @param \WikipaliApi\Model\PostApiV3EmailCertificationsRequest $post_api_v3_email_certifications_request post_api_v3_email_certifications_request (required)
  120. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3EmailCertifications'] to see the possible values for this operation
  121. *
  122. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  123. * @throws \InvalidArgumentException
  124. * @return void
  125. */
  126. public function postApiV3EmailCertifications($post_api_v3_email_certifications_request, string $contentType = self::contentTypes['postApiV3EmailCertifications'][0])
  127. {
  128. $this->postApiV3EmailCertificationsWithHttpInfo($post_api_v3_email_certifications_request, $contentType);
  129. }
  130. /**
  131. * Operation postApiV3EmailCertificationsWithHttpInfo
  132. *
  133. * 发送注册验证码
  134. *
  135. * @param \WikipaliApi\Model\PostApiV3EmailCertificationsRequest $post_api_v3_email_certifications_request (required)
  136. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3EmailCertifications'] to see the possible values for this operation
  137. *
  138. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  139. * @throws \InvalidArgumentException
  140. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  141. */
  142. public function postApiV3EmailCertificationsWithHttpInfo($post_api_v3_email_certifications_request, string $contentType = self::contentTypes['postApiV3EmailCertifications'][0])
  143. {
  144. $request = $this->postApiV3EmailCertificationsRequest($post_api_v3_email_certifications_request, $contentType);
  145. try {
  146. $options = $this->createHttpClientOption();
  147. try {
  148. $response = $this->client->send($request, $options);
  149. } catch (RequestException $e) {
  150. throw new ApiException(
  151. "[{$e->getCode()}] {$e->getMessage()}",
  152. (int) $e->getCode(),
  153. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  154. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  155. );
  156. } catch (ConnectException $e) {
  157. throw new ApiException(
  158. "[{$e->getCode()}] {$e->getMessage()}",
  159. (int) $e->getCode(),
  160. null,
  161. null
  162. );
  163. }
  164. $statusCode = $response->getStatusCode();
  165. return [null, $statusCode, $response->getHeaders()];
  166. } catch (ApiException $e) {
  167. switch ($e->getCode()) {
  168. case 422:
  169. $data = ObjectSerializer::deserialize(
  170. $e->getResponseBody(),
  171. '\WikipaliApi\Model\ProblemDetails',
  172. $e->getResponseHeaders()
  173. );
  174. $e->setResponseObject($data);
  175. throw $e;
  176. case 429:
  177. $data = ObjectSerializer::deserialize(
  178. $e->getResponseBody(),
  179. '\WikipaliApi\Model\ProblemDetails',
  180. $e->getResponseHeaders()
  181. );
  182. $e->setResponseObject($data);
  183. throw $e;
  184. case 503:
  185. $data = ObjectSerializer::deserialize(
  186. $e->getResponseBody(),
  187. '\WikipaliApi\Model\ProblemDetails',
  188. $e->getResponseHeaders()
  189. );
  190. $e->setResponseObject($data);
  191. throw $e;
  192. }
  193. throw $e;
  194. }
  195. }
  196. /**
  197. * Operation postApiV3EmailCertificationsAsync
  198. *
  199. * 发送注册验证码
  200. *
  201. * @param \WikipaliApi\Model\PostApiV3EmailCertificationsRequest $post_api_v3_email_certifications_request (required)
  202. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3EmailCertifications'] to see the possible values for this operation
  203. *
  204. * @throws \InvalidArgumentException
  205. * @return \GuzzleHttp\Promise\PromiseInterface
  206. */
  207. public function postApiV3EmailCertificationsAsync($post_api_v3_email_certifications_request, string $contentType = self::contentTypes['postApiV3EmailCertifications'][0])
  208. {
  209. return $this->postApiV3EmailCertificationsAsyncWithHttpInfo($post_api_v3_email_certifications_request, $contentType)
  210. ->then(
  211. function ($response) {
  212. return $response[0];
  213. }
  214. );
  215. }
  216. /**
  217. * Operation postApiV3EmailCertificationsAsyncWithHttpInfo
  218. *
  219. * 发送注册验证码
  220. *
  221. * @param \WikipaliApi\Model\PostApiV3EmailCertificationsRequest $post_api_v3_email_certifications_request (required)
  222. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3EmailCertifications'] to see the possible values for this operation
  223. *
  224. * @throws \InvalidArgumentException
  225. * @return \GuzzleHttp\Promise\PromiseInterface
  226. */
  227. public function postApiV3EmailCertificationsAsyncWithHttpInfo($post_api_v3_email_certifications_request, string $contentType = self::contentTypes['postApiV3EmailCertifications'][0])
  228. {
  229. $returnType = '';
  230. $request = $this->postApiV3EmailCertificationsRequest($post_api_v3_email_certifications_request, $contentType);
  231. return $this->client
  232. ->sendAsync($request, $this->createHttpClientOption())
  233. ->then(
  234. function ($response) use ($returnType) {
  235. return [null, $response->getStatusCode(), $response->getHeaders()];
  236. },
  237. function ($exception) {
  238. $response = $exception->getResponse();
  239. $statusCode = $response->getStatusCode();
  240. throw new ApiException(
  241. sprintf(
  242. '[%d] Error connecting to the API (%s)',
  243. $statusCode,
  244. $exception->getRequest()->getUri()
  245. ),
  246. $statusCode,
  247. $response->getHeaders(),
  248. (string) $response->getBody()
  249. );
  250. }
  251. );
  252. }
  253. /**
  254. * Create request for operation 'postApiV3EmailCertifications'
  255. *
  256. * @param \WikipaliApi\Model\PostApiV3EmailCertificationsRequest $post_api_v3_email_certifications_request (required)
  257. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3EmailCertifications'] to see the possible values for this operation
  258. *
  259. * @throws \InvalidArgumentException
  260. * @return \GuzzleHttp\Psr7\Request
  261. */
  262. public function postApiV3EmailCertificationsRequest($post_api_v3_email_certifications_request, string $contentType = self::contentTypes['postApiV3EmailCertifications'][0])
  263. {
  264. // verify the required parameter 'post_api_v3_email_certifications_request' is set
  265. if ($post_api_v3_email_certifications_request === null || (is_array($post_api_v3_email_certifications_request) && count($post_api_v3_email_certifications_request) === 0)) {
  266. throw new \InvalidArgumentException(
  267. 'Missing the required parameter $post_api_v3_email_certifications_request when calling postApiV3EmailCertifications'
  268. );
  269. }
  270. $resourcePath = '/v3/email-certifications';
  271. $formParams = [];
  272. $queryParams = [];
  273. $headerParams = [];
  274. $httpBody = '';
  275. $multipart = false;
  276. $headers = $this->headerSelector->selectHeaders(
  277. ['application/problem+json', ],
  278. $contentType,
  279. $multipart
  280. );
  281. // for model (json/xml)
  282. if (isset($post_api_v3_email_certifications_request)) {
  283. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  284. # if Content-Type contains "application/json", json_encode the body
  285. try {
  286. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_email_certifications_request), JSON_THROW_ON_ERROR);
  287. } catch (\JsonException $e) {
  288. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  289. }
  290. } else {
  291. $httpBody = $post_api_v3_email_certifications_request;
  292. }
  293. } elseif (count($formParams) > 0) {
  294. if ($multipart) {
  295. $multipartContents = [];
  296. foreach ($formParams as $formParamName => $formParamValue) {
  297. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  298. foreach ($formParamValueItems as $formParamValueItem) {
  299. $multipartContents[] = [
  300. 'name' => $formParamName,
  301. 'contents' => $formParamValueItem
  302. ];
  303. }
  304. }
  305. // for HTTP post (form)
  306. $httpBody = new MultipartStream($multipartContents);
  307. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  308. # if Content-Type contains "application/json", json_encode the form parameters
  309. try {
  310. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  311. } catch (\JsonException $e) {
  312. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  313. }
  314. } else {
  315. // for HTTP post (form)
  316. $httpBody = ObjectSerializer::buildQuery($formParams);
  317. }
  318. }
  319. // this endpoint requires Bearer authentication (access token)
  320. if (!empty($this->config->getAccessToken())) {
  321. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  322. }
  323. $defaultHeaders = [];
  324. if ($this->config->getUserAgent()) {
  325. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  326. }
  327. $headers = array_merge(
  328. $defaultHeaders,
  329. $headerParams,
  330. $headers
  331. );
  332. $operationHost = $this->config->getHost();
  333. $query = ObjectSerializer::buildQuery($queryParams);
  334. return new Request(
  335. 'POST',
  336. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  337. $headers,
  338. $httpBody
  339. );
  340. }
  341. /**
  342. * Create http client option
  343. *
  344. * @throws \RuntimeException on file opening failure
  345. * @return array of http client options
  346. */
  347. protected function createHttpClientOption()
  348. {
  349. $options = [];
  350. if ($this->config->getDebug()) {
  351. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  352. if (!$options[RequestOptions::DEBUG]) {
  353. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  354. }
  355. }
  356. if ($this->config->getCertFile()) {
  357. $options[RequestOptions::CERT] = $this->config->getCertFile();
  358. }
  359. if ($this->config->getKeyFile()) {
  360. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  361. }
  362. return $options;
  363. }
  364. private function handleResponseWithDataType(
  365. string $dataType,
  366. RequestInterface $request,
  367. ResponseInterface $response
  368. ): array {
  369. if ($dataType === '\SplFileObject') {
  370. $content = $response->getBody(); //stream goes to serializer
  371. } else {
  372. $content = (string) $response->getBody();
  373. if ($dataType !== 'string') {
  374. try {
  375. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  376. } catch (\JsonException $exception) {
  377. throw new ApiException(
  378. sprintf(
  379. 'Error JSON decoding server response (%s)',
  380. $request->getUri()
  381. ),
  382. $response->getStatusCode(),
  383. $response->getHeaders(),
  384. $content
  385. );
  386. }
  387. }
  388. }
  389. return [
  390. ObjectSerializer::deserialize($content, $dataType, []),
  391. $response->getStatusCode(),
  392. $response->getHeaders()
  393. ];
  394. }
  395. private function responseWithinRangeCode(
  396. string $rangeCode,
  397. int $statusCode
  398. ): bool {
  399. $left = (int) ($rangeCode[0].'00');
  400. $right = (int) ($rangeCode[0].'99');
  401. return $statusCode >= $left && $statusCode <= $right;
  402. }
  403. }