データ転送インタフェース
5795 ワード
header=array(
'CLIENT_TOKEN'=>$this->auth,
'CLIENT_CODE'=>$this->authcode
);
}
else
{
return false;
}
return true;
}
private function setauth($auth)
{
if($auth)
{
$this->auth=$auth;
$this->authcode=md5(substr(md5($auth),5,15).md5($auth));
}
else
{
return false;
}
return true;
}
// CURL ,
private function Api_Curl()
{
$time_out=300;
$timeout=100;
$url='';
$referer='';
$curl='';
if(!$this->url && !$this->data)
{
return false;
}
try
{
if(!$curl=curl_init())
{
throw new Exception(' !');
}
else
{
}
}
catch(Exception $e)
{
$e->getMessage();
}
curl_setopt($curl,CURLOPT_URL,$this->url);// ( )
curl_setopt($curl,CURLOPT_REFERER,$this->referer);// ( )
//curl_setopt($curl,CURLOPT_HTTPHEADER,$this->header);
//curl_setopt($curl,CURLOPT_HEADER,'content-type:aplication/json;charset=utf-8');
curl_setopt($curl,CURLOPT_POST,true);//
curl_setopt($curl,CURLOPT_POSTFIELDS,$this->data);//
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,$time_out);//
curl_setopt($curl,CURLOPT_TIMEOUT,$timeout);//
$result_data=curl_exec($curl);//
$error=curl_errno($curl);
curl_close($curl);
return $result_data;
}
//
public function DoRequest($url,$auth,$data=null)
{
$sign_str=$this->set_sign($data);
$sign=$this->get_sign($sign_str,$auth);
$data['sign']=$sign;
if($this->setauth($auth))
{
if($this->setheader())
{
$this->url=$url;
if(!empty($data))
{
if(is_array($data))
{
foreach($data as $key => $value)
{
$datas.=$key.'='.urlencode($value).'&';//urlencode()
}
$datas=rtrim($datas,'&');
$this->data=$datas;
unset($datas);
}
}
$result_data=$this->Api_Curl();
return $result_data;
}
}
}
//
public function __destruct()
{
}
//
private function display_multi_array($array)
{
if(empty($array))
{
return false;
}
elseif(is_array($array))
{
$count=count($array);
if($count>1)
{
foreach($array as $key => $value )
{
if(!is_array($value))
{
echo ''.$key.':'.$value.'
';
}
else
{
$this->display_multi_array($value);
}
}
}
}
else
{
echo ''.$array.'
';
}
}
private function set_sign($arr)
{
$sign='';
if(!is_array($arr))
{
return null;
}
ksort($arr,SORT_STRING);
foreach($arr as $key=>$value)
{
if($value!=null)
{
$sign.=$key.(is_array($value)?$this->get_sign($value):$value);
}
else
{
}
}
return $sign;
}
private function get_sign($sign,$token)
{
return strtoupper(md5(strtoupper(md5($sign)).$token));
}
}
$auth='';
$json_arr=array('data'=>'','count'=>'');
$json_arr=json_encode($json_arr);
$time=time();
$data=array('flag'=>'coprsys','method'=>'copr.add','type'=>'json',' timestamp'=>$time,'charset'=>'utf- 8','ver'=>1,'copr_data'=>$json_arr);
//$url='';
$url='';
$api=new UpFile_ApiClient();
$result=$api->DoRequest($url,$auth,$data);
?>