<?php
/*
$request = new request();
$data = array('method'=>'taobao.user.get','fields'=>'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind','nick'=>'ray1985514');
die($request->get($data));
*/
class
request {
private
$params
=
array
(
'format'
=>
'xml'
,
'app_key'
=>App_Key,
'sign_method'
=>
'md5'
,
'v'
=>
'2.0'
);
private
$server_url
;
private
$App_Secret
;
private
$cache
=NULL;
function
request(&
$_cache
) {
$this
->cache=
$_cache
;
if
(SANFBOX){
$this
->server_url=
'http://gw.api./router/rest'
;
$this
->App_Secret=
'sandbox6df2fdfb1fe3f05a64c4c6743'
;
}
else
{
$this
->server_url=
'http://gw.api.taobao.com/router/rest'
;//http://gw.api.taobao.com/router/rest
$this
->App_Secret=
'9cf5af56df2fdfb1fe3f05a64c4c6743'
;
}
}
public
function
get(
$data
){
$key
=md5(serialize(
$data
));
$rs
=
$this
->cache->get(
$key
);
if
(
$rs
)
return
simplexml_load_string(
$rs
);
$data
[
'timestamp'
]=
date
(
'Y-m-d H:i:s'
);
$this
->params =
array_merge
(
$this
->params,
$data
);
ksort(
$this
->params);
$url
=
$this
->server_url.
'?'
;
$dv
=
''
;
$tmp
=
''
;
$url_param
=
''
;
foreach
(
$this
->params
as
$k
=>
$v
){
$url_param
.=
$dv
.
$k
.
'='
.urlencode(
$v
);
$tmp
.=
$k
.
$v
;
$dv
=
'&'
;
}
//die ($App_Secret.$tmp.$App_Secret);
$url
.=
$url_param
.
'&sign='
.
strtoupper
(md5(
$this
->App_Secret.
$tmp
.
$this
->App_Secret));
//die($url);
$rs
=
$this
->curl(
$url
);
$this
->cache->set(
$key
,
$rs
,Cache_timeout);
$rs
=simplexml_load_string(
$rs
);
return
$rs
;
}
private
function
curl(
$url
)
{
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$url
);
curl_setopt(
$ch
, CURLOPT_HEADER, 0);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
$result
= curl_exec(
$ch
);
curl_close(
$ch
);
return
$result
;
}
}
?>