Files
LittleBeast/src/Std/Lib/Openprovider.php

1975 lines
68 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/*************************************************************
# 076 License
Copyright (c) テクニカル諏訪子
Permission is hereby granted to any person obtaining a copy of the software
Little Beast (the "Software") to use, modify, merge, copy, publish, distribute,
sublicense, and/or sell copies of the Software, subject to the following conditions:
1. **Origin Attribution**:
- You must not misrepresent the origin of the Software; you must not claim
you created the original Software.
- If the Software is used in a product, you must either:
a. Provide clear attribution in the product's documentation, user interface,
or other visible areas, **OR**
b. Pay the original developers a fee they specify in writing.
2. **Usage Restriction**:
- The Software, or any derivative works, dependencies, or libraries
incorporating it, must not be used for censorship or to suppress freedom of
speech, expression, or creativity. Prohibited uses include, but are not
limited to:
- Censorship of so-called "hate speech", visuals, non-mainstream opinions,
ideas, or objective reality.
- Tools or systems designed to restrict access to information or
artistic works.
3. **Notice Preservation**:
- This license and the above copyright notice must remain intact in all copies
of the source code.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Std\Lib;
use Std\Lib\Cache;
use Std\Lib\Curl;
use Result;
class Openprovider {
protected string $cacheDir = ROOT."/data/cache/openprovider/";
protected int $tokenDuration = 172800; // 48時間
private Cache $cache;
private string $user = '';
private string $pass = '';
private string $token = '';
private string $ip = '';
private int $resellerId = 0;
private int $lastAuth = 0;
private string $BASEURL = DEBUG_MODE ? 'http://api.sandbox.openprovider.nl:8480/v1beta'
: 'https://api.openprovider.eu/v1beta';
public function __construct() {
if (!OPENPROVIDER_ENABLED) return;
$this->user = OPENPROVIDER['username'];
$this->pass = OPENPROVIDER['password'];
$this->ip = OPENPROVIDER['ip'];
$this->cache = new Cache($this->cacheDir);
}
/**
* トークンの受け取り。
* このライブリリーを使ったら、一回「login()」を実行する事が必須となります。
*
* @return Result 結果
*/
public function login(): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'login';
$cache = $this->cache->get($cacheName);
if (time() < ($this->lastAuth + $this->tokenDuration)) {
$this->token = $cache['data']['token'];
$this->lastAuth = $cache['last_auth'];
return Result::Success('', $cache);
}
$curl = new Curl("{$this->BASEURL}/auth/login");
$payload = [
'username' => $this->user,
'password' => $this->pass,
'ip' => $this->ip ?: '0.0.0.0',
];
$curl->setMethod("POST");
$curl->setPostRaw(json_encode($payload));
$curl->addHeader("Content-Type", "application/json");
$curl->addHeader("Accept", "application/json");
$res = $curl->execute();
if (!$res->isSuccess) {
$err = "CURLの実行に失敗 ".$curl->message;
assert_unless_success($res, $err);
return Result::Error($err);
}
$body = $curl->getResponseBody();
if ($curl->getResponseCode() != 200) {
$err = json_decode($body, true);
assert_not_null($err, "エラーの受け取りに失敗。");
assert($curl->getResponseCode() == 200, $err['desc']);
return Result::Error();
}
assert_not_null($body, "返事ボディーは空です。");
$res = json_decode($body, true);
if (isset($res['data']['token'])) {
$this->token = $res['data']['token'];
$this->lastAuth = time();
$res['last_auth'] = $this->lastAuth;
$this->cache->set($cacheName, $res);
return Result::Success('', $res);
}
return Result::Error('ログインに失敗。');
}
/**
* SpanExpert向けログインURLの生成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function generateLoginUrlSpamExpert(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/spam-expert-generate-login-url';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
return Result::Success('DNSテンプレートの追加に成功。', $res->data);
}
return Result::Error('DNSテンプレートの追加に失敗。');
}
// ドメイン
//// ドメイン
/**
* ドメイン一覧。
* @todo テスト
*
* @return Result 結果。
*/
public function listDomains(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listdomains';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
$curl = $this->setupCurl('/domains');
$res = $this->curlResult($curl);
if (isset($res['data']['results'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res['data']['results']);
}
return Result::Error('ドメインの確認に失敗。');
}
/**
* ドメイン名の登録。
* @todo テスト
*
* @param string $name 登録したいドメイン名(例:"076studio.jp"
* @param array $info カスタマー情報等
* @param int $period 年間(デフォルト=1年)
* @return Result 結果。配列の場合:'activation_date'(リアルタイムで成功したのみ), 'auth_code'TLDが対応している場合のみ, 'expiration_date', 'id', 'renewal_date', 'status'ACT又はREQ
*/
public function createDomain(string $name, array $info, int $period = 1): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
if (!isset($info['owner_handle']) || $info['owner_handle'] === '') $info['owner_handle'] = OPENPROVIDER['owner_handle'];
if (!isset($info['admin_handle']) || $info['admin_handle'] === '') $info['admin_handle'] = OPENPROVIDER['owner_handle'];
if (!isset($info['tech_handle']) || $info['tech_handle'] === '') $info['tech_handle'] = OPENPROVIDER['owner_handle'];
if (!isset($info['billing_handle']) || $info['billing_handle'] === '') $info['billing_handle'] = OPENPROVIDER['owner_handle'];
if (!isset($info['reseller_handle']) || $info['reseller_handle'] === '') $info['reseller_handle'] = OPENPROVIDER['owner_handle'];
if (!isset($info['name_servers']) || empty($info['name_servers'])) $info['name_servers'] = ['ns1.openprovider.nl', 'ns2.openprovider.be', 'ns3.openprovider.eu'];
if (!isset($info['autorenew']) || $info['autorenew'] === '') $info['autorenew'] = 'default';
// 新しい顧客の場合
$parts = explode('.', $name, 2);
assert_exists($parts[0]);
assert_exists($parts[1]);
$domain = [
'name' => $parts[0],
'extension' => $parts[1],
];
$ns = [];
foreach ($info['name_servers'] as $n) {
$ns[] = ['name' => $n];
}
$payload = [
'name' => $domain,
'period' => $period,
'owner_handle' => $owner_handle,
'admin_handle' => $admin_handle,
'tech_handle' => $tech_handle,
'billing_handle' => $billing_handle,
'reseller_handle' => $reseller_handle,
'name_servers' => $ns,
'autorenew' => $autorenew,
];
$curl = $this->setupCurl('/domains/', 'POST', $payload);
kys('TODO');
$res = $this->curlResult($curl);
if (isset($res['data'])) return Result::Success('', $res);
return Result::Error('ドメインの確認に失敗。');
}
/**
* ドメインを登録可能かどうかの確認。
*
* @param array $domains ドメイン名リスト。例:['076.moe', '076.co.jp', '076.com']
* @param bool $with_price 値段を表示するかどうか。デフォルトは「false」
* @return Result 結果。配列の場合:'domain'と'status'はいつでもあり、'reason', 'premium', 'is_premium'が多分あり、そして'price'が「with_price」が「true」の場合のみ。
*/
public function checkDomainAvailable(array $domains, bool $with_price = false): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$domainList = [];
foreach ($domains as $d) {
$domain = explode('.', $d);
assert_exists($domain[0]);
assert_exists($domain[1]);
if (count($domain) !== 2) {
return Result::Error("不正なドメイン形: {$d}");
}
$domainList[] = [
'name' => $domain[0],
'extension' => $domain[1],
];
}
$payload = [
'domains' => $domainList,
'with_price' => $with_price,
];
$curl = $this->setupCurl('/domains/check', 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data']['results'])) return Result::Success('', $res->data['data']['results']);
return Result::Error('ドメインの確認に失敗。');
}
//// 追加データ
/**
* 追加データの受け取り
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function getDomainAdditionalData(array $query): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$name = '';
$ext = '';
if (isset($query['domain.name'])) $name = $query['domain.name'];
if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
$cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
$uri = "/domains/additional-data?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('ドメインの追加データの受け取りに失敗。');
}
//// 顧客様の追加データ
/**
* 顧客様の追加データの受け取り
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function getDomainCustomerAdditionalData(array $query): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$name = '';
$ext = '';
if (isset($query['domain.name'])) $name = $query['domain.name'];
if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
$cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
$uri = "/domains/additional-data/customers?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('ドメインの顧客様の追加データの受け取りに失敗。');
}
//// ドメイン値段
/**
* ドメイン値段一覧
*
* @param array $query 検索クエリー
* @return Result
*/
public function getDomainPrices(array $query): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$name = '';
$ext = '';
if (isset($query['domain.name'])) $name = $query['domain.name'];
if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
$cacheName = $name && $ext ? "domainprices-{$name}.{$ext}" : 'domainprices';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
$uri = "/domains/prices?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('TLD一覧の受け取りに失敗。');
}
//// 認証コード
/**
* 認証コードの受け取り
* @todo テスト
*
* @param int $id ドメイン名ID
* @param array $query 検索クエリー
* @return Result
*/
public function getAuthCode(int $id, array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/domains/{$id}/authcode?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
return Result::Success('', $res->data);
}
return Result::Error('認証コードの受け取りに失敗。');
}
/**
* 認証コードの再設定
* @todo テスト
*
* @param int $id ドメイン名ID
* @param array $payload フォームデータ
* @return Result
*/
public function resetAuthCode(int $id, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/domains/{$id}/authcode/reset";
$curl->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
kys($res);
if (isset($res)) {
return Result::Success('', $res->data);
}
return Result::Error("認証コードの再設定に失敗。");
}
//// TLD
/**
* TLD一覧
*
* @param array $query 検索クエリー
* @return Result
*/
public function listTlds(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listtlds';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0, 'order' => 'ASC' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = '/tlds?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('TLD一覧の受け取りに失敗。');
}
/**
* TLDの表示
*
* @param string $tld TLD
* @param array $query 検索クエリー
* @return Result
*/
public function getTld(string $tld, array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "gettld-{$tld}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/tlds/{$tld}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('TLD一覧の受け取りに失敗。');
}
// 請求
//// 請求書
/**
* 請求書一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listInvoices(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listinvoices';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/invoices?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('請求書一覧の受け取りに請求書');
}
//// 支払
/**
* 支払一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listPayments(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listpayments';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/payments?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('支払一覧の受け取りに失敗。');
}
//// トランザクション
/**
* トランザクション一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listTransactions(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listtransactions';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/transactions?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('トランザクション一覧の受け取りに失敗。');
}
// DNS
//// DomainToken
/**
* ドメイントークンの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createDomainToken(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/dns/domain-token';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
return Result::Success('DNSテンプレートの追加に成功。', $res->data);
}
return Result::Error('DNSテンプレートの追加に失敗。');
}
//// ネームサーバー
/**
* ネームサーバー一覧
* @todo テスト
*
* @param array $query
* @return Result
*/
public function listNameservers(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listnameservers';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/dns/nameservers?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('ネームサーバー一覧の受け取りに失敗。');
}
/**
* ネームサーバーの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createNameserver(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/dns/nameservers';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listnameservers');
return Result::Success('ネームサーバーの追加に成功。', $res->data);
}
return Result::Error('ネームサーバーの追加に失敗。');
}
/**
* ネームサーバー一覧
* @todo テスト
*
* @param string $domain ドメイン名
* @param array $query 検索クエリー
* @return Result
*/
public function getNameserver(string $domain, array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "listnameserver-{$domain}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/dns/nameservers/{$domain}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('ネームサーバー一覧の受け取りに失敗。');
}
/**
* ネームサーバーの更新
* @todo テスト
*
* @param string $domain ドメイン名
* @param array $payload フォームデータ
* @return Result
*/
public function updateNameserver(string $domain, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/nameservers/{$domain}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listnameservers');
$this->cache->murder("listnameserver-{$domain}");
if ($res->data['data']['success']) return Result::Success('ネームサーバーの更新に成功。', $res->data);
}
return Result::Error('ネームサーバーの更新に失敗。');
}
/**
* ネームサーバーの削除
* @todo テスト
*
* @param string $domain ドメイン名
* @return Result
*/
public function deleteNameserver(string $domain): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/nameservers/{$domain}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listnameservers');
$this->cache->murder("listnameserver-{$domain}");
if ($res->data['data']['success']) return Result::Success('ネームサーバーの削除に成功。', $res->data);
}
return Result::Error('ネームサーバーの削除に失敗。');
}
//// NSグループ
/**
* NSグループ一覧
* @todo テスト
*
* @param array $query
* @return Result
*/
public function listNsGroups(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listnsgroups';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/dns/nameservers/groups?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('NSグループ一覧の受け取りに失敗。');
}
/**
* NSグループの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createNsGroup(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/dns/nameservers/groups';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listnsgroups');
return Result::Success('NSグループの追加に成功。', $res->data);
}
return Result::Error('NSグループの追加に失敗。');
}
/**
* NSグループ一覧
* @todo テスト
*
* @param string $nsGroup ネームサーバー名
* @param array $query 検索クエリー
* @return Result
*/
public function getNsGroup(string $nsGroup, array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "listnsgroup-{$nsGroup}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/dns/nameservers/groups/{$nsGroup}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('NSグループ一覧の受け取りに失敗。');
}
/**
* NSグループの更新
* @todo テスト
*
* @param string $nsGroup ネームサーバー名
* @param array $payload フォームデータ
* @return Result
*/
public function updateNsGroup(string $nsGroup, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/nameservers/groups/{$nsGroup}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listnsgroups');
$this->cache->murder("listnsgroup-{$nsGroup}");
if ($res->data['data']['success']) return Result::Success('NSグループの更新に成功。', $res->data);
}
return Result::Error('NSグループの更新に失敗。');
}
/**
* NSグループの削除
* @todo テスト
*
* @param string $nsGroup ネームサーバー名
* @return Result
*/
public function deleteNsGroup(string $nsGroup): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/nameservers/groups/{$nsGroup}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listnsgroups');
$this->cache->murder("listnsgroup-{$nsGroup}");
if ($res->data['data']['success']) return Result::Success('NSグループの削除に成功。', $res->data);
}
return Result::Error('NSグループの削除に失敗。');
}
//// テンプレート
/**
* DNSテンプレート一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listDnsTemplate(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listdnstemplates';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/dns/templates?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('DNSテンプレート一覧の受け取りに失敗。');
}
/**
* DNSテンプレートの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createDnsTemplate(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/dns/templates';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdnstemplates');
return Result::Success('DNSテンプレートの追加に成功。', $res->data);
}
return Result::Error('DNSテンプレートの追加に失敗。');
}
/**
* DNSテンプレートの表示
* @todo テスト
*
* @param int $id DNSテンプレートID
* @return Result
*/
public function getDnsTemplate(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getdnstemplate-{$id}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
$uri = "/dns/templates/{$id}";
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('DNSテンプレートの更新に失敗。');
}
/**
* DNSテンプレートの削除
* @todo テスト
*
* @param int $id DNSテンプレートID
* @return Result
*/
public function deleteDnsTemplate(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/templates/{$id}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdnstemplates');
$this->cache->murder("getdnstemplate-{$id}");
if ($res->data['data']['success']) return Result::Success('DNSテンプレートの削除に成功。', $res->data);
}
return Result::Error('DNSテンプレートの削除に失敗。');
}
//// DNSゾーン
/**
* DNSゾーン一覧
*
* @param array $query
* @return Result
*/
public function listDnsZones(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listdnszones';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/dns/zones?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('DNSゾーン一覧の受け取りに失敗。');
}
/**
* DNSゾーンの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createDnsZone(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/dns/zones';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdnszones');
return Result::Success('DNSゾーンの追加に成功。', $res->data);
}
return Result::Error('DNSゾーンの追加に失敗。');
}
/**
* DNSゾーン一覧
*
* @param string $domain ドメイン名
* @param array $query 検索クエリー
* @return Result
*/
public function getDnsZone(string $domain, array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getdnszone-{$domain}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
$uri = "/dns/zones/{$domain}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('DNSゾーン一覧の受け取りに失敗。');
}
/**
* DNSゾーンの更新
* @todo テスト
*
* @param string $domain ドメイン名
* @param array $payload フォームデータ
* @return Result
*/
public function updateDnsZone(string $domain, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/zones/{$domain}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdnszones');
$this->cache->murder("getdnszone-{$domain}");
if ($res->data['data']['success']) return Result::Success('DNSゾーンの更新に成功。', $res->data);
}
return Result::Error('DNSゾーンの更新に失敗。');
}
/**
* DNSゾーンの削除
* @todo テスト
*
* @param string $domain ドメイン名
* @return Result
*/
public function deleteDnsZone(string $domain): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/dns/zones/{$domain}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdnszones');
$this->cache->murder("getdnszone-{$domain}");
if ($res->data['data']['success']) return Result::Success('DNSゾーンの削除に成功。', $res->data);
}
return Result::Error('DNSゾーンの削除に失敗。');
}
//// ゾーンレコード
/**
* DNSレコード一覧
*
* @param string $domain
* @return Result
*/
public function listZoneRecords(string $domain): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getzonerecords-{$domain}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache)) return Result::Success('', $cache);
$curl = $this->setupCurl("/dns/zones/{$domain}/records");
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('TLD一覧の受け取りに失敗。');
}
// Easydmarc
// メールテンプレート
//// メール
/**
* メールテンプレート一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listEmails(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listemails';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('メールテンプレート一覧の受け取りに失敗。');
}
/**
* メールテンプレートの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createEmail(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/emails';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listemails');
return Result::Success('メールテンプレートの追加に成功。', $res->data);
}
return Result::Error('メールテンプレートの追加に失敗。');
}
/**
* メールテンプレートの更新
* @todo テスト
*
* @param int $id メールテンプレートID
* @param array $payload フォームデータ
* @return Result
*/
public function updateEmail(int $id, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/emails/{$id}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listemails');
if ($res->data['data']['success']) return Result::Success('メールテンプレートの更新に成功。', $res->data);
}
return Result::Error('メールテンプレートの更新に失敗。');
}
/**
* メールテンプレートの削除
* @todo テスト
*
* @param int $id メールテンプレートID
* @return Result
*/
public function deleteEmail(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/emails/{$id}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listemails');
if ($res->data['data']['success']) return Result::Success('メールテンプレートの削除に成功。', $res->data);
}
return Result::Error('メールテンプレートの削除に失敗。');
}
// ライセンス
// リセラー・顧客様
//// 連絡先
/**
* 連絡先の一覧
*
* @param array $query 検索クエリー
* @return Result
*/
public function listContacts(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listcontacts';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/contacts?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('連絡先一覧の受け取りに失敗。');
}
/**
* 連絡先の作成
*
* @param array $payload
* @return Result
*/
public function createContact(array $payload): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/contacts';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res)) {
$this->cache->murder('listcontacts');
return Result::Success('', $res->data);
}
return Result::Error("連絡先の作成に失敗。");
}
/**
* 連絡先の表示
*
* @param int $id 連絡先ID
* @param bool $withAdditionalData 詳細データ含むか?
* @return Result
*/
public function getContact(int $id, bool $withAdditionalData = false): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getcontact-{$id}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $id, 'id')) return Result::Success('', $cache);
$query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
$uri = "/contacts/{$id}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
// kys($uri);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['id'] = $id;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('連絡先の受け取りに失敗。');
}
/**
* 連絡先の更新
* @todo テスト
*
* @param int $id 連絡先ID
* @param array $payload フォームデータ
* @return Result
*/
public function updateContact(int $id, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/contacts/{$id}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder("getcontact-{$id}");
$this->cache->murder('listcontacts');
if ($res->data['data']['success']) return Result::Success('連絡先の更新に成功。', $res->data);
}
return Result::Error('連絡先の更新に失敗。');
}
/**
* 連絡先の削除
*
* @param int $id 連絡先ID
* @return Result
*/
public function deleteContact(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/contacts/{$id}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder("getcontact-{$id}");
$this->cache->murder('listcontacts');
if ($res->data['data']['success']) return Result::Success('連絡先の削除に成功。');
}
return Result::Error('連絡先の削除に失敗。');
}
//// 顧客様
/**
* 顧客様の一覧
*
* @param array $query 検索クエリー
* @return Result
*/
public function listCustomers(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listcustomers';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/customers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('顧客様一覧の受け取りに失敗。');
}
/**
* 顧客様の作成
*
* @param array $payload
* @return Result
*/
public function createCustomer(array $payload): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/customers';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res)) {
$this->cache->murder('listcustomers');
return Result::Success('', $res->data);
}
return Result::Error("顧客様の作成に失敗。");
}
/**
* 顧客様の表示
*
* @param string $handle ハンドル
* @param bool $withAdditionalData 詳細データ含むか?
* @return Result
*/
public function getCustomer(string $handle, bool $withAdditionalData = false): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getcustomer-{$handle}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $handle, 'handle')) return Result::Success('', $cache);
$query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
$uri = "/customers/{$handle}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
// kys($uri);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['handle'] = $handle;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('顧客様の受け取りに失敗。');
}
/**
* 顧客様の更新
* @todo テスト
*
* @param string $handle 顧客様のハンドル
* @param array $payload フォームデータ
* @return Result
*/
public function updateCustomer(string $handle, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/customers/{$handle}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listcustomers');
$this->cache->murder("getcustomer-{$handle}");
if ($res->data['data']['success']) return Result::Success('顧客様の更新に成功。', $res->data);
}
return Result::Error('顧客様の更新に失敗。');
}
/**
* 顧客様の削除
*
* @param string $handle 顧客様のハンドル
* @return Result
*/
public function deleteCustomer(string $handle): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/customers/{$handle}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listcustomers');
$this->cache->murder("getcustomer-{$handle}");
if ($res->data['data']['success']) return Result::Success('顧客様の削除に成功。');
}
return Result::Error('顧客様の削除に失敗。');
}
//// メール認証
/**
* メール認証一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listEmailVerifications(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listemailverifications';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/customers/verifications/emails/domains?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('メール認証一覧の受け取りに失敗。');
}
/**
* メール認証の再起動
* @todo テスト
*
* @param string $email メールアドレス
* @return Result
*/
public function restartEmailVerifications(string $email, string $language = '', string $tag = ''): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/customers/verifications/emails/restart';
$curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'language' => $language, 'tag' => $tag]);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listemailverifications');
return Result::Success('メール認証の再起動に成功。', $res->data);
}
return Result::Error('メール認証の再起動に失敗。');
}
/**
* メール認証の起動
* @todo テスト
*
* @param string $email メールアドレス
* @param string $handle 顧客様のハンドル
* @param string $language 言語
* @param string $tag タグ
* @return Result
*/
public function startEmailVerifications(string $email, string $handle = '', string $language = '', string $tag = ''): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/customers/verifications/emails/start';
$curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'handle' => $handle, 'language' => $language, 'tag' => $tag]);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listemailverifications');
return Result::Success('メール認証の起動に成功。', $res->data);
}
return Result::Error('メール認証の起動に失敗。');
}
//// リセラー
/**
* リセラーの受け取り
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function getReseller(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'getreseller';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/resellers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('リセラーの受け取りに失敗。');
}
/**
* リセラーの更新
* @todo テスト
*
* @param int $id リセラーID
* @param array $payload フォームデータ
* @return Result
*/
public function updateReseller(int $id, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/resellers/{$id}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('getreseller');
if ($res->data['data']['success']) return Result::Success('リセラーの更新に成功。', $res->data);
}
return Result::Error('リセラーの更新に失敗。');
}
//// 設定
/**
* 設定の受け取り
* @todo テスト
*
* @return Result
*/
public function listSettings(): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listsettings';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
$uri = '/resellers/settings';
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('設定の受け取りに失敗。');
}
//// 統計
/**
* 統計の受け取り
* @todo テスト
*
* @return Result
*/
public function listStatistics(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'liststatistics';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
$uri = '/resellers/statistics';
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('統計の受け取りに失敗。');
}
//// タグ
/**
* タグ一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listTags(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listtags';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/tags?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('タグ一覧の受け取りに失敗。');
}
/**
* タグの作成
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function createTag(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/tags';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listtags');
return Result::Success('タグの追加に成功。', $res->data);
}
return Result::Error('タグの追加に失敗。');
}
/**
* タグの削除
* @todo テスト
*
* @param array $payload フォームデータ
* @return Result
*/
public function deleteTag(array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/tags/{$id}";
$curl = $this->setupCurl($uri, 'DELETE', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listtags');
if ($res->data['data']['success']) return Result::Success('タグの削除に成功。', $res->data);
}
return Result::Error('タグの削除に失敗。');
}
// SpamExpert
//// SEDomain
/**
* SEDomainの作成
* @todo テスト
*
* @param array $payload
* @return Result
*/
public function createSeDomain(array $payload): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/spam-expert/domains';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res)) {
$this->cache->murder('listdomains');
return Result::Success('', $res->data);
}
return Result::Error("SEDomainの作成に失敗。");
}
/**
* SEDomainの表示
* @todo テスト
*
* @param string $domain ドメイン名
* @param array $query 検索クエリー
* @return Result
*/
public function getSeDomain(string $domain, array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getsedomain-{$domain}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $domain, 'domain')) return Result::Success('', $cache);
$uri = "/spam-expert/domains/{$domain}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
// kys($uri);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['domain'] = $domain;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('SEDomainの受け取りに失敗。');
}
/**
* SEDomainの更新
* @todo テスト
*
* @param string $domain ドメイン名
* @param array $payload フォームデータ
* @return Result
*/
public function updateSeDomain(string $domain, array $payload = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/spam-expert/domains/{$domain}";
$curl = $this->setupCurl($uri, 'PUT', $payload);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdomains');
$this->cache->murder("getsedomain-{$domain}");
if ($res->data['data']['success']) return Result::Success('SEDomainの更新に成功。', $res->data);
}
return Result::Error('SEDomainの更新に失敗。');
}
/**
* SEDomainの削除
* @todo テスト
*
* @param string $domain ドメイン名
* @return Result
*/
public function deleteSeDomain(string $domain): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/spam-expert/domains/{$domain}";
$curl = $this->setupCurl($uri, 'DELETE');
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$this->cache->murder('listdomains');
$this->cache->murder("getsedomain-{$domain}");
if ($res->data['data']['success']) return Result::Success('SEDomainの削除に成功。');
}
return Result::Error('SEDomainの削除に失敗。');
}
// SSL証明書
//// 確認担当者メール
/**
* 確認担当者メール一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listApproverEmails(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listapproveremails';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/ssl/approver-emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('確認担当者メール一覧の受け取りに失敗。');
}
//// CSR
/**
* 注文確認担当者メールの再送信
* @todo テスト
*
* @param array $payload
* @return Result
*/
public function createCsr(array $payload): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/ssl/csr';
$curl = $this->setupCurl($uri, 'POST', $payload);
$res = $this->curlResult($curl);
if (isset($res)) {
return Result::Success('', $res->data);
}
return Result::Error("注文確認担当者メールの再送信に失敗。");
}
/**
* 注文確認担当者メールの再送信
* @todo テスト
*
* @param string $csr
* @return Result
*/
public function decodeCsr(string $csr): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = '/ssl/csr/decode';
$curl = $this->setupCurl($uri, 'POST', ['csr' => $csr]);
$res = $this->curlResult($curl);
if (isset($res)) {
return Result::Success('', $res->data);
}
return Result::Error("注文確認担当者メールの再送信に失敗。");
}
//// 注文
//// 注文確認担当者メール
/**
* 注文確認担当者メールの更新
* @todo テスト
*
* @param int $id
* @param string $approverEmail
* @return Result
*/
public function updateSslApproverEmail(int $id, string $approverEmail): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/ssl/orders/{$id}/approver-email";
$curl = $this->setupCurl($uri, 'PUT', ['id' => $id, 'approver_email' => $approverEmail]);
$res = $this->curlResult($curl);
if (isset($res)) {
$this->cache->murder('listapproveremails');
return Result::Success('', $res->data);
}
return Result::Error("注文確認担当者メールの更新に失敗。");
}
/**
* 注文確認担当者メールの再送信
* @todo テスト
*
* @param int $id
* @return Result
*/
public function resendSslApproverEmail(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/ssl/orders/{$id}/approver-email/resend";
$curl = $this->setupCurl($uri, 'POST', ['id' => $id]);
$res = $this->curlResult($curl);
if (isset($res)) {
$this->cache->murder('listapproveremails');
return Result::Success('', $res->data);
}
return Result::Error("注文確認担当者メールの再送信に失敗。");
}
//// OTPトークン
/**
* OTPトークンの作成
* @todo テスト
*
* @param int $id
* @return Result
*/
public function createSslOtpToken(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$uri = "/ssl/orders/{$id}/otp-tokens";
$curl = $this->setupCurl($uri, 'POST');
$res = $this->curlResult($curl);
if (isset($res)) {
return Result::Success('', $res->data);
}
return Result::Error("OTPトークンの作成に失敗。");
}
//// 商品
/**
* 商品一覧
* @todo テスト
*
* @param array $query 検索クエリー
* @return Result
*/
public function listSslProducts(array $query = []): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = 'listsslproducts';
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
$uri = '/ssl/products?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['query'] = $query;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('商品一覧の受け取りに失敗。');
}
/**
* 商品の表示
* @todo テスト
*
* @param int $id 商品ID
* @return Result
*/
public function getSslProduct(int $id): Result {
if (!OPENPROVIDER_ENABLED) return Result::error('エラーOpenProviderは無効です。');
$cacheName = "getsslproduct-{$id}";
$cache = $this->cache->get($cacheName);
if ($this->cache->validate($cache, $id, 'id')) return Result::Success('', $cache);
// kys($uri);
$curl = $this->setupCurl($uri);
$res = $this->curlResult($curl);
if (isset($res->data['data'])) {
$res->data['id'] = $id;
$this->cache->set($cacheName, $res->data);
return Result::Success('', $res->data);
}
return Result::Error('商品の受け取りに失敗。');
}
////////
/**
* トークンの受け取り。
*
* @return string トークン
*/
public function getToken(): string {
if (!OPENPROVIDER_ENABLED) return '';
return $this->token;
}
/**
* リセラーIDの受け取り。
*
* @return int リセラーID
*/
public function getResellerId(): int {
if (!OPENPROVIDER_ENABLED) return 0;
return $this->resellerId;
}
//////////
private function setupCurl(string $uri, string $resType = 'GET', array $payload = []): Curl {
$curl = new Curl("{$this->BASEURL}{$uri}");
$curl->setMethod($resType);
if (!empty($payload)) $curl->setPostRaw(json_encode($payload));
$curl->setBearerAuth($this->token);
$curl->addHeader('Content-Type', 'application/json');
$curl->addHeader('Accept', 'application/json');
return $curl;
}
private function curlResult(Curl &$curl): Result {
$res = $curl->execute();
if (!$res->isSuccess) {
$err = "CURL実行に失敗 {$curl->message}";
assert_unless_success($res, $err);
return Result::Error($err);
}
$body = $curl->getResponseBody();
if ($curl->getResponseCode() != 200) {
$err = json_decode($body, true);
assert_not_null($err, "エラーの受け取りに失敗。");
assert($curl->getResponseCode() == 200, $err['desc']);
return Result::Error($err['desc']);
}
assert_not_null($body, "返事ボディーは空です。");
return Result::Success('', json_decode($body, true));
}
}