Файл: billing/_rootinc/todaynic/agentxmlclient.inc.php
Строк: 184
<?
class XMLClient
{
public $responseXML;
public $sendXML;
public $DEBUG=0;
public $serverURL;
public $VCP;
public $VCPPassword;
public $smsuser;
public $smspassword;
public function getCode()
{
$start_pos = strpos($this->responseXML, "<result code="");
return trim(substr($this->responseXML, $start_pos + 14, 4));
}
public function getMessage()
{
return getValue("msg",$this->responseXML);
}
public function isSuccess()
{
return preg_match("/successfully/i",$this->responseXML);
}
public function sendXMLData($XMLDATA)
{
$this->sendXML=$XMLDATA;
$buffer=8192; //ûС
$timeout=20; //socketӳʱʱ
$this->responseXML="";
if($this->DEBUG)echo "sendxml:".$XMLDATA;
$this->serverURL=preg_replace("/^http:///i","",$this->serverURL);
$pos=strpos($this->serverURL,"/");
if($pos>0){
$deshost=substr($this->serverURL,0,$pos);
$despath=substr($this->serverURL,$pos);
}else{
$deshost=$this->serverURL;
$despath="/";
}
$pos=strpos($deshost,":");
if($pos>0){
$port=substr($deshost,$pos+1);
$deshost=substr($deshost,0,$pos);
}else $port=80;
if($this->DEBUG) echo "$deshost:$port:$despath";
if(strlen($deshost)==0 || strlen($despath)==0 || $port<=0)
{
$this->responseXML="HOST:".$deshost." PORT:".$port." PATH:".$despath;
return $this->responseXML;
}
$fp =@fsockopen($deshost, $port, $errno, $errstr, $timeout);
if(!$fp)
{
$this->responseXML="unable to connect to ".$deshost.":".$port;
return $this->responseXML;
}
/*
$out = "POST $despath HTTP/1.1rn";
$out .= "Host: $deshostrn";
$out .= "Content-Length: ".strlen($XMLDATA)."rn";
$out .= "Connection: Closernrn";
*/
$out=$XMLDATA;
fputs($fp, $out);
do {
$data = fread($fp, $buffer);
if (strlen($data) == 0) break;
$contents .= $data;
if (preg_match("/</scp>/i", $contents)) break;
} while(true);
fclose($fp);
$this->responseXML=$contents;
if($this->DEBUG) echo $this->responseXML;
if(!$this->responseXML) $this->responseXML="NO XML Error,please check the xml which post to Server.";
return $this->responseXML;
}
public function toPlain(){
$contents=trim($this->responseXML);
$contents=strstr($contents,"<?xml");
$end=strpos($contents,"</scp>")+strlen("</scp>");
$contents=substr($contents,0,$end);
if($contents) $this->responseXML=$contents;
return $this->responseXML;
}
public function sendSCPData($desurl,$XMLDATA){
$XMLDATA=$this->toSCPXML($XMLDATA);
return $this->sendXMLData($XMLDATA);
}
public function toArray($content="response",$parsetype=0){
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$this->responseXML,$values,$tags);
xml_parser_free($parser);
$showMess=XMLtoArray($values,$tags,$content,$parsetype);
if(!$showMess) $showMess[Error]=$this->responseXML;
return $showMess;
}
public function toSCPXML($CommandXML)
{
$cltrid=CltrID();
if($this->VCP){
$clientid=getENCID($cltrid,$this->VCPPassword);
$respxml="<?xml version="1.0" encoding="GB2312"?>
<scp xmlns="urn:scp:params:xml:ns:scp-3.0"
xmlns:domain="urn:todaynic.com:domain"
xmlns:contact="urn:todaynic.com:contact"
xmlns:registrant="urn:todayisp.com:registrant"
xmlns:vhost="urn:todaynic.com:vhost"
xmlns:host="urn:todaynic.com:host"
xmlns:email="urn:todaynic.com:email"
xmlns:sms="urn:todaynic.com:sms"
xmlns:user="urn:todaynic.com:user">
<command>
$CommandXML
</command>
<security>
<vcpuser>$this->VCP</vcpuser>
<cltrid>$cltrid</cltrid>
<login>$clientid</login>
</security>
</scp>";
}
else {
$clientid=getENCID($cltrid,$this->smspassword);
$respxml="<?xml version="1.0" encoding="GB2312"?>
<scp xmlns="urn:scp:params:xml:ns:scp-3.0"
xmlns:sms="urn:todaynic.com:sms"
xmlns:user="urn:todaynic.com:user">
<command>
$CommandXML
</command>
<security>
<smsuser>$this->smsuser</smsuser>
<cltrid>$cltrid</cltrid>
<login>$clientid</login>
</security>
</scp>";
}
//
//$respxml=preg_replace("/t/i"," ",$respxml);
return $respxml;
}
public function getUserInfo($contactI)
{
$sendxml="<action>user:detail</action>
<userid>$contactI[userid]</userid>
<userpassword>$contactI[userpassword]</userpassword>";
$this->sendSCPData($this->serverURL,$sendxml);
$this->toPlain();
return $this->responseXML;
}
}
?>