我正在尝试使用 CentralNic PHP EPP 库与 Nominet EPP 进行交互。
很清楚如何使用 Net_EPP_Frame_Command 类生成命令帧 例如,
$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>
这正是我需要的。唯一的问题是我无法生成必须看起来类似于
<?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>
你能指导我正确的方向吗?
谢谢
我编辑了 https://github.com/centralnic/php-epp/blob/master/Net/EPP/Frame/Command.php 通过在类中插入另外两个函数
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;
}
在当前情况下看起来最好的最终版本
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;
}