Home > php教程 > php手册 > body text

php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法

WBOY
Release: 2016-06-06 19:49:59
Original
1353 people have browsed it

这篇文章主要介绍了php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法,实例分析了php调用淘宝API查询店铺信息的相关技巧,具有一定参考借鉴价值,需要的朋

本文实例讲述了php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法。分享给大家供大家参考。具体实现方法如下:

$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程序设计有所帮助。

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!