简体   繁体   English

连接到域注册表EPP服务器

[英]Connecting to domain registry EPP server

I'm getting my sea legs and need some pointers and a small sample of code that connects to an epp server. 我正在学习,需要一些指针和一小段连接到epp服务器的代码示例。 The sample of code need to login and send one command and receive a response.(in XML). 代码示例需要登录并发送一个命令并接收响应(以XML格式)。 Code can be in php or python. 代码可以在php或python中。

This I believe will form a basis/kickstart for me to delve in further and learn more about this topic. 我相信这将成为我进一步研究并了解有关此主题的基础/开始。 It's driving me up the wall - in a good way as I want to solve it in one day or a thousand. 它使我无法自拔-一种很好的方式,因为我想在一天或一千天内解决它。

And I have been searching for days now but can't seem to make sense of the info found, and now opted to ask here for guidance. 我现在已经搜索了几天,但似乎无法理解找到的信息,因此选择在此处寻求指导。

Thank you in advance. 先感谢您。

This is sample php script 这是示例PHP脚本

<?php


class Epp 
{

var $socket;

public function __construct()
{
}


private $_connected = false;

function connect($host, $port = 700, $timeout = 1, $ssl = true)
{
    if ($this->_connected)
        return true;
    $target = sprintf('%s://%s', ($ssl === true ? 'ssl' : 'tcp'), $host);
    $socket = fsockopen($target, $port, $errno, $errstr, $timeout);
    if (!$socket) {
        return new PEAR_Error("Error connecting to $target: $errstr (code $errno)");
    } else {
        $this->socket = $socket;
        $this->_connected = true;
        return $this->getFrame();
    }
}


function getFrame()
{
    if (feof($this->socket))
        return new PEAR_Error("Connection appears to have closed.");
    $hdr = @fread($this->socket, 4);
    if (empty($hdr)) {
        return new PEAR_Error("Error reading from server: $php_errormsg");
    } else {
        $unpacked = unpack('N', $hdr);
        $answer = fread($this->socket, ($unpacked[1] - 4));
        return $answer;
    }
}

function sendFrame($xml)
{
    return @fwrite($this->socket, pack('N', (strlen($xml) + 4)) . $xml);
}

function disconnect()
{
    return @fclose($this->socket);
}

}

?>

And there are 4 functions , connect , getFrame , sendFrame , disconnect . 并且有4个函数,connect,getFrame,sendFrame,disconnect。 Epp protocol works following . Epp协议的工作原理如下。 Firstly you must connect to server . 首先,您必须连接到服务器。

Send xml request to server and receive xml response from server . 将xml请求发送到服务器,并从server接收xml响应。

And firstly you must login to server . 首先,您必须登录到server。 for that you must send login xml to server . 为此,您必须将登录xml发送到server。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
      epp-1.0.xsd">
    <command>
        <login>
            <clID><?php echo $username;?></clID>
            <pw><?php echo $password;?></pw>
            <options>
                <version>1.0</version>
                <lang>en</lang>
            </options>
            <svcs>
                <svcExtension>

                </svcExtension>
            </svcs>
        </login>
        <clTRID>12345</clTRID>
    </command>
</epp>

All request and responses is xml . 所有请求和响应都是xml。 And you can find xmls from this sites http://tools.ietf.org/html/rfc5732 您可以从以下站点找到xml: http://tools.ietf.org/html/rfc5732

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM