时间:2021-07-01 10:21:17 帮助过:23人阅读
<?php header("Content-Type:text/html;charset=UTF-8"); /*本程序功能:根卖家昵称获取卖家店铺sid,还有店铺标题*/ //config $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; } //解析xml函数 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', /*想要返回的数据的相应参数,sid对应卖家店铺id,nick对应卖家昵称,这里其实不用返回,因为已经知道了嘛。title对应卖家店铺标题,也就是店铺名称*/ 'nick' => $salenick //卖家昵称 ); //生成签名 $sign = createSign($paramArr); //组织参数 $strParam = createStrParam($paramArr); $strParam .= 'sign='.$sign; //访问服务 $url = 'http://gw.api.taobao.com/router/rest'.$strParam; $result = file_get_contents($url); $result = getXmlData($result); $sid = $result['shop']['sid']; //返回卖家店铺ID $nick = $result['shop']['nick']; //返回卖家昵称 $title = $result['shop']['title']; //返回卖家店铺标题 ?>';> ';> ';>
希望本文所述对大家的php程序设计有所帮助。