Home >Backend Development >PHP Tutorial >Taobao Open API Novice Tutorial - Obtain the seller's store ID based on the seller's nickname

Taobao Open API Novice Tutorial - Obtain the seller's store ID based on the seller's nickname

WBOY
WBOYOriginal
2016-07-25 09:02:401582browse
Taobao Open API Novice Tutorial - Obtain the sellers store ID based on the sellers nicknameOriginal address: http://blog.qita.in
  1. header("Content-Type:text/html;charset=UTF-8");
  2. /*This program function: get the seller's store sid based on the seller's nickname, and the store title*/
  3. / /config
  4. $appKey = '12345678; //Your key
  5. $appSecret = '123456789';
  6. $usernick = 'grayvoice'; //Your username
  7. $salenick= '无水鱼'; // Seller nickname
  8. //Signature function
  9. function createSign ($paramArr) {
  10. global $appSecret;
  11. $sign = $appSecret;
  12. ksort($paramArr);
  13. foreach ($paramArr as $key => $val) {
  14. if ($key !='' && $val !='') {
  15. $sign .= $key.$val;
  16. }
  17. }
  18. $sign = strtoupper(md5($sign));
  19. return $sign;
  20. }
  21. //Group parameter function
  22. function createStrParam ($paramArr) {
  23. $strParam = '';
  24. foreach ($paramArr as $key => $val) {
  25. if ($key != '' && $val !='') {
  26. $strParam .= $key.'='.urlencode($val).'&';
  27. }
  28. }
  29. return $strParam;
  30. }
  31. //Parse xml function
  32. function getXmlData ($ strXml) {
  33. $pos = strpos($strXml, 'xml');
  34. if ($pos) {
  35. $xmlCode=simplexml_load_string($strXml,'SimpleXMLElement', LIBXML_NOCDATA);
  36. $arrayCode=get_object_vars_final($xmlCode);
  37. return $arrayCode ;
  38. } else {
  39. return '';
  40. }
  41. }
  42. function get_object_vars_final($obj){
  43. if(is_object($obj)){
  44. $obj=get_object_vars($obj);
  45. }
  46. if(is_array($obj)){
  47. foreach ($obj as $key=>$value){
  48. $obj[$key]=get_object_vars_final($value);
  49. }
  50. }
  51. return $obj;
  52. }
  53. //Parameter array
  54. $paramArr = array(
  55. 'app_key' => $appKey,
  56. 'method' => 'taobao.shop.get',
  57. 'format' => 'xml',
  58. 'v' => '1.0',
  59. 'timestamp' => date('Y-m-d H:i:s'),
  60. 'fields' => 'sid,nick,title', /*Correspondence of the data you want to return Parameters, sid corresponds to the seller's store id, and nick corresponds to the seller's nickname. There is actually no need to return it here, because you already know it. title corresponds to the seller's store title, which is the store name*/
  61. 'nick' => $salenick //Seller's nickname
  62. );
  63. //Generate signature
  64. $sign = createSign($paramArr);
  65. //Organization parameters
  66. $strParam = createStrParam($paramArr);
  67. $strParam .= 'sign='.$sign;
  68. //Access service
  69. $url = 'http://gw.api.taobao.com/router/rest'.$ strParam;
  70. $result = file_get_contents($url);
  71. $result = getXmlData($result);
  72. $sid = $result['shop']['sid']; //Return the seller's store ID
  73. $nick = $ result['shop']['nick']; //Return the seller's nickname
  74. $title = $result['shop']['title']; //Return the seller's store title
  75. >
  76. ';>
  77. ';>
  78. ';>
Copy code


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