我正在尝试创建一个代表 NXCP 消息的类(它是与监控系统 NetXMS 一起使用的协议),我正在尝试对其进行修改http://wiki.netxms.org/wiki/Communication_Protocol_Reference_Guide
..这是我到目前为止的代码
NXCP.inc.php:
<?php
class message_nxcp {
public $message;
public $header;
public $payload;
public $padding;
function header ($name,$ID,$eof,$de,$ro,$eos,$c )
{ //CODE
$sql= "select value from nxcp_code where name = '$name'" ;
$code=mysql_query($sql);
//FLAG
//$sql1="select Value from flag where name = '$flag'"; $flag=mysql_query($sql1);
if ($eof=true){ $flag =0x0002;}
elseif ($de=true) {$flag = 0x0004;}
elseif ($eos=true) {$flag = 0x0008;}
elseif ($ro=true) {$flag = 0x0010;}
elseif ($c=true) {$flag = 0x0020;
$payload= ' ';}
//SIZE
$size=strlen($message);
//ID
$this->id= $ID;
// HEADER
$header= $code.$flag.$size.$id.$df_count;
}
function payload ($var_id,$d_type,$value)
{ //VARIABLE id
$sql= "select value from nxcp_code where name = '$var_id'" ;
$vid=mysql_query($sql);
//data type ,padding ,data
if ($d_type = 'integer')
{ $data_type =0;
$padding1= 00;
$data=$value;
}
if ($d_type ='string' )
{ $data_type =1;
$padding1= 00;
$data= strlen($value).$value;
}
if ($d_type = 'int64')
{ $data_type =2;
$padding1=00 ;
$data=$value;
}
if ($d_type ='int32')
{ $data_type =3;
$padding1= '';
$data=$value;
}
if ($d_type ='binary')
{ $data_type =4;
$padding1= 00;
$data=strlen($value).$value;
}
if ($d_type ='float')
{ $data_type =5;
$padding1= 00;
$data=$value;
}
$payload=$vid.$data_type.$padding1.$data ;
}
function padding ()
{
$i =0 ;
$pad = 262160 - (strlen($header)+strlen($payload));
if ($pad > 0)
{
for ($i=0 ; $i<$pad ; $i++)
{
$padding= $padding.'0' ;
}
}
}
function message()
{ $message = $header.$payload.$padding;
return $message;
}
}
?>
然后我message_nxcp
在 new.php 中创建我的类的一个新对象:
<?php
require_once('NXCP.inc.php');
$message=new message_nxcp;
$message->header('CMD_LOGIN' ,'1',true,false,false,false,false);
$message->payload('VID_LOGIN_NAME','string','admin');
$message->padding();
$message->message();
echo $message;
?>
任何帮助,并提前感谢