mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-22 10:25:35 +08:00
76 lines
2.6 KiB
PHP
76 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
|
|
class base_httpclient extends base_http{
|
|
|
|
function get($url,$headers=null,$callback=null,$ping_only=false){
|
|
return $this->action(__FUNCTION__,$url,$headers,$callback,null,$ping_only);
|
|
}
|
|
|
|
function post($url,$data,$headers=null,$callback=null,$ping_only=false){
|
|
return $this->action(__FUNCTION__,$url,$headers,$callback,$data,$ping_only);
|
|
}
|
|
|
|
function upload($url,$files,$data,$headers=null,$callback=null,$ping_only=false){
|
|
$boundary = '----ShopExFormBoundaryEsor2rdD1hne8INi';
|
|
$headers['Content-Type']='multipart/form-data; boundary='.$boundary;
|
|
$formData = array();
|
|
$this->_http_query($formData,$data);
|
|
|
|
$output ='';
|
|
foreach($formData as $k=>$v){
|
|
$output .= '--'.$boundary."\r\n";
|
|
$output .= 'Content-Disposition: form-data; name="'
|
|
.str_replace('"','\\\"',$k)."\"\r\n\r\n";
|
|
$output .= $v."\r\n";
|
|
}
|
|
foreach($files as $k=>$v){
|
|
$output .= '--'.$boundary."\r\n";
|
|
$output .= 'Content-Disposition: form-data; name="'
|
|
.str_replace('"','\\\"',$k).'"; filename="'.basename($v)."\"\r\n";
|
|
$mime = function_exists('mime_content_type')?mime_content_type($v):'application/octet-stream';
|
|
$output .= "Content-Type: $mime\r\n\r\n";
|
|
$output .= file_get_contents($v)."\r\n";
|
|
}
|
|
$output .= '--'.$boundary."--\r\n";
|
|
|
|
return $this->action('post',$url,$headers,$callback,$output,$ping_only);
|
|
}
|
|
|
|
function _http_query(&$return,$data,$prefix=null,$key='')
|
|
{
|
|
$ret = array();
|
|
foreach((array)$data as $k => $v){
|
|
if(is_int($k) && $prefix != null){
|
|
$k = $prefix.$k;
|
|
}
|
|
if(!empty($key)){
|
|
$k = $key."[".$k."]";
|
|
}
|
|
|
|
if(is_array($v) || is_object($v)){
|
|
$this->_http_query($return,$v,"",$k);
|
|
}else{
|
|
$return[$k]=$v;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|