dir = $dir;
parent::__construct( $type, $uid, $sid, $key );
}
public function __call( $name, $args )
{
$path = CU_ROOT.$this->dir.'/'.$name.'.php';
if( !file_exists($path) )
{
trigger_error('请求路径错误',E_USER_ERROR);
}
@require $path;
if( !class_exists($name) )
{
trigger_error('实例不存在',E_USER_ERROR);
}
$C = new $name( $this->open_api, $args[0] );
// xml加壳
$request_xml = $C->request_xml( $this->_uid, $this->_sid,
$this->_stmp, $this->_sign, $this->_type );
$request = $this->request_xml_shell($request_xml);
// 远程通信
$http = new MyHttp($C->open_api);
$result_xml = $http->send($request);
// xml去壳
$respond = $this->respond_xml_shell($result_xml);
$respond_type = array_key_exists(1, $args)?$args[1]:FALSE;
if( !$respond_type )
{
$respond_xml = $C->respond_xml($respond);
}
else
{
$respond_xml = $this->respond_xml($respond,$respond_type);
}
return $respond_xml;
}
// 请求体xml加壳
public function request_xml_shell($xml)
{
$request_xml_shell =
''
.''
.''
.''
.'{%REQUEST_XML%}'
.''
.''
.'';
return str_replace('{%REQUEST_XML%}', $xml, $request_xml_shell);
}
// 返回体xml去壳
public function respond_xml_shell($xml)
{
$request_xml_begin =
''
.''
.''
.''
.'';
$request_xml_end =
''
.''
.''
.'';
return str_replace( $request_xml_end, '', str_replace($request_xml_begin, '', $xml) );
}
public function respond_xml($string, $type='')
{
// 将内层xmll中转义的符号恢复
$string = str_replace("<","<",$string);
$string = str_replace(">",">",$string);
$simplexml = simplexml_load_string($string);
switch ($type)
{
case 'xml':
return $simplexml;
break;
case 'json':
return json_encode($simplexml);
break;
case 'array':
return json_decode(json_encode($simplexml),TRUE);
break;
case 'object':
return json_decode(json_encode($simplexml),FALSE);
break;
case 'string':
default:
return $string;
}
}
}