Home  >  Article  >  php教程  >  淘宝开放API根据卖家昵称获取卖家店铺ID

淘宝开放API根据卖家昵称获取卖家店铺ID

PHP中文网
PHP中文网Original
2017-03-30 10:37:313418browse

淘宝开放API菜鸟教程根据卖家昵称获取卖家店铺ID

<php 
header("Content-Type:text/html;charset=UTF-8"); 
/*本程序功能:根卖家昵称获取卖家店铺sid,还有店铺标题*/ 
//config 
$appKey = &#39;12345678; //你的密匙 
$appSecret = &#39;123456789&#39;; 
$usernick = &#39;grayvoice&#39;; //你的用户名 
$salenick= &#39;缺水鱼儿&#39;; //卖家昵称 
//签名函数 
function createSign ($paramArr) { 
global $appSecret; 
$sign = $appSecret; 
ksort($paramArr); 
foreach ($paramArr as $key =>$val) { 
if ($key !=&#39;&#39; && $val !=&#39;&#39;) { 
$sign .= $key.$val; 
} 
} 
$sign = strtoupper(md5($sign)); 
return $sign; 
} 
//组参函数 
function createStrParam ($paramArr) { 
$strParam = &#39;&#39;; 
foreach ($paramArr as $key => $val) { 
if ($key != &#39;&#39; && $val !=&#39;&#39;) { 
$strParam .= $key.&#39;=&#39;.urlencode($val).&#39;&&#39;; 
} 
} 
return $strParam; 
} 
//解析xml函数 
function getXmlData ($strXml) { 
$pos = strpos($strXml, &#39;xml&#39;); 
if ($pos) { 
$xmlCode=simplexml_load_string($strXml,&#39;SimpleXMLElement&#39;, LIBXML_NOCDATA); 
$arrayCode=get_object_vars_final($xmlCode); 
return $arrayCode ; 
} else { 
return &#39;&#39;; 
} 
} 

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( 
&#39;app_key&#39; => $appKey, 
&#39;method&#39; => &#39;taobao.shop.get&#39;, 
&#39;format&#39; => &#39;xml&#39;, 
&#39;v&#39; => &#39;1.0&#39;, 
&#39;timestamp&#39; => date(&#39;Y-m-d H:i:s&#39;), 
&#39;fields&#39; => &#39;sid,nick,title&#39;,
/*想要返回的数据的相应参数,sid对应卖家店铺id,nick对应卖家昵称,这里其实不用返回,因为已经知道了嘛。
title对应卖家店铺标题,也就是店铺名称*/ 
&#39;nick&#39; => $salenick //卖家昵称 

); 
//生成签名 
$sign = createSign($paramArr); 
//组织参数 
$strParam = createStrParam($paramArr); 
$strParam .= &#39;sign=&#39;.$sign; 
//访问服务 
$url = &#39;http://gw.api.taobao.com/router/rest&#39;.$strParam; 
$result = file_get_contents($url); 
$result = getXmlData($result); 
$sid = $result[&#39;shop&#39;][&#39;sid&#39;]; //返回卖家店铺ID 
$nick = $result[&#39;shop&#39;][&#39;nick&#39;]; //返回卖家昵称 
$title = $result[&#39;shop&#39;][&#39;title&#39;]; //返回卖家店铺标题 
>

以上就是淘宝开放API根据卖家昵称获取卖家店铺ID的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn