centralnic PHP EPP 库 - 登录框架 [英] centralnic PHP EPP library - login frame
问题描述
我正在尝试使用 CentralNic PHP EPP 库与 Nominet EPP 交互.
I am trying to use CentralNic PHP EPP library to interact with Nominet EPP.
很清楚如何使用 Net_EPP_Frame_Command 类生成命令帧例如,
It is clear how to genrate command frames using Net_EPP_Frame_Command class For instance,
$frame = new Net_EPP_Frame_Command("check", "host");
$frame->addObjectProperty("name", "ns1.example.com");
$frame->addObjectProperty("name", "ns2.example.com");
$frame->addObjectProperty("name", "ns3.example.com");
$client->sendFrame($frame->saveXML());
结果是
<?xml version="1.0"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<host:check xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>ns1.example.com</host:name>
<host:name>ns2.example.com</host:name>
<host:name>ns3.example.com</host:name>
</host:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
这正是我需要的.唯一的问题是我无法生成看起来类似于
Which is exactly what I need. The only problem is that I am unable to generate login frame that has to look similar to
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<login>
<clID>ClientX</clID>
<pw>foo-BAR2</pw>
<newPW>bar-FOO2</newPW>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>urn:ietf:params:xml:ns:obj1</objURI>
<objURI>urn:ietf:params:xml:ns:obj2</objURI>
<objURI>urn:ietf:params:xml:ns:obj3</objURI>
<svcExtension>
<extURI>http://custom/obj1ext-1.0</extURI>
</svcExtension>
</svcs>
</login>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
你能指导我正确的方向吗?
Could you please guide me in a right direction?
谢谢
我编辑了https://github.com/centralnic/php-epp/blob/master/Net/EPP/Frame/Command.php通过在类中插入另外两个函数
I edited https://github.com/centralnic/php-epp/blob/master/Net/EPP/Frame/Command.php By inserting two more functions to the class
function setParam($param, $value)
{
$this->$param->appendChild($this->createTextNode($value));
//$this->$param->setAttribute($param, $value);
}
function addElement($name, $value, $parentNode)
{
$element = $this->createElement($name);
$element->appendChild($this->createTextNode($value));
$this->$parentNode->appendChild($element);
}
我现在使用它的方式:
public function login($clid, $pw)
{
$frame = $this->buildLoginFrame($clid, $pw);
$this->client->sendFrame($frame->saveXML());
print_r($frame->friendly());
print_r($this->client->getFrame());
}
private function buildLoginFrame($clid, $pw)
{
$frame = new Net_EPP_Frame_Command_Login();
$frame->setParam("clID", $clid);
$frame->setParam("pw", $pw);
$frame->setParam("eppVersion", self::VERSION);
$frame->setParam("eppLang", self::LANG);
$frame->addElement("objURI", "urn:ietf:params:xml:ns:contact-1.0", "svcs");
$frame->addElement("objURI", "urn:ietf:params:xml:ns:domain-1.0", "svcs");
$frame->addElement("objURI", "urn:ietf:params:xml:ns:host-1.0", "svcs");
$frame->setParam("clTRID", $this->clTRID);
return $frame;
}
<小时>
目前看来最好的最终版本
The final version that seems the best in the current situation
class EPPHelper
{
static function setParam($frame, $param, $value)
{
$frame->$param->appendChild($frame->createTextNode($value));
}
public function addElement($frame, $name, $value, $parentNode)
{
$element = $frame->createElement($name);
$element->appendChild($frame->createTextNode($value));
$parentNode->appendChild($element);
}
}
}
...
public function login($clid, $pw)
{
$frame = $this->buildLoginFrame($clid, $pw);
$this->client->sendFrame($frame->saveXML());
print_r($frame->friendly());
print_r($this->client->getFrame());
}
private function buildLoginFrame($clid, $pw)
{
$frame = new Net_EPP_Frame_Command_Login();
//$frame->setParam("clID", $clid);
EPPHelper::setParam($frame, "clID", $clid);
EPPHelper::setParam($frame, "pw", $pw);
EPPHelper::setParam($frame, "eppVersion", self::VERSION);
EPPHelper::setParam($frame, "eppLang", self::LANG);
EPPHelper::addElement($frame, "objURI", "urn:ietf:params:xml:ns:contact-1.0", $frame->svcs);
EPPHelper::addElement($frame, "objURI", "urn:ietf:params:xml:ns:domain-1.0", $frame->svcs);
EPPHelper::addElement($frame, "objURI", "urn:ietf:params:xml:ns:host-1.0", $frame->svcs);
EPPHelper::setParam($frame, "clTRID", $this->clTRID);
return $frame;
}
推荐答案
正是出于这个原因,我创建了一个新库:https://github.com/AfriCC/php-epp2 - 它最初是作为 Net_EPP 的扩展/分支,但最终可能只共享了 Net_EPP 代码的 1%.
for exactly this reason I created a new library: https://github.com/AfriCC/php-epp2 - it started as extension/fork of Net_EPP, but ending up sharing maybe only 1% of the code of Net_EPP.
基本上它是 PHP 的高级"EPP 客户端.高级意味着,您不必担心创建对象/XML,而只需使用方便的方法来修改您的框架.
Basically it is a "high-level" EPP Client for PHP. High-level means, you don't have to worry about creating objects/XML but can just use the convenient methods to modify your frames.
<?php
require 'src/AfriCC/autoload.php';
use AfriCC\EPP\Frame\Command\Create\Host as CreateHost;
$frame = new CreateHost;
$frame->setHost('ns1.example.com');
$frame->addAddr('8.8.8.8');
$frame->addAddr('8.8.4.4');
$frame->addAddr('2a00:1450:4009:809::1001');
echo $frame;
此外,如果您使用客户端,它会自动为您进行登录/注销:
Also if you use the Client, it will automatically do the login/logout for your:
<?php
require 'src/AfriCC/autoload.php';
use AfriCC\EPP\Client as EPPClient;
$epp_client = new EPPClient([
'host' => 'epptest.org',
'username' => 'foo',
'password' => 'bar',
'services' => [
'urn:ietf:params:xml:ns:domain-1.0',
'urn:ietf:params:xml:ns:contact-1.0'
],
'debug' => true,
]);
try {
$greeting = $epp_client->connect();
} catch(Exception $e) {
echo $e->getMessage() . PHP_EOL;
unset($epp_client);
exit(1);
}
$epp_client->close();
它仍然是相当新的,因此可能存在一些错误.它是开源的,所以不要对它嗤之以鼻,只需提交错误报告或进行合并请求:)
It is still fairly new, so there might be some bugs. Its opensource, so don't be a dick about it and just file a bug report or do a merge request :)
这篇关于centralnic PHP EPP 库 - 登录框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!