php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法
本文实例讲述了php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法。分享给大家供大家参考。具体实现方法如下:
<?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 echo '卖家店铺ID:'.$sid.'<br>';> <!-- 在页面打印店铺ID --> <php echo '卖家昵称:'.$nick.'<br>';> <!-- 在页面打印卖家昵称--> <php echo '店铺标题:'.$title.'<br>';> <!-- 在页面打印卖家店铺标题 -->
希望本文所述对大家的php程序设计有所帮助。
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23