PHP calls Taobao open API to achieve the seller's nickname based on the seller's store ID method _php Tips

Source: Internet
Author: User
Tags php programming

The example in this article describes the way that PHP calls Taobao open API to get the seller's store ID based on the seller's nickname. Share to everyone for your reference. The implementation method is as follows:

<?php header ("Content-type:text/html;charset=utf-8"); * This program function: Root sellers nickname to get sellers store SID, there are shop title * * *//config $appKey = ' 12345678; 
Your secret key $appSecret = ' 123456789 '; $usernick = ' Grayvoice '; Your username $salenick = ' water shortage fish '; 
Seller Nickname//Signature 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; 
//The Group parameter function Createstrparam ($PARAMARR) {$strParam = '; foreach ($paramArr as $key => $val) {if ($key!= ' && $val!= ') {$strParam. = $key. ' = '. UrlEncode ($val). ' 
& '; 
} return $strParam; 
}//Parse XML functions 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; {//parameter array $paramArr = Array (' App_key ' => $appKey, ' method ' => ' taobao.shop.get ', ' Format ' => ' xml ', ' V ' =&G T ' 1.0 ', ' timestamp ' => date (' y-m-d h:i:s '), ' Fields ' => ' sid,nick,title ',/* The corresponding parameters of the data to be returned, Sid corresponds to the seller's store Id,nick the seller's nickname, There's no need to return here, because you already know. 
Title corresponding to the seller's shop titles, that is, the shop name * * Nick ' => $salenick//sellers nickname); 
Generate Signature $sign = Createsign ($PARAMARR); 
Tissue parameter $strParam = Createstrparam ($PARAMARR); 
$strParam. = ' sign= '. $sign; 
Access Service $url = ' http://gw.api.taobao.com/router/rest '. $strParam; 
$result = file_get_contents ($url); 
$result = Getxmldata ($result); $sid = $result [' Shop '] [' Sid ']; Return the seller Store id $nick = $result [' Shop '] [' Nick ']; Return the seller's nickname $title = $result [' Shop '] [' title ']; return Seller Shop title?> <php echo ' seller Store ID: '. $sid. ' <br> ';> <!--print Shop ID on page--> <php echo ' seller nickname: '. $nick. ' <br> ';> <!--print sellers nickname--> <php echo ' shop title: '. $title. '

 <br> ';> <!--print Seller shop title on page-->

I hope this article will help you with your PHP programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.