PasswordResetsApi.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. <?php
  2. /**
  3. * PasswordResetsApi
  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. * PasswordResetsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class PasswordResetsApi
  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. 'getApiV3PasswordResetsToken' => [
  69. 'application/json',
  70. ],
  71. 'patchApiV3PasswordResetsToken' => [
  72. 'application/json',
  73. ],
  74. 'postApiV3PasswordResets' => [
  75. 'application/json',
  76. ],
  77. ];
  78. /**
  79. * @param ClientInterface $client
  80. * @param Configuration $config
  81. * @param HeaderSelector $selector
  82. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  83. */
  84. public function __construct(
  85. ?ClientInterface $client = null,
  86. ?Configuration $config = null,
  87. ?HeaderSelector $selector = null,
  88. int $hostIndex = 0
  89. ) {
  90. $this->client = $client ?: new Client();
  91. $this->config = $config ?: Configuration::getDefaultConfiguration();
  92. $this->headerSelector = $selector ?: new HeaderSelector();
  93. $this->hostIndex = $hostIndex;
  94. }
  95. /**
  96. * Set the host index
  97. *
  98. * @param int $hostIndex Host index (required)
  99. */
  100. public function setHostIndex($hostIndex): void
  101. {
  102. $this->hostIndex = $hostIndex;
  103. }
  104. /**
  105. * Get the host index
  106. *
  107. * @return int Host index
  108. */
  109. public function getHostIndex()
  110. {
  111. return $this->hostIndex;
  112. }
  113. /**
  114. * @return Configuration
  115. */
  116. public function getConfig()
  117. {
  118. return $this->config;
  119. }
  120. /**
  121. * Operation getApiV3PasswordResetsToken
  122. *
  123. * 查看一次待完成的重置
  124. *
  125. * @param string $token 邮件链接里的 token (required)
  126. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  127. *
  128. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  129. * @throws \InvalidArgumentException
  130. * @return \WikipaliApi\Model\GetApiV3PasswordResetsToken200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  131. */
  132. public function getApiV3PasswordResetsToken($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  133. {
  134. list($response) = $this->getApiV3PasswordResetsTokenWithHttpInfo($token, $contentType);
  135. return $response;
  136. }
  137. /**
  138. * Operation getApiV3PasswordResetsTokenWithHttpInfo
  139. *
  140. * 查看一次待完成的重置
  141. *
  142. * @param string $token 邮件链接里的 token (required)
  143. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  144. *
  145. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  146. * @throws \InvalidArgumentException
  147. * @return array of \WikipaliApi\Model\GetApiV3PasswordResetsToken200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  148. */
  149. public function getApiV3PasswordResetsTokenWithHttpInfo($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  150. {
  151. $request = $this->getApiV3PasswordResetsTokenRequest($token, $contentType);
  152. try {
  153. $options = $this->createHttpClientOption();
  154. try {
  155. $response = $this->client->send($request, $options);
  156. } catch (RequestException $e) {
  157. throw new ApiException(
  158. "[{$e->getCode()}] {$e->getMessage()}",
  159. (int) $e->getCode(),
  160. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  161. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  162. );
  163. } catch (ConnectException $e) {
  164. throw new ApiException(
  165. "[{$e->getCode()}] {$e->getMessage()}",
  166. (int) $e->getCode(),
  167. null,
  168. null
  169. );
  170. }
  171. $statusCode = $response->getStatusCode();
  172. switch($statusCode) {
  173. case 200:
  174. return $this->handleResponseWithDataType(
  175. '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response',
  176. $request,
  177. $response,
  178. );
  179. case 404:
  180. return $this->handleResponseWithDataType(
  181. '\WikipaliApi\Model\ProblemDetails',
  182. $request,
  183. $response,
  184. );
  185. case 422:
  186. return $this->handleResponseWithDataType(
  187. '\WikipaliApi\Model\ProblemDetails',
  188. $request,
  189. $response,
  190. );
  191. }
  192. if ($statusCode < 200 || $statusCode > 299) {
  193. throw new ApiException(
  194. sprintf(
  195. '[%d] Error connecting to the API (%s)',
  196. $statusCode,
  197. (string) $request->getUri()
  198. ),
  199. $statusCode,
  200. $response->getHeaders(),
  201. (string) $response->getBody()
  202. );
  203. }
  204. return $this->handleResponseWithDataType(
  205. '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response',
  206. $request,
  207. $response,
  208. );
  209. } catch (ApiException $e) {
  210. switch ($e->getCode()) {
  211. case 200:
  212. $data = ObjectSerializer::deserialize(
  213. $e->getResponseBody(),
  214. '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response',
  215. $e->getResponseHeaders()
  216. );
  217. $e->setResponseObject($data);
  218. throw $e;
  219. case 404:
  220. $data = ObjectSerializer::deserialize(
  221. $e->getResponseBody(),
  222. '\WikipaliApi\Model\ProblemDetails',
  223. $e->getResponseHeaders()
  224. );
  225. $e->setResponseObject($data);
  226. throw $e;
  227. case 422:
  228. $data = ObjectSerializer::deserialize(
  229. $e->getResponseBody(),
  230. '\WikipaliApi\Model\ProblemDetails',
  231. $e->getResponseHeaders()
  232. );
  233. $e->setResponseObject($data);
  234. throw $e;
  235. }
  236. throw $e;
  237. }
  238. }
  239. /**
  240. * Operation getApiV3PasswordResetsTokenAsync
  241. *
  242. * 查看一次待完成的重置
  243. *
  244. * @param string $token 邮件链接里的 token (required)
  245. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  246. *
  247. * @throws \InvalidArgumentException
  248. * @return \GuzzleHttp\Promise\PromiseInterface
  249. */
  250. public function getApiV3PasswordResetsTokenAsync($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  251. {
  252. return $this->getApiV3PasswordResetsTokenAsyncWithHttpInfo($token, $contentType)
  253. ->then(
  254. function ($response) {
  255. return $response[0];
  256. }
  257. );
  258. }
  259. /**
  260. * Operation getApiV3PasswordResetsTokenAsyncWithHttpInfo
  261. *
  262. * 查看一次待完成的重置
  263. *
  264. * @param string $token 邮件链接里的 token (required)
  265. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  266. *
  267. * @throws \InvalidArgumentException
  268. * @return \GuzzleHttp\Promise\PromiseInterface
  269. */
  270. public function getApiV3PasswordResetsTokenAsyncWithHttpInfo($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  271. {
  272. $returnType = '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response';
  273. $request = $this->getApiV3PasswordResetsTokenRequest($token, $contentType);
  274. return $this->client
  275. ->sendAsync($request, $this->createHttpClientOption())
  276. ->then(
  277. function ($response) use ($returnType) {
  278. if ($returnType === '\SplFileObject') {
  279. $content = $response->getBody(); //stream goes to serializer
  280. } else {
  281. $content = (string) $response->getBody();
  282. if ($returnType !== 'string') {
  283. $content = json_decode($content);
  284. }
  285. }
  286. return [
  287. ObjectSerializer::deserialize($content, $returnType, []),
  288. $response->getStatusCode(),
  289. $response->getHeaders()
  290. ];
  291. },
  292. function ($exception) {
  293. $response = $exception->getResponse();
  294. $statusCode = $response->getStatusCode();
  295. throw new ApiException(
  296. sprintf(
  297. '[%d] Error connecting to the API (%s)',
  298. $statusCode,
  299. $exception->getRequest()->getUri()
  300. ),
  301. $statusCode,
  302. $response->getHeaders(),
  303. (string) $response->getBody()
  304. );
  305. }
  306. );
  307. }
  308. /**
  309. * Create request for operation 'getApiV3PasswordResetsToken'
  310. *
  311. * @param string $token 邮件链接里的 token (required)
  312. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  313. *
  314. * @throws \InvalidArgumentException
  315. * @return \GuzzleHttp\Psr7\Request
  316. */
  317. public function getApiV3PasswordResetsTokenRequest($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  318. {
  319. // verify the required parameter 'token' is set
  320. if ($token === null || (is_array($token) && count($token) === 0)) {
  321. throw new \InvalidArgumentException(
  322. 'Missing the required parameter $token when calling getApiV3PasswordResetsToken'
  323. );
  324. }
  325. $resourcePath = '/v3/password-resets/{token}';
  326. $formParams = [];
  327. $queryParams = [];
  328. $headerParams = [];
  329. $httpBody = '';
  330. $multipart = false;
  331. // path params
  332. if ($token !== null) {
  333. $resourcePath = str_replace(
  334. '{token}',
  335. ObjectSerializer::toPathValue($token),
  336. $resourcePath
  337. );
  338. }
  339. $headers = $this->headerSelector->selectHeaders(
  340. ['application/json', 'application/problem+json', ],
  341. $contentType,
  342. $multipart
  343. );
  344. // for model (json/xml)
  345. if (count($formParams) > 0) {
  346. if ($multipart) {
  347. $multipartContents = [];
  348. foreach ($formParams as $formParamName => $formParamValue) {
  349. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  350. foreach ($formParamValueItems as $formParamValueItem) {
  351. $multipartContents[] = [
  352. 'name' => $formParamName,
  353. 'contents' => $formParamValueItem
  354. ];
  355. }
  356. }
  357. // for HTTP post (form)
  358. $httpBody = new MultipartStream($multipartContents);
  359. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  360. # if Content-Type contains "application/json", json_encode the form parameters
  361. try {
  362. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  363. } catch (\JsonException $e) {
  364. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  365. }
  366. } else {
  367. // for HTTP post (form)
  368. $httpBody = ObjectSerializer::buildQuery($formParams);
  369. }
  370. }
  371. // this endpoint requires Bearer authentication (access token)
  372. if (!empty($this->config->getAccessToken())) {
  373. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  374. }
  375. $defaultHeaders = [];
  376. if ($this->config->getUserAgent()) {
  377. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  378. }
  379. $headers = array_merge(
  380. $defaultHeaders,
  381. $headerParams,
  382. $headers
  383. );
  384. $operationHost = $this->config->getHost();
  385. $query = ObjectSerializer::buildQuery($queryParams);
  386. return new Request(
  387. 'GET',
  388. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  389. $headers,
  390. $httpBody
  391. );
  392. }
  393. /**
  394. * Operation patchApiV3PasswordResetsToken
  395. *
  396. * 设置新密码
  397. *
  398. * @param string $token 邮件链接里的 token (required)
  399. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request patch_api_v3_password_resets_token_request (required)
  400. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  401. *
  402. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  403. * @throws \InvalidArgumentException
  404. * @return void
  405. */
  406. public function patchApiV3PasswordResetsToken($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  407. {
  408. $this->patchApiV3PasswordResetsTokenWithHttpInfo($token, $patch_api_v3_password_resets_token_request, $contentType);
  409. }
  410. /**
  411. * Operation patchApiV3PasswordResetsTokenWithHttpInfo
  412. *
  413. * 设置新密码
  414. *
  415. * @param string $token 邮件链接里的 token (required)
  416. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  417. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  418. *
  419. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  420. * @throws \InvalidArgumentException
  421. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  422. */
  423. public function patchApiV3PasswordResetsTokenWithHttpInfo($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  424. {
  425. $request = $this->patchApiV3PasswordResetsTokenRequest($token, $patch_api_v3_password_resets_token_request, $contentType);
  426. try {
  427. $options = $this->createHttpClientOption();
  428. try {
  429. $response = $this->client->send($request, $options);
  430. } catch (RequestException $e) {
  431. throw new ApiException(
  432. "[{$e->getCode()}] {$e->getMessage()}",
  433. (int) $e->getCode(),
  434. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  435. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  436. );
  437. } catch (ConnectException $e) {
  438. throw new ApiException(
  439. "[{$e->getCode()}] {$e->getMessage()}",
  440. (int) $e->getCode(),
  441. null,
  442. null
  443. );
  444. }
  445. $statusCode = $response->getStatusCode();
  446. return [null, $statusCode, $response->getHeaders()];
  447. } catch (ApiException $e) {
  448. switch ($e->getCode()) {
  449. case 404:
  450. $data = ObjectSerializer::deserialize(
  451. $e->getResponseBody(),
  452. '\WikipaliApi\Model\ProblemDetails',
  453. $e->getResponseHeaders()
  454. );
  455. $e->setResponseObject($data);
  456. throw $e;
  457. case 422:
  458. $data = ObjectSerializer::deserialize(
  459. $e->getResponseBody(),
  460. '\WikipaliApi\Model\ProblemDetails',
  461. $e->getResponseHeaders()
  462. );
  463. $e->setResponseObject($data);
  464. throw $e;
  465. }
  466. throw $e;
  467. }
  468. }
  469. /**
  470. * Operation patchApiV3PasswordResetsTokenAsync
  471. *
  472. * 设置新密码
  473. *
  474. * @param string $token 邮件链接里的 token (required)
  475. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  476. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  477. *
  478. * @throws \InvalidArgumentException
  479. * @return \GuzzleHttp\Promise\PromiseInterface
  480. */
  481. public function patchApiV3PasswordResetsTokenAsync($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  482. {
  483. return $this->patchApiV3PasswordResetsTokenAsyncWithHttpInfo($token, $patch_api_v3_password_resets_token_request, $contentType)
  484. ->then(
  485. function ($response) {
  486. return $response[0];
  487. }
  488. );
  489. }
  490. /**
  491. * Operation patchApiV3PasswordResetsTokenAsyncWithHttpInfo
  492. *
  493. * 设置新密码
  494. *
  495. * @param string $token 邮件链接里的 token (required)
  496. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  497. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  498. *
  499. * @throws \InvalidArgumentException
  500. * @return \GuzzleHttp\Promise\PromiseInterface
  501. */
  502. public function patchApiV3PasswordResetsTokenAsyncWithHttpInfo($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  503. {
  504. $returnType = '';
  505. $request = $this->patchApiV3PasswordResetsTokenRequest($token, $patch_api_v3_password_resets_token_request, $contentType);
  506. return $this->client
  507. ->sendAsync($request, $this->createHttpClientOption())
  508. ->then(
  509. function ($response) use ($returnType) {
  510. return [null, $response->getStatusCode(), $response->getHeaders()];
  511. },
  512. function ($exception) {
  513. $response = $exception->getResponse();
  514. $statusCode = $response->getStatusCode();
  515. throw new ApiException(
  516. sprintf(
  517. '[%d] Error connecting to the API (%s)',
  518. $statusCode,
  519. $exception->getRequest()->getUri()
  520. ),
  521. $statusCode,
  522. $response->getHeaders(),
  523. (string) $response->getBody()
  524. );
  525. }
  526. );
  527. }
  528. /**
  529. * Create request for operation 'patchApiV3PasswordResetsToken'
  530. *
  531. * @param string $token 邮件链接里的 token (required)
  532. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  533. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  534. *
  535. * @throws \InvalidArgumentException
  536. * @return \GuzzleHttp\Psr7\Request
  537. */
  538. public function patchApiV3PasswordResetsTokenRequest($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  539. {
  540. // verify the required parameter 'token' is set
  541. if ($token === null || (is_array($token) && count($token) === 0)) {
  542. throw new \InvalidArgumentException(
  543. 'Missing the required parameter $token when calling patchApiV3PasswordResetsToken'
  544. );
  545. }
  546. // verify the required parameter 'patch_api_v3_password_resets_token_request' is set
  547. if ($patch_api_v3_password_resets_token_request === null || (is_array($patch_api_v3_password_resets_token_request) && count($patch_api_v3_password_resets_token_request) === 0)) {
  548. throw new \InvalidArgumentException(
  549. 'Missing the required parameter $patch_api_v3_password_resets_token_request when calling patchApiV3PasswordResetsToken'
  550. );
  551. }
  552. $resourcePath = '/v3/password-resets/{token}';
  553. $formParams = [];
  554. $queryParams = [];
  555. $headerParams = [];
  556. $httpBody = '';
  557. $multipart = false;
  558. // path params
  559. if ($token !== null) {
  560. $resourcePath = str_replace(
  561. '{token}',
  562. ObjectSerializer::toPathValue($token),
  563. $resourcePath
  564. );
  565. }
  566. $headers = $this->headerSelector->selectHeaders(
  567. ['application/problem+json', ],
  568. $contentType,
  569. $multipart
  570. );
  571. // for model (json/xml)
  572. if (isset($patch_api_v3_password_resets_token_request)) {
  573. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  574. # if Content-Type contains "application/json", json_encode the body
  575. try {
  576. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_password_resets_token_request), JSON_THROW_ON_ERROR);
  577. } catch (\JsonException $e) {
  578. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  579. }
  580. } else {
  581. $httpBody = $patch_api_v3_password_resets_token_request;
  582. }
  583. } elseif (count($formParams) > 0) {
  584. if ($multipart) {
  585. $multipartContents = [];
  586. foreach ($formParams as $formParamName => $formParamValue) {
  587. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  588. foreach ($formParamValueItems as $formParamValueItem) {
  589. $multipartContents[] = [
  590. 'name' => $formParamName,
  591. 'contents' => $formParamValueItem
  592. ];
  593. }
  594. }
  595. // for HTTP post (form)
  596. $httpBody = new MultipartStream($multipartContents);
  597. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  598. # if Content-Type contains "application/json", json_encode the form parameters
  599. try {
  600. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  601. } catch (\JsonException $e) {
  602. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  603. }
  604. } else {
  605. // for HTTP post (form)
  606. $httpBody = ObjectSerializer::buildQuery($formParams);
  607. }
  608. }
  609. // this endpoint requires Bearer authentication (access token)
  610. if (!empty($this->config->getAccessToken())) {
  611. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  612. }
  613. $defaultHeaders = [];
  614. if ($this->config->getUserAgent()) {
  615. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  616. }
  617. $headers = array_merge(
  618. $defaultHeaders,
  619. $headerParams,
  620. $headers
  621. );
  622. $operationHost = $this->config->getHost();
  623. $query = ObjectSerializer::buildQuery($queryParams);
  624. return new Request(
  625. 'PATCH',
  626. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  627. $headers,
  628. $httpBody
  629. );
  630. }
  631. /**
  632. * Operation postApiV3PasswordResets
  633. *
  634. * 申请重置密码(发邮件)
  635. *
  636. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request post_api_v3_password_resets_request (required)
  637. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  638. *
  639. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  640. * @throws \InvalidArgumentException
  641. * @return void
  642. */
  643. public function postApiV3PasswordResets($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  644. {
  645. $this->postApiV3PasswordResetsWithHttpInfo($post_api_v3_password_resets_request, $contentType);
  646. }
  647. /**
  648. * Operation postApiV3PasswordResetsWithHttpInfo
  649. *
  650. * 申请重置密码(发邮件)
  651. *
  652. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  653. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  654. *
  655. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  656. * @throws \InvalidArgumentException
  657. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  658. */
  659. public function postApiV3PasswordResetsWithHttpInfo($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  660. {
  661. $request = $this->postApiV3PasswordResetsRequest($post_api_v3_password_resets_request, $contentType);
  662. try {
  663. $options = $this->createHttpClientOption();
  664. try {
  665. $response = $this->client->send($request, $options);
  666. } catch (RequestException $e) {
  667. throw new ApiException(
  668. "[{$e->getCode()}] {$e->getMessage()}",
  669. (int) $e->getCode(),
  670. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  671. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  672. );
  673. } catch (ConnectException $e) {
  674. throw new ApiException(
  675. "[{$e->getCode()}] {$e->getMessage()}",
  676. (int) $e->getCode(),
  677. null,
  678. null
  679. );
  680. }
  681. $statusCode = $response->getStatusCode();
  682. return [null, $statusCode, $response->getHeaders()];
  683. } catch (ApiException $e) {
  684. switch ($e->getCode()) {
  685. case 422:
  686. $data = ObjectSerializer::deserialize(
  687. $e->getResponseBody(),
  688. '\WikipaliApi\Model\ProblemDetails',
  689. $e->getResponseHeaders()
  690. );
  691. $e->setResponseObject($data);
  692. throw $e;
  693. case 429:
  694. $data = ObjectSerializer::deserialize(
  695. $e->getResponseBody(),
  696. '\WikipaliApi\Model\ProblemDetails',
  697. $e->getResponseHeaders()
  698. );
  699. $e->setResponseObject($data);
  700. throw $e;
  701. case 503:
  702. $data = ObjectSerializer::deserialize(
  703. $e->getResponseBody(),
  704. '\WikipaliApi\Model\ProblemDetails',
  705. $e->getResponseHeaders()
  706. );
  707. $e->setResponseObject($data);
  708. throw $e;
  709. }
  710. throw $e;
  711. }
  712. }
  713. /**
  714. * Operation postApiV3PasswordResetsAsync
  715. *
  716. * 申请重置密码(发邮件)
  717. *
  718. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  719. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  720. *
  721. * @throws \InvalidArgumentException
  722. * @return \GuzzleHttp\Promise\PromiseInterface
  723. */
  724. public function postApiV3PasswordResetsAsync($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  725. {
  726. return $this->postApiV3PasswordResetsAsyncWithHttpInfo($post_api_v3_password_resets_request, $contentType)
  727. ->then(
  728. function ($response) {
  729. return $response[0];
  730. }
  731. );
  732. }
  733. /**
  734. * Operation postApiV3PasswordResetsAsyncWithHttpInfo
  735. *
  736. * 申请重置密码(发邮件)
  737. *
  738. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  739. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  740. *
  741. * @throws \InvalidArgumentException
  742. * @return \GuzzleHttp\Promise\PromiseInterface
  743. */
  744. public function postApiV3PasswordResetsAsyncWithHttpInfo($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  745. {
  746. $returnType = '';
  747. $request = $this->postApiV3PasswordResetsRequest($post_api_v3_password_resets_request, $contentType);
  748. return $this->client
  749. ->sendAsync($request, $this->createHttpClientOption())
  750. ->then(
  751. function ($response) use ($returnType) {
  752. return [null, $response->getStatusCode(), $response->getHeaders()];
  753. },
  754. function ($exception) {
  755. $response = $exception->getResponse();
  756. $statusCode = $response->getStatusCode();
  757. throw new ApiException(
  758. sprintf(
  759. '[%d] Error connecting to the API (%s)',
  760. $statusCode,
  761. $exception->getRequest()->getUri()
  762. ),
  763. $statusCode,
  764. $response->getHeaders(),
  765. (string) $response->getBody()
  766. );
  767. }
  768. );
  769. }
  770. /**
  771. * Create request for operation 'postApiV3PasswordResets'
  772. *
  773. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  774. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  775. *
  776. * @throws \InvalidArgumentException
  777. * @return \GuzzleHttp\Psr7\Request
  778. */
  779. public function postApiV3PasswordResetsRequest($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  780. {
  781. // verify the required parameter 'post_api_v3_password_resets_request' is set
  782. if ($post_api_v3_password_resets_request === null || (is_array($post_api_v3_password_resets_request) && count($post_api_v3_password_resets_request) === 0)) {
  783. throw new \InvalidArgumentException(
  784. 'Missing the required parameter $post_api_v3_password_resets_request when calling postApiV3PasswordResets'
  785. );
  786. }
  787. $resourcePath = '/v3/password-resets';
  788. $formParams = [];
  789. $queryParams = [];
  790. $headerParams = [];
  791. $httpBody = '';
  792. $multipart = false;
  793. $headers = $this->headerSelector->selectHeaders(
  794. ['application/problem+json', ],
  795. $contentType,
  796. $multipart
  797. );
  798. // for model (json/xml)
  799. if (isset($post_api_v3_password_resets_request)) {
  800. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  801. # if Content-Type contains "application/json", json_encode the body
  802. try {
  803. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_password_resets_request), JSON_THROW_ON_ERROR);
  804. } catch (\JsonException $e) {
  805. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  806. }
  807. } else {
  808. $httpBody = $post_api_v3_password_resets_request;
  809. }
  810. } elseif (count($formParams) > 0) {
  811. if ($multipart) {
  812. $multipartContents = [];
  813. foreach ($formParams as $formParamName => $formParamValue) {
  814. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  815. foreach ($formParamValueItems as $formParamValueItem) {
  816. $multipartContents[] = [
  817. 'name' => $formParamName,
  818. 'contents' => $formParamValueItem
  819. ];
  820. }
  821. }
  822. // for HTTP post (form)
  823. $httpBody = new MultipartStream($multipartContents);
  824. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  825. # if Content-Type contains "application/json", json_encode the form parameters
  826. try {
  827. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  828. } catch (\JsonException $e) {
  829. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  830. }
  831. } else {
  832. // for HTTP post (form)
  833. $httpBody = ObjectSerializer::buildQuery($formParams);
  834. }
  835. }
  836. // this endpoint requires Bearer authentication (access token)
  837. if (!empty($this->config->getAccessToken())) {
  838. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  839. }
  840. $defaultHeaders = [];
  841. if ($this->config->getUserAgent()) {
  842. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  843. }
  844. $headers = array_merge(
  845. $defaultHeaders,
  846. $headerParams,
  847. $headers
  848. );
  849. $operationHost = $this->config->getHost();
  850. $query = ObjectSerializer::buildQuery($queryParams);
  851. return new Request(
  852. 'POST',
  853. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  854. $headers,
  855. $httpBody
  856. );
  857. }
  858. /**
  859. * Create http client option
  860. *
  861. * @throws \RuntimeException on file opening failure
  862. * @return array of http client options
  863. */
  864. protected function createHttpClientOption()
  865. {
  866. $options = [];
  867. if ($this->config->getDebug()) {
  868. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  869. if (!$options[RequestOptions::DEBUG]) {
  870. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  871. }
  872. }
  873. if ($this->config->getCertFile()) {
  874. $options[RequestOptions::CERT] = $this->config->getCertFile();
  875. }
  876. if ($this->config->getKeyFile()) {
  877. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  878. }
  879. return $options;
  880. }
  881. private function handleResponseWithDataType(
  882. string $dataType,
  883. RequestInterface $request,
  884. ResponseInterface $response
  885. ): array {
  886. if ($dataType === '\SplFileObject') {
  887. $content = $response->getBody(); //stream goes to serializer
  888. } else {
  889. $content = (string) $response->getBody();
  890. if ($dataType !== 'string') {
  891. try {
  892. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  893. } catch (\JsonException $exception) {
  894. throw new ApiException(
  895. sprintf(
  896. 'Error JSON decoding server response (%s)',
  897. $request->getUri()
  898. ),
  899. $response->getStatusCode(),
  900. $response->getHeaders(),
  901. $content
  902. );
  903. }
  904. }
  905. }
  906. return [
  907. ObjectSerializer::deserialize($content, $dataType, []),
  908. $response->getStatusCode(),
  909. $response->getHeaders()
  910. ];
  911. }
  912. private function responseWithinRangeCode(
  913. string $rangeCode,
  914. int $statusCode
  915. ): bool {
  916. $left = (int) ($rangeCode[0].'00');
  917. $right = (int) ($rangeCode[0].'99');
  918. return $statusCode >= $left && $statusCode <= $right;
  919. }
  920. }