Home > Backend Development > PHP Tutorial > PHP calls Taobao open API to implement the method of obtaining the seller's store ID based on the seller's nickname, api seller_PHP tutorial

PHP calls Taobao open API to implement the method of obtaining the seller's store ID based on the seller's nickname, api seller_PHP tutorial

WBOY
Release: 2016-07-13 09:45:42
Original
914 people have browsed it

php calls Taobao open API to obtain the seller's store ID based on the seller's nickname, api seller

This article describes the example of php calling Taobao open API to obtain the seller's store ID based on the seller's nickname method. Share it with everyone for your reference. The specific implementation method is as follows:

<&#63;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']; //返回卖家店铺标题 
&#63;> 
<php echo '卖家店铺ID:'.$sid.'<br>';> <!-- 在页面打印店铺ID --> 
<php echo '卖家昵称:'.$nick.'<br>';> <!-- 在页面打印卖家昵称--> 
<php echo '店铺标题:'.$title.'<br>';> <!-- 在页面打印卖家店铺标题 -->

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1039196.htmlTechArticlephp calls Taobao’s open API to implement the method of obtaining the seller’s store ID based on the seller’s nickname. The api seller’s example in this article describes the php call Taobao's open API enables obtaining the seller's store ID based on the seller's nickname...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template