Слияние кода завершено, страница обновится автоматически
<?php
/**
* @author jake
* @version 1.0
* @created 09-三月-2009 9:45:38
*/
class JYNET
{
/**
* 错误信息
*/
var $__errorInfo = "";
/**
* 网络返回信息
*/
var $__netInfo = "";
/**
* 链接参数
*/
var $__linkParams = array();
/**
* 持续对象的ID
*/
var $__persi_object_id = 0;
/**
* 多次执行后返回的字符串信息,供调试
*/
var $__arrCallback = array();
/**
* 多次执行后返回的计时器
*/
var $__callbackCounter = 0;
private $ch;
/**
* 构造函数,同时进行网络验证及存储KEY
*
* @param mixed $value
*
* @return string
*/
function __construct( $remoteClass, $linkParams, $setPersistent ){
$this->__linkParams = $linkParams;
// 网络验证,返回验证信息
$args_client = array(
$this->__linkParams["clientid"],
$this->__linkParams["clientkey"]
);
$ping_echo = $this->sendCommand( $remoteClass, "PING", $args_client, true );
if( true == $setPersistent )$this->__persi_object_id = $ping_echo;
return false != $ping_echo;
}
function sendFile( $file_path ){
if( !is_readable($file_path) )return false;
$send_file = file_get_contents($file_path);
$send_file = base64_encode($send_file);
$sends = array(
"command" => "file",
"filename" => basename($file_path),
"md5" => md5($file_path),
"binary" => $send_file
);
$this->__arrCallback[$this->__callbackCounter]["send"] = array(
"command" => "file",
"filename" => basename($file_path),
"md5" => md5($file_path)
);
$tmp_back = $this->net_post( $sends );
$this->__arrCallback[$this->__callbackCounter]["result"] = $tmp_back["body"];
return $tmp_back["body"];
}
function sendCommand( $class, $func, $args, $forcePersistent = false ){
$sendPersistent = 0;
if( true == $forcePersistent ){
// 当PING的时候,$__persi_object_id为能赋值,那么需要强制设置
$sendPersistent = 1;
}else{
$sendPersistent = $this->__persi_object_id;
}
// 过滤 magic_quotes
if (get_magic_quotes_gpc()) {
$in = array(& $args);
while (list($k,$v) = each($in)) {
foreach ($v as $key => $val) {
if (!is_array($val)) {
$in[$k][$key] = stripslashes($val);
$in[$k][$key] = str_replace("\\\"", "\"",$val);
continue;
}
$in[] =& $in[$k][$key];
}
}
unset($in);
}
set_magic_quotes_runtime(0);
$sends = array(
"command" => $class,
"function" => $func,
"args" => $this->net_encode( $args ),
"persistent" => $sendPersistent,
);
$this->__arrCallback[$this->__callbackCounter]["send"] = array(
"command" => $class,
"function" => $func,
"args" => $args,
"persistent" => $sendPersistent,
);
return $this->getContent( $this->net_post( $sends ) );
}
function getContent( $net_data ){
$this->__arrCallback[$this->__callbackCounter]["result"] = $this->net_decode( $net_data["body"] );
return $this->net_decode( $net_data["body"] );
}
/**
*
* $params = array('url' => '',
* 'host' => '', // 'http://www.google.com'
* 'header' => '',
* 'method' => '', // 'POST','HEAD'
* 'referer' => '',
* 'cookie' => '',
* 'post_fields' => '', // 'var1=value&var2=value
* ['login' => '',]
* ['password' => '',]
* 'timeout' => 0
* );
*/
function net_post( $sends ){
try
{
$params = array_merge( $this->__linkParams, array( "post_fields" => $sends ) );
$this->send_init($params);
$result = $this->exec();
if ($result['curl_error'])throw new Exception($result['curl_error']);
if ($result['http_code']!='200')throw new Exception("HTTP Code = ".$result['http_code']);
if (!$result['body'])throw new Exception("NULL");
return $result;
}
catch (Exception $e)
{
$this->__errorInfo = $e->getMessage();
}
}
public function send_init($params)
{
$this->ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9';
$header = array("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5","Accept-Language: ru-ru,ru;q=0.7,en-us;q=0.5,en;q=0.3","Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7","Keep-Alive: 300");
if (isset($params['host']) && $params['host']) $header[]="Host: ".$host;
if (isset($params['header']) && $params['header']) $header[]=$params['header'];
@curl_setopt ( $this -> ch , CURLOPT_RETURNTRANSFER , 1 );
@curl_setopt ( $this -> ch , CURLOPT_VERBOSE , 1 );
@curl_setopt ( $this -> ch , CURLOPT_HEADER , 1 );
if ($params['method'] == "HEAD") @curl_setopt($this -> ch,CURLOPT_NOBODY,1);
@curl_setopt ( $this -> ch, CURLOPT_FOLLOWLOCATION, 1);
@curl_setopt ( $this -> ch , CURLOPT_HTTPHEADER, $header );
if ($params['referer']) @curl_setopt ($this -> ch , CURLOPT_REFERER, $params['referer'] );
@curl_setopt ( $this -> ch , CURLOPT_USERAGENT, $user_agent);
if ($params['cookie']) @curl_setopt ($this -> ch , CURLOPT_COOKIE, $params['cookie']);
if ( $params['method'] == "POST" )
{
@curl_setopt( $this -> ch, CURLOPT_POST, true );
@curl_setopt( $this -> ch, CURLOPT_POSTFIELDS, $params['post_fields'] );
}
@curl_setopt( $this -> ch, CURLOPT_URL, $params['url']);
@curl_setopt ( $this -> ch , CURLOPT_SSL_VERIFYPEER, 0 );
@curl_setopt ( $this -> ch , CURLOPT_SSL_VERIFYHOST, 0 );
if (isset($params['login']) & isset($params['password']))
@curl_setopt($this -> ch , CURLOPT_USERPWD,$params['login'].':'.$params['password']);
@curl_setopt ( $this -> ch , CURLOPT_TIMEOUT, $params['timeout']);
}
/**
* Make curl request
*
* @return array 'header','body','curl_error','http_code','last_url'
*/
public function exec()
{
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$result = array( 'header' => '',
'body' => '',
'curl_error' => '',
'http_code' => '',
'last_url' => '');
if ( $error != "" )
{
$result['curl_error'] = $error;
return $result;
}
$header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
$result['http_code'] = curl_getinfo($this -> ch,CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($this -> ch,CURLINFO_EFFECTIVE_URL);
return $result;
}
/**
* 取得上次的错误信息
*
* @return string
*/
function getError(){
return $this->__errorInfo;
}
/**
* 取得一直以来的返回字符串
*
* @return string
*/
function getDump(){
return $this->__arrCallback;
}
/**
* 取得一直以来的返回字符串,无过滤
*
* @return string
*/
function getNetInfo(){
return $this->__netInfo;
}
/**
* 将变量转换为网络字符串
*
* @param mixed $value
*
* @return string
*/
function net_encode( $value ){
return urlencode( serialize( $value ) );
}
/**
* 将网络字符串转换为变量
*
* @param string $value
*
* @return mixed
*/
function net_decode($value){
$this->__netInfo = $value;
return @unserialize( urldecode( $value ) );
}
}
?>
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )