沢山APIの追加

諏訪子 <suwako@076.moe>、2026-04-28 14:39
コミット d4176e6553e5d3436270c0616031552f1c511ee1 ・親 430249e ・ファイルを見る

5個のファイル、+940 -33

変更 route.php
@@ -61,6 +61,7 @@
6161 if (OPENPROVIDER_ENABLED) {
6262 $routes[] = Route::add('GET', 'openprovider', Op::class.'@index');
6363 $routes[] = Route::add('GET', 'openprovider/listcustomers', Op::class.'@opListCustomers');
64+ $routes[] = Route::add('GET', 'openprovider/createcustomer', Op::class.'@opCreateCustomers');
6465 $routes[] = Route::add('GET', 'openprovider/getcustomer/{handle}', Op::class.'@opGetCustomer');
6566 $routes[] = Route::add('GET', 'openprovider/listtlds', Op::class.'@opListTlds');
6667 $routes[] = Route::add('GET', 'openprovider/gettld/{tld}', Op::class.'@opGetTld');
@@ -73,6 +73,81 @@
7373 }
7474 }
7575
76+ public function opCreateCustomer(array $params): void {
77+ try {
78+ kys('sasa');
79+ if (isset($_POST)) kys($_POST);
80+ $payload = [
81+ 'additional_data' => [
82+ 'company_registration_number' => '',
83+ 'company_url' => '',
84+ ],
85+ 'address' => [
86+ 'city' => '',
87+ 'country' => '',
88+ 'number' => '',
89+ 'state' => '',
90+ 'street' => '',
91+ 'zipcode' => '',
92+ ],
93+ 'comments' => '',
94+ 'company_name' => '',
95+ 'email' => '',
96+ 'fax' => [
97+ 'area_code' => '',
98+ 'country_code' => '',
99+ 'subscriber_number' => '',
100+ ],
101+ 'locale' => 'ja_JP',
102+ 'name' => [
103+ 'first_name' => '',
104+ 'full_name' => '',
105+ 'last_name' => '',
106+ ],
107+ 'phone' => [
108+ 'area_code' => '',
109+ 'country_code' => '',
110+ 'subscriber_number' => '',
111+ ],
112+ ];
113+ $tmpl = new Template('/openprovider/');
114+ $pagetit = "OpenProvider管理 - 顧客様の新規作成";
115+ $description = '';
116+
117+ // ユーザー
118+ $auth = new Auth();
119+ $user = $auth->getLoggedInUser();
120+ $tmpl->assign('user', $user);
121+
122+ $tmpl->assign('pagetit', $pagetit);
123+ $tmpl->assign('curPage', 'openprovider');
124+ $tmpl->assign('custCss', true);
125+ $tmpl->assign('menu', $this->getMenu());
126+ $tmpl->assign('description', $description);
127+
128+ if (!$user || $user->role !== \Roles::ADMIN) goto noaccess;
129+ if (isset($_POST)) {
130+ $op = new Openprovider();
131+ $op->login();
132+ $data = $op->createCustomer($_POST, true);
133+ kys($data->data);
134+ header("Location: /openprovider/getcustomer/{$data->data['handle']}");
135+ exit();
136+ }
137+
138+ $tmpl->assign('data', $payload);
139+ $tmpl->render('createcustomer');
140+ kys('sasa');
141+
142+ exit();
143+
144+ noaccess:
145+ $tmpl->render('nopermission');
146+ } catch (\Exception $e) {
147+ throw new \Exception($e->getMessage());
148+ }
149+ }
150+
76151 public function opGetCustomer(array $params): void {
77152 try {
78153 $handle = '';
@@ -80,14 +80,33 @@
8080 return \Result::Error('ログインに失敗。');
8181 }
8282
83- // カスタマー
83+ /**
84+ * SpanExpert向けログインURLの生成
85+ * @todo テスト
86+ *
87+ * @param array $payload フォームデータ
88+ * @return Result
89+ */
90+ public function generateLoginUrlSpamExpert(array $payload = []): \Result {
91+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
8492
93+ $uri = '/spam-expert-generate-login-url';
94+ $curl = $this->setupCurl($uri, 'POST', $payload);
95+ $res = $this->curlResult($curl);
96+ if (isset($res->data['data'])) {
97+ return \Result::Success('DNSテンプレートの追加に成功。', $res->data);
98+ }
99+
100+ return \Result::Error('DNSテンプレートの追加に失敗。');
101+ }
102+
85103 // ドメイン
86104
87105 //// ドメイン
88106
89107 /***
90108 * ドメイン一覧。
109+ * @todo テスト
91110 *
92111 * @return Result 結果。
93112 */
@@ -108,6 +127,7 @@
108127
109128 /**
110129 * ドメイン名の登録。
130+ * @todo テスト
111131 *
112132 * @param string $name 登録したいドメイン名(例:"076studio.jp")
113133 * @param array $info カスタマー情報等
@@ -197,59 +217,67 @@
197217
198218 //// 追加データ
199219
200- //// 顧客様の追加データ
201-
202220 /**
203- * 顧客様の一覧
221+ * 追加データの受け取り
222+ * @todo テスト
204223 *
205224 * @param array $query 検索クエリー
206225 * @return Result
207226 */
208- public function listCustomers(array $query = []): \Result {
227+ public function getDomainAdditionalData(array $query): \Result {
209228 if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
210- $cache = $this->getCache('listcustomers');
211- if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
229+ $name = '';
230+ $ext = '';
231+ if (isset($query['domain.name'])) $name = $query['domain.name'];
232+ if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
233+ $cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
212234
213- foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? '1' : '0'; }
214- $uri = '/customers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
235+ $cache = $this->getCache($cacheName);
236+ if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
237+
238+ $uri = "/domains/additional-data?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
215239 $curl = $this->setupCurl($uri);
216240 $res = $this->curlResult($curl);
217241 if (isset($res->data['data'])) {
218- $res->data['query'] = $query;
219- $this->setCache('listcustomers', $res->data);
242+ $this->setCache($cacheName, $res->data);
220243 return \Result::Success('', $res->data);
221244 }
222245
223- return \Result::Error('顧客様一覧の受け取りに失敗。');
246+ return \Result::Error('ドメインの追加データの受け取りに失敗。');
224247 }
225248
249+ //// 顧客様の追加データ
250+
226251 /**
227- * 顧客様の表示
252+ * 顧客様の追加データの受け取り
253+ * @todo テスト
228254 *
229- * @param string $handle ハンドル
230- * @param bool $withAdditionalData 詳細データ含むか?
255+ * @param array $query 検索クエリー
231256 * @return Result
232257 */
233- public function getCustomer(string $handle, bool $withAdditionalData = false): \Result {
258+ public function getDomainCustomerAdditionalData(array $query): \Result {
234259 if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
235- $cacheName = "getcustomer-{$handle}";
260+ $name = '';
261+ $ext = '';
262+ if (isset($query['domain.name'])) $name = $query['domain.name'];
263+ if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
264+ $cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
265+
236266 $cache = $this->getCache($cacheName);
237- if ($this->isValidLifespan($cache, $handle, 'handle')) return \Result::Success('', $cache);
267+ if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
238268
239- $query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
240- $uri = "/customers/{$handle}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
241- // kys($uri);
269+ $uri = "/domains/additional-data/customers?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
242270 $curl = $this->setupCurl($uri);
243271 $res = $this->curlResult($curl);
244272 if (isset($res->data['data'])) {
245- $res->data['handle'] = $handle;
246273 $this->setCache($cacheName, $res->data);
247274 return \Result::Success('', $res->data);
248275 }
249276
250- return \Result::Error('顧客様の受け取りに失敗。');
277+ return \Result::Error('ドメインの顧客様の追加データの受け取りに失敗。');
251278 }
252279
280+
253281 //// ドメイン値段
254282
255283 /**
@@ -282,6 +310,47 @@
282310
283311 //// 認証コード
284312
313+ /**
314+ * 認証コードの受け取り
315+ *
316+ * @param int $id ドメイン名ID
317+ * @param array $query 検索クエリー
318+ * @return Result
319+ */
320+ public function getAuthCode(int $id, array $query = []): \Result {
321+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
322+
323+ $uri = "/domains/{$id}/authcode?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
324+ $curl = $this->setupCurl($uri);
325+ $res = $this->curlResult($curl);
326+ if (isset($res->data['data'])) {
327+ return \Result::Success('', $res->data);
328+ }
329+
330+ return \Result::Error('認証コードの受け取りに失敗。');
331+ }
332+
333+ /**
334+ * 認証コードの再設定
335+ *
336+ * @param int $id ドメイン名ID
337+ * @param array $payload フォームデータ
338+ * @return Result
339+ */
340+ public function resetAuthCode(int $id, array $payload = []): \Result {
341+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
342+
343+ $uri = "/domains/{$id}/authcode/reset";
344+ $curl->setupCurl($uri, 'POST', $payload);
345+ $res = $this->curlResult($curl);
346+ kys($res);
347+ if (isset($res)) {
348+ return \Result::Success('', $res->data);
349+ }
350+
351+ return \Result::Error("認証コードの再設定に失敗。");
352+ }
353+
285354 //// TLD
286355
287356 /**
@@ -296,7 +365,7 @@
296365 if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
297366
298367 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0, 'order' => 'ASC' ];
299- foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? '1' : '0';
368+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
300369
301370 $uri = '/tlds?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
302371 $curl = $this->setupCurl($uri);
@@ -318,37 +387,231 @@
318387 */
319388 public function getTld(string $tld, array $query = []): \Result {
320389 if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
321- $cache = $this->getCache("gettld-{$tld}");
390+ $cacheName = "gettld-{$tld}";
391+ $cache = $this->getCache($cacheName);
322392 if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
323393
324394 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
325- foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? '1' : '0';
395+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
326396
327397 $uri = "/tlds/{$tld}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
328398 $curl = $this->setupCurl($uri);
329399 $res = $this->curlResult($curl);
330400 if (isset($res->data['data'])) {
331- $this->setCache("gettld-{$tld}", $res->data);
401+ $this->setCache($cacheName, $res->data);
332402 return \Result::Success('', $res->data);
333403 }
334404
335405 return \Result::Error('TLD一覧の受け取りに失敗。');
336406 }
337407
408+ // 請求
409+ //// 請求書
410+
338411 /**
339- * TLDの受け取り
412+ * 請求書一覧
413+ * @todo テスト
414+ *
415+ * @param array $query 検索クエリー
416+ * @return Result
340417 */
418+ public function listInvoices(array $query = []): \Result {
419+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
420+ $cacheName = 'listinvoices';
421+ $cache = $this->getCache($cacheName);
422+ if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
341423
342- // 請求
343- //// 請求書
424+ if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
425+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
426+
427+ $uri = "/invoices?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
428+ $curl = $this->setupCurl($uri);
429+ $res = $this->curlResult($curl);
430+ if (isset($res->data['data'])) {
431+ $this->setCache($cacheName, $res->data);
432+ return \Result::Success('', $res->data);
433+ }
434+
435+ return \Result::Error('請求書一覧の受け取りに請求書');
436+ }
437+
344438 //// 支払
439+
440+ /**
441+ * 支払一覧
442+ * @todo テスト
443+ *
444+ * @param array $query 検索クエリー
445+ * @return Result
446+ */
447+ public function listPayments(array $query = []): \Result {
448+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
449+ $cacheName = 'listpayments';
450+ $cache = $this->getCache($cacheName);
451+ if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
452+
453+ if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
454+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
455+
456+ $uri = "/payments?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
457+ $curl = $this->setupCurl($uri);
458+ $res = $this->curlResult($curl);
459+ if (isset($res->data['data'])) {
460+ $this->setCache($cacheName, $res->data);
461+ return \Result::Success('', $res->data);
462+ }
463+
464+ return \Result::Error('支払一覧の受け取りに失敗。');
465+ }
466+
345467 //// トランザクション
346468
469+ /**
470+ * トランザクション一覧
471+ * @todo テスト
472+ *
473+ * @param array $query 検索クエリー
474+ * @return Result
475+ */
476+ public function listTransactions(array $query = []): \Result {
477+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
478+ $cacheName = 'listtransactions';
479+ $cache = $this->getCache($cacheName);
480+ if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
481+
482+ if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
483+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
484+
485+ $uri = "/transactions?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
486+ $curl = $this->setupCurl($uri);
487+ $res = $this->curlResult($curl);
488+ if (isset($res->data['data'])) {
489+ $this->setCache($cacheName, $res->data);
490+ return \Result::Success('', $res->data);
491+ }
492+
493+ return \Result::Error('トランザクション一覧の受け取りに失敗。');
494+ }
495+
347496 // DNS
348497 //// DomainToken
498+
499+ /**
500+ * ドメイントークンの作成
501+ * @todo テスト
502+ *
503+ * @param array $payload フォームデータ
504+ * @return Result
505+ */
506+ public function createDomainToken(array $payload = []): \Result {
507+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
508+
509+ $uri = '/dns/domain-token';
510+ $curl = $this->setupCurl($uri, 'POST', $payload);
511+ $res = $this->curlResult($curl);
512+ if (isset($res->data['data'])) {
513+ return \Result::Success('DNSテンプレートの追加に成功。', $res->data);
514+ }
515+
516+ return \Result::Error('DNSテンプレートの追加に失敗。');
517+ }
518+
349519 //// ネームサーバー
350520 //// NSグループ
351521 //// テンプレート
522+
523+ /**
524+ * DNSテンプレート一覧
525+ * @todo テスト
526+ *
527+ * @param array $query 検索クエリー
528+ * @return Result
529+ */
530+ public function listDnsTemplate(array $query = []): \Result {
531+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
532+ $cacheName = 'listdnstemplates';
533+ $cache = $this->getCache($cacheName);
534+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
535+
536+ foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
537+ $uri = '/dns/templates?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
538+ $curl = $this->setupCurl($uri);
539+ $res = $this->curlResult($curl);
540+ if (isset($res->data['data'])) {
541+ $res->data['query'] = $query;
542+ $this->setCache($cacheName, $res->data);
543+ return \Result::Success('', $res->data);
544+ }
545+
546+ return \Result::Error('DNSテンプレート一覧の受け取りに失敗。');
547+ }
548+
549+ /**
550+ * DNSテンプレートの作成
551+ * @todo テスト
552+ *
553+ * @param array $payload フォームデータ
554+ * @return Result
555+ */
556+ public function createDnsTemplate(array $payload = []): \Result {
557+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
558+
559+ $uri = '/dns/templates';
560+ $curl = $this->setupCurl($uri, 'POST', $payload);
561+ $res = $this->curlResult($curl);
562+ if (isset($res->data['data'])) {
563+ $this->murderCache('listdnstemplates');
564+ return \Result::Success('DNSテンプレートの追加に成功。', $res->data);
565+ }
566+
567+ return \Result::Error('DNSテンプレートの追加に失敗。');
568+ }
569+
570+ /**
571+ * DNSテンプレートの表示
572+ * @todo テスト
573+ *
574+ * @param int $id DNSテンプレートID
575+ * @return Result
576+ */
577+ public function getDnsTemplate(int $id): \Result {
578+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
579+ $cacheName = "getdnstemplate-{$id}";
580+ $cache = $this->getCache($cacheName);
581+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
582+
583+ $uri = "/dns/templates/{$id}";
584+ $curl = $this->setupCurl($uri);
585+ $res = $this->curlResult($curl);
586+ if (isset($res->data['data'])) {
587+ $this->setCache($cacheName, $res->data);
588+ return \Result::Success('', $res->data);
589+ }
590+
591+ return \Result::Error('DNSテンプレートの更新に失敗。');
592+ }
593+
594+ /**
595+ * DNSテンプレートの削除
596+ * @todo テスト
597+ *
598+ * @param int $id DNSテンプレートID
599+ * @return Result
600+ */
601+ public function deleteDnsTemplate(int $id): \Result {
602+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
603+
604+ $uri = "/dns/templates/{$id}";
605+ $curl = $this->setupCurl($uri, 'DELETE');
606+ $res = $this->curlResult($curl);
607+ if (isset($res->data['data'])) {
608+ $this->murderCache('listdnstemplates');
609+ if ($res->data['data']['success']) return \Result::Success('DNSテンプレートの削除に成功。', $res->data);
610+ }
611+
612+ return \Result::Error('DNSテンプレートの削除に失敗。');
613+ }
614+
352615 //// ゾーン
353616
354617 /**
@@ -363,7 +626,7 @@
363626 if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
364627
365628 if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
366- foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? '1' : '0';
629+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
367630
368631 $uri = "/dns/zones?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
369632 $curl = $this->setupCurl($uri);
@@ -389,7 +652,7 @@
389652 if ($this->isValidLifespan($cache)) return \Result::Success('', $cache);
390653
391654 if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
392- foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? '1' : '0';
655+ foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
393656
394657 $uri = "/dns/zones/{$domain}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
395658 $curl = $this->setupCurl($uri);
@@ -427,9 +690,468 @@
427690
428691 // Easydmarc
429692
693+ // メールテンプレート
694+
695+ //// メール
696+
697+ /**
698+ * メールテンプレート一覧
699+ * @todo テスト
700+ *
701+ * @param array $query 検索クエリー
702+ * @return Result
703+ */
704+ public function listEmails(array $query = []): \Result {
705+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
706+ $cacheName = 'listemails';
707+ $cache = $this->getCache($cacheName);
708+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
709+
710+ foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
711+ $uri = '/emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
712+ $curl = $this->setupCurl($uri);
713+ $res = $this->curlResult($curl);
714+ if (isset($res->data['data'])) {
715+ $res->data['query'] = $query;
716+ $this->setCache($cacheName, $res->data);
717+ return \Result::Success('', $res->data);
718+ }
719+
720+ return \Result::Error('メールテンプレート一覧の受け取りに失敗。');
721+ }
722+
723+ /**
724+ * メールテンプレートの作成
725+ * @todo テスト
726+ *
727+ * @param array $payload フォームデータ
728+ * @return Result
729+ */
730+ public function createEmail(array $payload = []): \Result {
731+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
732+
733+ $uri = '/emails';
734+ $curl = $this->setupCurl($uri, 'POST', $payload);
735+ $res = $this->curlResult($curl);
736+ if (isset($res->data['data'])) {
737+ $this->murderCache('listemails');
738+ return \Result::Success('メールテンプレートの追加に成功。', $res->data);
739+ }
740+
741+ return \Result::Error('メールテンプレートの追加に失敗。');
742+ }
743+
744+ /**
745+ * メールテンプレートの更新
746+ * @todo テスト
747+ *
748+ * @param int $id メールテンプレートID
749+ * @param array $payload フォームデータ
750+ * @return Result
751+ */
752+ public function updateEmail(int $id, array $payload = []): \Result {
753+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
754+
755+ $uri = "/emails/{$id}";
756+ $curl = $this->setupCurl($uri, 'PUT', $payload);
757+ $res = $this->curlResult($curl);
758+ if (isset($res->data['data'])) {
759+ $this->murderCache('listemails');
760+ if ($res->data['data']['success']) return \Result::Success('メールテンプレートの更新に成功。', $res->data);
761+ }
762+
763+ return \Result::Error('メールテンプレートの更新に失敗。');
764+ }
765+
766+ /**
767+ * メールテンプレートの削除
768+ * @todo テスト
769+ *
770+ * @param int $id メールテンプレートID
771+ * @return Result
772+ */
773+ public function deleteEmail(int $id): \Result {
774+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
775+
776+ $uri = "/emails/{$id}";
777+ $curl = $this->setupCurl($uri, 'DELETE');
778+ $res = $this->curlResult($curl);
779+ if (isset($res->data['data'])) {
780+ $this->murderCache('listemails');
781+ if ($res->data['data']['success']) return \Result::Success('メールテンプレートの削除に成功。', $res->data);
782+ }
783+
784+ return \Result::Error('メールテンプレートの削除に失敗。');
785+ }
786+
430787 // ライセンス
431788
432789 // リセラー・顧客様
790+
791+ //// 連絡先
792+
793+ //// 顧客様
794+
795+ /**
796+ * 顧客様の一覧
797+ *
798+ * @param array $query 検索クエリー
799+ * @return Result
800+ */
801+ public function listCustomers(array $query = []): \Result {
802+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
803+ $cacheName = 'listcustomers';
804+ $cache = $this->getCache($cacheName);
805+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
806+
807+ foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
808+ $uri = '/customers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
809+ $curl = $this->setupCurl($uri);
810+ $res = $this->curlResult($curl);
811+ if (isset($res->data['data'])) {
812+ $res->data['query'] = $query;
813+ $this->setCache($cacheName, $res->data);
814+ return \Result::Success('', $res->data);
815+ }
816+
817+ return \Result::Error('顧客様一覧の受け取りに失敗。');
818+ }
819+
820+ /**
821+ * 顧客様の作成
822+ *
823+ * @param array $payload
824+ * @return Result
825+ */
826+ public function createCustomer(array $payload): \Result {
827+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
828+
829+ $uri = '/customers';
830+ $curl->setupCurl($uri, 'POST', $payload);
831+ $res = $this->curlResult($curl);
832+ kys($res);
833+ if (isset($res)) {
834+ $this->murderCache('listcustomers');
835+ return \Result::Success('', $res->data);
836+ }
837+
838+ return \Result::Error("顧客様の作成に失敗。");
839+ }
840+
841+ /**
842+ * 顧客様の表示
843+ *
844+ * @param string $handle ハンドル
845+ * @param bool $withAdditionalData 詳細データ含むか?
846+ * @return Result
847+ */
848+ public function getCustomer(string $handle, bool $withAdditionalData = false): \Result {
849+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
850+ $cacheName = "getcustomer-{$handle}";
851+ $cache = $this->getCache($cacheName);
852+ if ($this->isValidLifespan($cache, $handle, 'handle')) return \Result::Success('', $cache);
853+
854+ $query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
855+ $uri = "/customers/{$handle}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
856+ // kys($uri);
857+ $curl = $this->setupCurl($uri);
858+ $res = $this->curlResult($curl);
859+ if (isset($res->data['data'])) {
860+ $res->data['handle'] = $handle;
861+ $this->setCache($cacheName, $res->data);
862+ return \Result::Success('', $res->data);
863+ }
864+
865+ return \Result::Error('顧客様の受け取りに失敗。');
866+ }
867+
868+ /**
869+ * 顧客様の更新
870+ * @todo テスト
871+ *
872+ * @param string $handle 顧客様のハンドル
873+ * @param array $payload フォームデータ
874+ * @return Result
875+ */
876+ public function updateCustomer(string $handle, array $payload = []): \Result {
877+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
878+
879+ $uri = "/customers/{$handle}";
880+ $curl = $this->setupCurl($uri, 'PUT', $payload);
881+ $res = $this->curlResult($curl);
882+ if (isset($res->data['data'])) {
883+ $this->murderCache('listcustomers');
884+ if ($res->data['data']['success']) return \Result::Success('顧客様の更新に成功。', $res->data);
885+ }
886+
887+ return \Result::Error('顧客様の更新に失敗。');
888+ }
889+
890+ /**
891+ * 顧客様の削除
892+ * @todo テスト
893+ *
894+ * @param string $handle 顧客様のハンドル
895+ * @return Result
896+ */
897+ public function deleteCustomer(int $id): \Result {
898+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
899+
900+ $uri = "/customers/{$handle}";
901+ $curl = $this->setupCurl($uri, 'DELETE');
902+ $res = $this->curlResult($curl);
903+ if (isset($res->data['data'])) {
904+ $this->murderCache('listcustomers');
905+ if ($res->data['data']['success']) return \Result::Success('顧客様の削除に成功。', $res->data);
906+ }
907+
908+ return \Result::Error('顧客様の削除に失敗。');
909+ }
910+
911+ //// メール認証
912+
913+ /**
914+ * メール認証一覧
915+ * @todo テスト
916+ *
917+ * @param array $query 検索クエリー
918+ * @return Result
919+ */
920+ public function listEmailVerifications(array $query = []): \Result {
921+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
922+ $cacheName = 'listemailverifications';
923+ $cache = $this->getCache($cacheName);
924+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
925+
926+ foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
927+ $uri = '/customers/verifications/emails/domains?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
928+ $curl = $this->setupCurl($uri);
929+ $res = $this->curlResult($curl);
930+ if (isset($res->data['data'])) {
931+ $res->data['query'] = $query;
932+ $this->setCache($cacheName, $res->data);
933+ return \Result::Success('', $res->data);
934+ }
935+
936+ return \Result::Error('メール認証一覧の受け取りに失敗。');
937+ }
938+
939+ /**
940+ * メール認証の再起動
941+ * @todo テスト
942+ *
943+ * @param string $email メールアドレス
944+ * @return Result
945+ */
946+ public function restartEmailVerifications(string $email, string $language = '', string $tag = ''): \Result {
947+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
948+
949+ $uri = '/customers/verifications/emails/restart';
950+ $curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'language' => $language, 'tag' => $tag]);
951+ $res = $this->curlResult($curl);
952+ if (isset($res->data['data'])) {
953+ $this->murderCache('listemailverifications');
954+ return \Result::Success('メール認証の再起動に成功。', $res->data);
955+ }
956+
957+ return \Result::Error('メール認証の再起動に失敗。');
958+ }
959+
960+ /**
961+ * メール認証の起動
962+ * @todo テスト
963+ *
964+ * @param string $email メールアドレス
965+ * @param string $handle 顧客様のハンドル
966+ * @param string $language 言語
967+ * @param string $tag タグ
968+ * @return Result
969+ */
970+ public function startEmailVerifications(string $email, string $handle = '', string $language = '', string $tag = ''): \Result {
971+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
972+
973+ $uri = '/customers/verifications/emails/start';
974+ $curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'handle' => $handle, 'language' => $language, 'tag' => $tag]);
975+ $res = $this->curlResult($curl);
976+ if (isset($res->data['data'])) {
977+ $this->murderCache('listemailverifications');
978+ return \Result::Success('メール認証の起動に成功。', $res->data);
979+ }
980+
981+ return \Result::Error('メール認証の起動に失敗。');
982+ }
983+
984+ //// リセラー
985+
986+ /**
987+ * リセラーの受け取り
988+ * @todo テスト
989+ *
990+ * @param array $query 検索クエリー
991+ * @return Result
992+ */
993+ public function getReseller(array $query = []): \Result {
994+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
995+ $cacheName = 'getreseller';
996+ $cache = $this->getCache($cacheName);
997+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
998+
999+ foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
1000+ $uri = '/resellers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
1001+ $curl = $this->setupCurl($uri);
1002+ $res = $this->curlResult($curl);
1003+ if (isset($res->data['data'])) {
1004+ $res->data['query'] = $query;
1005+ $this->setCache($cacheName, $res->data);
1006+ return \Result::Success('', $res->data);
1007+ }
1008+
1009+ return \Result::Error('リセラーの受け取りに失敗。');
1010+ }
1011+
1012+ /**
1013+ * リセラーの更新
1014+ * @todo テスト
1015+ *
1016+ * @param int $id リセラーID
1017+ * @param array $payload フォームデータ
1018+ * @return Result
1019+ */
1020+ public function updateReseller(int $id, array $payload = []): \Result {
1021+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
1022+
1023+ $uri = "/resellers/{$id}";
1024+ $curl = $this->setupCurl($uri, 'PUT', $payload);
1025+ $res = $this->curlResult($curl);
1026+ if (isset($res->data['data'])) {
1027+ $this->murderCache('getreseller');
1028+ if ($res->data['data']['success']) return \Result::Success('リセラーの更新に成功。', $res->data);
1029+ }
1030+
1031+ return \Result::Error('リセラーの更新に失敗。');
1032+ }
1033+
1034+ //// 設定
1035+
1036+ /**
1037+ * 設定の受け取り
1038+ * @todo テスト
1039+ *
1040+ * @return Result
1041+ */
1042+ public function listSettings(): \Result {
1043+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
1044+ $cacheName = 'listsettings';
1045+ $cache = $this->getCache($cacheName);
1046+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
1047+
1048+ $uri = '/resellers/settings';
1049+ $curl = $this->setupCurl($uri);
1050+ $res = $this->curlResult($curl);
1051+ if (isset($res->data['data'])) {
1052+ $res->data['query'] = $query;
1053+ $this->setCache($cacheName, $res->data);
1054+ return \Result::Success('', $res->data);
1055+ }
1056+
1057+ return \Result::Error('設定の受け取りに失敗。');
1058+ }
1059+
1060+ //// 統計
1061+
1062+ /**
1063+ * 統計の受け取り
1064+ * @todo テスト
1065+ *
1066+ * @return Result
1067+ */
1068+ public function listStatistics(array $query = []): \Result {
1069+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
1070+ $cacheName = 'liststatistics';
1071+ $cache = $this->getCache($cacheName);
1072+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
1073+
1074+ $uri = '/resellers/statistics';
1075+ $curl = $this->setupCurl($uri);
1076+ $res = $this->curlResult($curl);
1077+ if (isset($res->data['data'])) {
1078+ $res->data['query'] = $query;
1079+ $this->setCache($cacheName, $res->data);
1080+ return \Result::Success('', $res->data);
1081+ }
1082+
1083+ return \Result::Error('統計の受け取りに失敗。');
1084+ }
1085+
1086+ //// タグ
1087+
1088+ /**
1089+ * タグ一覧
1090+ * @todo テスト
1091+ *
1092+ * @param array $query 検索クエリー
1093+ * @return Result
1094+ */
1095+ public function listTags(array $query = []): \Result {
1096+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
1097+ $cacheName = 'listtags';
1098+ $cache = $this->getCache($cacheName);
1099+ if ($this->isValidLifespan($cache, $query)) return \Result::Success('', $cache);
1100+
1101+ foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
1102+ $uri = '/tags?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
1103+ $curl = $this->setupCurl($uri);
1104+ $res = $this->curlResult($curl);
1105+ if (isset($res->data['data'])) {
1106+ $res->data['query'] = $query;
1107+ $this->setCache($cacheName, $res->data);
1108+ return \Result::Success('', $res->data);
1109+ }
1110+
1111+ return \Result::Error('タグ一覧の受け取りに失敗。');
1112+ }
1113+
1114+ /**
1115+ * タグの作成
1116+ * @todo テスト
1117+ *
1118+ * @param array $payload フォームデータ
1119+ * @return Result
1120+ */
1121+ public function createTag(array $payload = []): \Result {
1122+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
1123+
1124+ $uri = '/tags';
1125+ $curl = $this->setupCurl($uri, 'POST', $payload);
1126+ $res = $this->curlResult($curl);
1127+ if (isset($res->data['data'])) {
1128+ $this->murderCache('listtags');
1129+ return \Result::Success('タグの追加に成功。', $res->data);
1130+ }
1131+
1132+ return \Result::Error('タグの追加に失敗。');
1133+ }
1134+
1135+ /**
1136+ * タグの削除
1137+ * @todo テスト
1138+ *
1139+ * @param array $payload フォームデータ
1140+ * @return Result
1141+ */
1142+ public function deleteTag(array $payload = []): \Result {
1143+ if (!OPENPROVIDER_ENABLED) return \Result::error('エラー:OpenProviderは無効です。');
1144+
1145+ $uri = "/tags/{$id}";
1146+ $curl = $this->setupCurl($uri, 'DELETE', $payload);
1147+ $res = $this->curlResult($curl);
1148+ if (isset($res->data['data'])) {
1149+ $this->murderCache('listtags');
1150+ if ($res->data['data']['success']) return \Result::Success('タグの削除に成功。', $res->data);
1151+ }
1152+
1153+ return \Result::Error('タグの削除に失敗。');
1154+ }
4331155
4341156 // SpamExpert
4351157
@@ -0,0 +1,109 @@
1+{@ include(common/header) @}
2+ <h2>新規顧客様作成</h2>
3+ <p>
4+ <form method="POST" action="/openprovider/createcustomer">
5+ <h3>会社情報</h3>
6+ <p>個人の場合、入力が不要です。</p>
7+ <table>
8+ <tbody>
9+ <tr>
10+ <td><label for="company_name">会社名</label></td>
11+ <td><input type="text" name="company_name" value="{{ $data['company_name'] }}" /></td>
12+ </tr>
13+ <tr>
14+ <td><label for="company_registration_number">法人番号</label></td>
15+ <td><input type="text" name="company_registration_number" value="{{ $data['company_registration_number'] }}" /></td>
16+ </tr>
17+ <tr>
18+ <td><label for="company_url">ウェブサイト</label></td>
19+ <td><input type="text" name="company_url" value="{{ $data['company_url'] }}" /></td>
20+ </tr>
21+ </tbody>
22+ </table>
23+ <h3>個人情報</h3>
24+ telephone number (req)
25+ fax number
26+ email address (req)
27+ birth date
28+ <table>
29+ <tbody>
30+ <tr>
31+ <td><label for="last_name">姓名(ローマ字)*</label></td>
32+ <td>
33+ <input type="text" name="last_name" placeholder="Taro" value="{{ $data['last_name'] }}" />
34+ <input type="text" name="first_name" placeholder="Yamada" value="{{ $data['first_name'] }}" />
35+ </td>
36+ </tr>
37+ <tr>
38+ <td><label for="phone.country_code">電話番号*</label></td>
39+ <td>
40+ <input type="text" name="phone.country_code" placeholder="+81" value="{{ $data['phone.country_code'] }}" />
41+ <input type="text" name="phone.area_code" placeholder="43" value="{{ $data['phone.area_code'] }}" />
42+ <input type="text" name="phone.subscriber_number" placeholder="0000000" value="{{ $data['phone.subscriber_number'] }}" />
43+ </td>
44+ </tr>
45+ <tr>
46+ <td><label for="fax.country_code">FAX</label></td>
47+ <td>
48+ <input type="text" name="fax.country_code" placeholder="+81" value="{{ $data['fax.country_code'] }}" />
49+ <input type="text" name="fax.area_code" placeholder="43" value="{{ $data['fax.area_code'] }}" />
50+ <input type="text" name="fax.subscriber_number" placeholder="0000000" value="{{ $data['fax.subscriber_number'] }}" />
51+ </td>
52+ </tr>
53+ <tr>
54+ <td><label for="email">メールアドレス*</label></td>
55+ <td><input type="text" name="email" placeholder="taro@076.co.jp" value="{{ $data['email'] }}" /></td>
56+ </tr>
57+ <tr>
58+ <td><label for="year">生年月日</label></td>
59+ <td>
60+ <input type="text" name="year" placeholder="1970" value="{{ $data['year'] }}" />年
61+ <input type="text" name="month" placeholder="12" value="{{ $data['month'] }}" />月
62+ <input type="text" name="day" placeholder="31" value="{{ $data['day'] }}" />日
63+ </td>
64+ </tr>
65+ </tbody>
66+ </table>
67+ <h3>住所情報</h3>
68+ <table>
69+ <tbody>
70+ <tr>
71+ <td><label for="zipcode">郵便番号*(ハイフン付き)</label></td>
72+ <td>〒<input type="text" name="zipcode" value="{{ $data['zipcode'] }}" /></td>
73+ </tr>
74+ <tr>
75+ <td><label for="state">都道府県*</label></td>
76+ <td><input type="text" name="state" value="{{ $data['state'] }}" /></td>
77+ </tr>
78+ <tr>
79+ <td><label for="city">市区町村*</label></td>
80+ <td><input type="text" name="city" value="{{ $data['city'] }}" /></td>
81+ </tr>
82+ <tr>
83+ <td><label for="street">町名*</label></td>
84+ <td><input type="text" name="street" value="{{ $data['street'] }}" /></td>
85+ </tr>
86+ <tr>
87+ <td><label for="number">番地*</label></td>
88+ <td><input type="text" name="number" value="{{ $data['number'] }}" /></td>
89+ </tr>
90+ <tr>
91+ <td><label for="country">国</label></td>
92+ <td>
93+ <select name="country">
94+ <option value="JP" selected="selected">日本</option>
95+ <option value="NL">オランダ</option>
96+ </select>
97+ </td>
98+ </tr>
99+ <tr>
100+ <td><label for="comments">メモ</label></td>
101+ <td><input type="text" name="comments" value="{{ $data['comments'] }}" /></td>
102+ </tr>
103+ </tbody>
104+ </table>
105+ <button>送信</button>
106+ </form>
107+ </p>
108+ {@ kys($data) @}
109+{@ include(common/footer) @}
@@ -1,5 +1,5 @@
11 {@ include(common/header) @}
2- 顧客様の追加<br />
2+ <a href="/openprovider/createcustomer">顧客様の追加</a><br />
33 検索<br />
44 {@ if (isset($data['data']['results'])) @}
55 <table>