<?php
class
KuaidiAPI{
private
$_APPKEY
=
''
;
private
$_APIURL
=
"http://highapi.kuaidi.com/openapi-querycountordernumber.html?"
;
private
$_show
= 0;
private
$_muti
= 0;
private
$_order
=
'desc'
;
public
function
KuaidiAPi(
$key
){
$this
->_APPKEY =
$key
;
}
public
function
setShow(
$show
= 0){
$this
->_show =
$show
;
}
public
function
setMuti(
$muti
= 0){
$this
->_muti =
$muti
;
}
public
function
setOrder(
$order
=
'desc'
){
$this
->_order =
$order
;
}
public
function
query(
$nu
,
$com
=
''
){
if
(function_exists(
'curl_init'
) == 1) {
$url
=
$this
->_APIURL;
$dataArr
=
array
(
'id'
=>
$this
->_APPKEY,
'com'
=>
$com
,
'nu'
=>
$nu
,
'show'
=>
$this
->_show,
'muti'
=>
$this
->_muti,
'order'
=>
$this
->_order
);
foreach
(
$dataArr
as
$key
=>
$value
) {
$url
.=
$key
.
'='
.
$value
.
"&"
;
}
$curl
= curl_init();
curl_setopt(
$curl
, CURLOPT_URL,
$url
);
curl_setopt(
$curl
, CURLOPT_HEADER, 0);
curl_setopt(
$curl
, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
$curl
, CURLOPT_TIMEOUT, 10);
$kuaidresult
= curl_exec(
$curl
);
curl_close(
$curl
);
if
(
$this
->_show == 0){
$result
= json_decode(
$kuaidresult
, true);
}
else
{
$result
=
$kuaidresult
;
}
return
$result
;
}
else
{
throw
new
Exception(
"Please install curl plugin"
, 1);
}
}
}