topsdk4yii Taobao Open Platform SDK for Yii

  1. Requirements
  2. Usage

Taobao Open Platform SDK for Yii

Requirements

Yii 1.1 or above

Usage

  • Extract the extension in your application.extensions dir.
  • Add configuration in your component config:
'top'=>array(
    'class'=>'application.extensions.taobao.TopClient',
    'appkey'=>'YOUR APP KEY',
    'secretKey'=>'YOUR APP SECRET KEY',
    'format'=>'json',
),
  • Then you can use the TopClient in your app like this:
Yii::import('application.extensions.taobao.request.*');
$request = new ShopGetRequest();
$request->setNick($nickname);
$request->setFields('sid,cid,title,nick,desc,bulletin,pic_path,created,modified,shop_score');
$shop = Yii::app()->top->execute($request);

DO remember to import the request classes first.

  • To get taobao sessionKey, getAuthUrl() and getCallbackResponse() can handle it:
public function actionVerify()
{
    Yii::app()->user->returnUrl = $_SERVER['HTTP_REFERER'];
    Yii::app()->session['taobao_verify_uid'] = $_GET['nick'];
    $this->redirect(Yii::app()->top->getAuthUrl());
}

public function actionCallback()
{
    if (isset(Yii::app()->session['taobao_verify_uid'])) {
        $token = Yii::app()->top->getCallbackResponse($_GET);
        if ($token !== false) {
            if ($token['visitor_nick'] == Yii::app()->session['taobao_verify_uid']) {
                Yii::app()->session['taobao_session_key'] = $token['sessionKey'];
                Yii::app()->user->setFlash('verify_taobao_shop', '淘宝认证成功');
                $this->redirect(Yii::app()->user->returnUrl);
            } else {
                Yii::app()->user->setFlash('verify_taobao_shop', '淘宝认证失败');
                $this->redirect(Yii::app()->user->returnUrl);
            }
        } 
    }
}
  • When need to update the SDK, replace the files in application.extensions.taobao.request with the files ./top/request/* in the Official PHP SDK.
1 0
1 follower
733 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Tags: taobao, top
Developed by: Leric
Created on: Jan 17, 2011
Last updated: 7 years ago

Downloads

show all

Related Extensions