<php
header(
"Content-Type:text/html;charset=UTF-8"
);
$appKey
= '12345678;
$appSecret
= '123456789';
$usernick
= 'grayvoice';
$salenick
= '缺水鱼儿';
function
createSign (
$paramArr
) {
global
$appSecret
;
$sign
=
$appSecret
;
ksort(
$paramArr
);
foreach
(
$paramArr
as
$key
=>
$val
) {
if
(
$key
!='' &&
$val
!='') {
$sign
.=
$key
.
$val
;
}
}
$sign
=
strtoupper
(md5(
$sign
));
return
$sign
;
}
function
createStrParam (
$paramArr
) {
$strParam
= '';
foreach
(
$paramArr
as
$key
=>
$val
) {
if
(
$key
!= '' &&
$val
!='') {
$strParam
.=
$key
.'='.urlencode(
$val
).'&';
}
}
return
$strParam
;
}
function
getXmlData (
$strXml
) {
$pos
=
strpos
(
$strXml
, 'xml');
if
(
$pos
) {
$xmlCode
=simplexml_load_string(
$strXml
,'SimpleXMLElement', LIBXML_NOCDATA);
$arrayCode
=get_object_vars_final(
$xmlCode
);
return
$arrayCode
;
}
else
{
return
'';
}
}
function
get_object_vars_final(
$obj
){
if
(
is_object
(
$obj
)){
$obj
=get_object_vars(
$obj
);
}
if
(
is_array
(
$obj
)){
foreach
(
$obj
as
$key
=>
$value
){
$obj
[
$key
]=get_object_vars_final(
$value
);
}
}
return
$obj
;
}
$paramArr
=
array
(
'app_key' =>
$appKey
,
'method' => 'taobao.shop.get',
'format' => 'xml',
'v' => '1.0',
'timestamp' =>
date
('Y-m-d H:i:s'),
'fields' => 'sid,nick,title',
'nick' =>
$salenick
);
$sign
= createSign(
$paramArr
);
$strParam
= createStrParam(
$paramArr
);
$strParam
.= 'sign='.
$sign
;
$url
= 'http:
$result
=
file_get_contents
(
$url
);
$result
= getXmlData(
$result
);
$sid
=
$result
['shop']['sid'];
$nick
=
$result
['shop']['nick'];
$title
=
$result
['shop']['title'];
>