CodeIgniter and Taobao SDK integration


CodeIgniter and Taobao SDK integration

Google search, the original text has been unable to open, the snapshot see, added the next picture.

Recently, in the research of third-party software development of Taobao, CodeIgniter PHP (CI) framework and Taobao SDK (topsdk) are used. Today, I’ll tell you how CI integrates with top SDK!
intended for:
If you don’t know what CodeIgniter is now, it’s not recommended to read it
If you don’t know what Taobao SDK is now, we suggest you don’t read it.
Step 1: Download and unzip Taobao SDK

CodeIgniter and Taobao SDK integration

Step 2: create tmp folder in the extracted SDK

CodeIgniter and Taobao SDK integration

Step 3: copy all the files and folders in the above figure to CI, as shown below

CodeIgniter and Taobao SDK integration

In the red box are the five in the second step.
Step 4: configure Ci
Open CI portal file( index.php ), drag directly to the last few lines, one line of code is

require_once BASEPATH.'core/CodeIgniter.php';

Add the following code above this line

require_once APPPATH.'libraries/taobaosdk/TopSdk.php';

The overall code is as follows:

require_once APPPATH.'libraries/taobaosdk/TopSdk.php';
require_once BASEPATH.'core/CodeIgniter.php';

Here is a screenshot of the code

CodeIgniter and Taobao SDK integration

In this way, Taobao SDK is integrated into our Ci

CodeIgniter and Taobao SDK integration

Here’s how to call:
Load the request class file corresponding to the API you want to call in the controller, and load it in. For example, I want to call user.seller.get API then find usersellergetrequest, which is usually in the request folder added to the top file, and then use $this – > Load – > library(); to load your request class. Let’s look at the code.

public function __construct() {
        $this - > config - > Load ('taobao '); // load the Taobao configuration file
        $this - > Load - > Library ('session '); // load session
        $this->load->library (array ('taobaosdk/top/TopClient','taobaosdk/top/request/UserSellerGetRequest')); // load the relevant SDK of Taobao. Note that there are two loaded here, and the TopClient is required. No matter which API is called, this class needs to be added.
public function index() { 
        $user = $this - > session - > UserData ('user '); // get user data 
        //Declare Taobao SDK client 
        $c = new TopClient(); 
        $c->appkey = $this->config->item('client_ ID '); // set client_ ID 
        $c->secretKey = $this->config->item('client_ Secret '); // set client_ secret 
        $C - > format = $this - > config - > item ('format '); // set the return data format XML, JSON 
        $sessionkey = $this->session->userdata('user')->access_ Token; // get authorization token // declare API 
        $req = new UserSellerGetRequest(); 
        $req->setFields("nick,user_ ID, type "); // set the return field 
        $resp = $C - > execute ($req, $sessionkey); // execute API 
        var_ Dump ($RESP); // print the returned result.

The printing result is:

  public 'user' => 
      Public 'Nick' = > string 'ccysx2' (length = 6) // nickname, my Wangwang account,
      Public 'type' = > string 'C' (length = 1) // shop type C shop
      public 'user_ ID '= > int 823177574 // Account ID