Home php教程 PHP源码 简单实现淘宝API调用

简单实现淘宝API调用

May 25, 2016 pm 05:03 PM

简单实现淘宝API调用

简单实现了淘宝API的调用的类,暂时没有考虑session,可以参照淘宝api实现各种功能,比如获取宝贝详情、图片链接等。欢迎提建议

<?php
 
class TaobaoApi {
    /*
     * 定义并初始化参数数组,某些固定参数可写在这个位置
     */
 
    protected $_param = array(&#39;app_key&#39; => &#39;21572060&#39;, &#39;v&#39; => &#39;2.0&#39;,
        &#39;sign_method&#39; => &#39;md5&#39;, &#39;format&#39; => &#39;xml&#39;);
    /*
     * Sign值存储变量
     */
    protected $_sign;
    /*
     * 应用密码存储变量
     */
    public $secret = &#39;your secret&#39;;
    /*
     * 请求URL存储变量
     */
    protected $_url;
 
    public function run() {
        $this->createSign();
        $this->createRequestUrl();
        return $this->requestData();
    }
 
    /*
     * 通过魔法赋值向参数数组写入数据
     * @param string $name 数组名
     * @param string $value 数组键值
     */
 
    public function __set($name, $value) {
        $this->_param[$name] = $value;
    }
 
    /*
     * 组建Sign
     * @global $this->_param 参数数组
     * @global $this->secret 应用密钥
     */
 
    protected function createSign() {
        $this->_param[&#39;timestamp&#39;] = date(&#39;Y-m-d H:i:s&#39;);
        ksort($this->_param, SORT_STRING); //数组按键值排序
        $tmp = &#39;&#39;;
        foreach ($this->_param as $key => $value) {
            $tmp.= $key . $value;
        }
        $this->_sign = strtoupper(md5($this->secret . $tmp . $this->secret));
    }
 
    /*
     * 由参数和Sign值组合成请求URL
     * @global $this->_param
     * @global $this->url
     */
 
    protected function createRequestUrl() {
        $this->_param[&#39;timestamp&#39;] = urlencode($this->_param[&#39;timestamp&#39;]);
        $this->_url = &#39;http://gw.api.taobao.com/router/rest?sign=&#39; . $this->_sign;
        foreach ($this->_param as $key => $value) {
            $this->_url.=&#39;&&#39; . $key . &#39;=&#39; . $value;
        }
    }
 
    /*
     * 获取数据
     */
 
    protected function requestData() {
        return file_get_contents($this->_url);
    }
 
}
 
$a = new TaobaoApi();
//下面只要写入淘宝API规定必须传入的参数
$a->method = &#39;taobao.item.get&#39;;
$a->fields = &#39;desc,nick&#39;;
$a->app_key = &#39;your key&#39;;
$a->secret = &#39;your secret&#39;;
$a->num_iid = 16096610668;
//默认以xml方式输出
echo $a->run();
?>
Copy after login

                   

以上就是简单实现淘宝API调用的内容,更多相关内容请关注PHP中文网(www.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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check where Taobao's shipping address is? How to check the shipping address of orders placed on Taobao app How to check where Taobao's shipping address is? How to check the shipping address of orders placed on Taobao app Mar 12, 2024 pm 04:00 PM

The Taobao app can satisfy all your shopping problems. There are so many merchants and so many products waiting for you to choose. No matter what kind of products you want to buy, you can search and find them here. , allowing everyone to directly place orders and purchase, and all functions can be freely operated. When you place an order successfully, you only need to wait for the merchant to ship the goods and carry out logistics delivery. It is very convenient and many , everyone can choose to view the shipping locations of these products and know where their products are shipped. Especially when you purchase some electronic products, you can check some related shipping locations. information to avoid the problem of buying some refurbished machines.

How to turn off password-free payment on Taobao. How to cancel the setting method of password-free payment. How to turn off password-free payment on Taobao. How to cancel the setting method of password-free payment. Mar 12, 2024 pm 12:07 PM

There are so many functions on Taobao APP. These functions exist so that everyone can get a better shopping experience. The large number of product types can well meet the shopping needs of different users. Everyone really wants to You can buy whatever you want. You can search by category or directly search for these products. There will be no problem. Everyone can shop online with confidence. We will provide you with value-for-money shopping services. It will definitely give you Everything you want. Of course, if you shop here, you will find a variety of shopping methods here that allow you to choose. Some people like the password-free payment function here, and some do not. I like it so much, but I think the security is not that high. Of course, everyone can cancel at any time.

How to get Taobao free red envelope 2024 How to get Taobao free red envelope 2024 May 09, 2024 pm 03:22 PM

The 2024 Taobao free order event will be held three times a day. Everyone needs to place an order and pay for the corresponding amount of goods at the corresponding time. The free order amount will be distributed in the form of red envelopes of equal amounts. Next, we will bring you how to receive the Taobao free order red envelope in 2024: grab it For users who are free of charge, the red envelope qualification will be issued to the card and coupon package, which is in a state of activation; the web version of Taobao currently does not have the card and coupon package, and only displays the winning records of the free order event; the card and coupon package is in [Taobao APP-My Taobao] -My Rights-Red Envelope]. How to get red envelopes for free orders on Taobao 20241. For users who grab free orders, the red envelope qualifications will be distributed to the card and coupon packages, which are in a state of waiting for activation; 2. The web version of Taobao currently does not have card and coupon packages, and only displays the winning records of the free order activities. ;3. The card coupon package is in [Taobao APP-My Taobao-My Rights-Red Envelope]

Taobao store registration process Taobao store registration process Mar 25, 2024 pm 01:37 PM

1. Open the Taobao app, click [My Taobao] in the lower right corner, and click [Settings] in the upper right corner. 2. Select [Merchant Settlement], click [Open Taobao Store], and select [General Merchant]. 3. In the [Free Store Opening] interface, users can see the specific process of opening a [Personal Merchant] store. 4. Name your store, then click [Open a store], check all three items, and click [Open a store for 0 yuan]. 5. Finally complete [Real Person Authentication] and complete [Basic Store Information] to successfully open a store.

How to check the total consumption amount on Taobao How to check the total consumption amount How to check the total consumption amount on Taobao How to check the total consumption amount Mar 12, 2024 pm 03:07 PM

If we usually need to do online shopping, we will all choose Taobao as a platform, which can fully meet all our shopping needs. It has a lot of resources for various commodities, and there are really all kinds of commodities. It is gathered on this platform. Everyone has found that there are many categories of products here, and you can choose them according to your own needs. You can buy whatever you want, so everyone will definitely buy it here. There are a lot of products, and the prices of these products are very different. All these shopping records can be saved, which can be convenient for everyone to check at any time. So if you know what you are shopping here, what exactly is it? How much money did you spend? You must be very curious. Below I will tell you

How to change name on Taobao How to change name on Taobao Mar 24, 2024 pm 03:31 PM

The name change function allows users to freely change their names and nicknames in Taobao. Some users do not know how to change their names on Taobao. Just click on the Taobao account of the avatar in the settings in My Taobao to modify it. Next, the editor will bring it to you This is an introduction to how to change your name and nickname. If you don’t know yet, please download it and give it a try. Taobao usage tutorial How to change Taobao name Answer: Click on the Taobao account of the avatar in the settings in My Taobao to modify it. Details: 1. Enter Taobao and click [My Taobao] on the lower right. 2. Click the [Settings] icon on the upper right. 3. Click the avatar. 4. Click [Taobao Account] again. 5. Click [Modify Account Name], enter and modify it.

How to turn off red envelope reminder on Taobao How to turn off red envelope reminder on Taobao Apr 01, 2024 pm 06:25 PM

Taobao is a commonly used online shopping software for many friends. You usually place orders and purchase many things from Taobao. It provides users with a red envelope reminder function. Some friends want to turn it off, so hurry up and check out the PHP Chinese website. Take a look. List of steps to turn off red envelope reminders on Taobao 1. Open the personal center of Taobao APP and select the [Settings] button to enter the page. 2. Find the [Message Notification] option. Here you can select the message push switch. Find the red envelope message and turn off the switch. 3. Or you can turn off the notification permission of Taobao APP through the settings page of your mobile phone, so that all messages from Taobao will not enter the push and can only be seen after turning it on. 4. Users can set what types of messages they want to receive, which makes it easier to use.

How to use 'Taobao' 510 free red envelope How to use 'Taobao' 510 free red envelope May 08, 2024 pm 10:00 PM

How to use Taobao 510 free red envelope? Taobao recently launched a free order event to celebrate its 510th anniversary. This event allows you to get free order red envelopes, and there are many benefits. I believe many friends want to participate in this event. Some friends have already received free order red envelopes, but they are not. If you know the specific usage, let’s take a look at the relevant introduction today. Instructions for using Taobao’s 510th Anniversary Free Order Red Packet: The free order red pack can be used after all orders placed for guessing questions have been confirmed and received. 1. Users can issue and recover free red envelopes through the web version of Taobao. Currently, there is no card and coupon package, but it can be viewed at [Taobao APP-My Taobao-My Rights-Red Envelopes]. For users who grab the free order, the red envelope qualification will be distributed to the card and coupon package, which is in a state of activation; the card and coupon package is in progress for winning prizes.

See all articles