vendasta / godaddy
用于Vendasta的Godaddy服务的PHP库
Requires
- google/common-protos: ^1.1
- google/protobuf: ^3.9.2
- grpc/grpc: ^v1.1.0
- guzzlehttp/guzzle: ^6.3
- mdanter/ecc: ^0.5.0
- vendasta/vax: ^1.2.0
Requires (Dev)
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2024-09-27 13:33:34 UTC
README
描述
这是Vendasta官方的GoDaddy API集成PHP SDK。
要求
- PHP 5.5以上或PHP 7.0以上
- PECL(可能用于安装所需的PHP扩展)
- Composer
- PHP gmp扩展
- 可选(但推荐):PHP grpc扩展
安装
安装上述要求,然后
composer require vendasta/godaddy
身份验证
为了验证SDK调用,您必须从Vendasta平台内部配置一个服务账户。请参考服务账户指南以设置身份验证。
您必须将此文件放在您的服务器上,并设置一个环境变量指向它的路径
export VENDASTA_APPLICATION_CREDENTIALS=<path to credentials.json>
客户端初始化
强烈建议您使用单例客户端实例。每次客户端初始化都会打开它自己的连接,因此使用单例将导致重用连接,节省时间和资源。
设置环境变量
export ENVIRONMENT=<DEMO or PROD>
以实例化客户端
$environment = getenv("ENVIRONMENT"); if ($environment == null) { $environment = "DEMO"; } $client = new Vendasta\Godaddy\V1\GoDaddyClient($environment);
注意,如果未指定,环境将被设置为DEMOS。
配置GoDaddy账户
可以通过使用Account Group SDK和Sales Orders SDK来配置新的GoDaddy账户。Account Group SDK用于在合作伙伴中心创建业务账户。请按照README进行安装和设置。创建是同步的。它立即创建账户并返回您创建的业务账户组ID(在其他SDK中使用作为业务ID)。业务创建后,您可以使用Sales Orders SDK使用Account Group SDK中的业务ID在该业务上购买产品。CreateAndActivateOrder是一个异步过程,可能导致供应商的批准或拒绝。可以使用GetSalesOrder端点轮询订单状态,前提是从CreateAndActivateOrder中提供订单ID。
生产App ID:MP-4TMLZSQ5FMJQX5T75TPC43FQBWD2VXLB
演示环境App ID:MP-NNTJMBF6HPXR5XXC2JKCFWKJ64VZLBFQ
// Choose environment and partnerId $env = "DEMO"; $pid = "<PID>"; // Instantiate clients $accountGroupClient = new AccountGroupServiceClient($env); $salesOrdersClient = new SalesOrdersClient($env); // Build request to create a business $createReq = new CreateAccountGroupRequest(); $location = new AccountGroupLocation(); $location->setCompanyName("Test Company"); $location->setAddress("123 Street Name"); $location->setCity("Chicago"); $location->setState("IL"); $location->setCountry("US"); $location->setZip("88888"); $workNumber = array("(999) 999-9999"); $location->setWorkNumber($workNumber); $createReq->setAccountGroupNap($location); $createReq->setPartnerId($pid); // Make call and store returned accountGroupId $resp = $accountGroupClient->Create($createReq); $accountGroupId = $resp->getAccountGroupId(); // Build sales order request & activate the products // Create the request $req = new CreateAndActivateOrderRequest(); // Create the line items $goDaddy = SalesOrdersUtils::buildLineItem('MP-NNTJMBF6HPXR5XXC2JKCFWKJ64VZLBFQ'); $lineItems = array($goDaddy); // Create the custom fields $goDaddyCustomField = SalesOrdersUtils::buildGoDaddyCustomFields("MP-NNTJMBF6HPXR5XXC2JKCFWKJ64VZLBFQ", "testdomain123.com", "example@email.com", "First", "Last", "3065555555", "example@email.com", "First", "Last"); $customFields = array($goDaddyCustomField); // Create the order $order = SalesOrdersUtils::buildOrder($pid, $accountGroupId, $lineItems, $customFields); $req->setOrder($order); // Call CreateAndActivateOrder $resp = $salesOrdersClient->CreateAndActivateOrder($req); // Poll the pending activation process using GetSalesOrder
取消配置账户
// Choose environment and partnerId $env = "DEMO"; $pid = ""; // Select the app ID and business ID to deactivate $businessId = ""; $appId = ""; // The activation ID will be populated after we list all the products on the business $activationId = ""; $client = new AccountsServiceClient($env); // First list all of the current products activated for that business and find the one matching the appID $listReq = new ListRequest(); $listReq->setPartnerId($pid); $listReq->setBusinessId($businessId); $resp = $client->List($listReq); foreach($resp->getAccounts() as $account) { if ($account->getAppId() == $appId) { // The activation ID is necessary for deactivating an app $activationId = $account->getActivationId(); } } // Build the deactivation request with the activation ID $deactivationReq = new DeactivateAppRequest(); $deactivationReq->setBusinessId($businessId); $deactivationReq->setAppId($appId); $deactivationReq->setActivationId($activationId); $deactivationReq->setDeactivationType(DeactivationType::DEACTIVATION_TYPE_CANCEL);
如何使用此SDK
获取域名可用性
$req = new Godaddy\V1\GetDomainAvailableRequest(); $req->setDomain("<domain>"); $resp = $client->GetDomainAvailable($req);
修补域名
这可以用来锁定或解锁域名
$req = new PatchDomainRequest(); $req->setDomain("example.com"); $fieldMask = new FieldMask(); $paths = ["locked"]; $fieldMask->setPaths($paths); $req->setFieldMask($fieldMask); $req->setLocked(false); $resp = $client->PatchDomain($req);
获取域名详细信息
这可以用来获取有关域名的详细信息,包括AuthCode
$req = new GetDomainRequest(); $req->setDomain("example.com"); $resp = $client->GetDomain($req);