/**
  * 最基础用法,以测试taobao.products.search为例子
  * @link http://open.taobao.com/apidoc/api.htm?path=cid:4-apiId:5
  */
 public function testSend()
 {
     $response = $this->mockClient->send('taobao.products.search', array('q' => '爆款'));
     if (!$response->isOk()) {
         $this->fail("RESPONSE_HAS_ERROR. " . "ERROR INFO:" . $response->getError() . PHP_EOL . "RAW HTTP RETURN BODY:" . PHP_EOL . $response->getRawResult() . PHP_EOL);
     }
     $result = $response->getResult();
     $this->assertArrayHasKey('total_results', $result);
 }
<?php

use AlibabaSDK\Taobao\TaobaoClient;
use AlibabaSDK\TaobaoOAuth\TaobaoOAuthClient;
use AlibabaSDK\Aliyun\AliyunClient;
use AlibabaSDK\Integrate\FileRequestLogger;
if (!class_exists('AlibabaSDK\\Integrate\\ServiceLocator', false)) {
    exit('ACCESS DENIED');
}
$config = array();
$config['TaobaoClient'] = function ($locator) {
    $client = new TaobaoClient(array('appkey' => DEMO_TAOBAO_APPKEY, 'appsecret' => DEMO_TAOBAO_APPSECRET));
    /*
     * 如果需要记录日志,可参照以下代码,
     * 在使用了\AlibabaSDK\Base\CurlRequestTrait的类中:
     *     - 注入实现了\AlibabaSDK\Base\CurlRequestLoggerInterface接口类的实例
     *         (\AlibabaSDK\Integrate\FileRequestLogger为一个示例)
     * 传递的参数请参见方法\AlibabaSDK\Base\CurlRequestLoggerInterface::receiveSignalRequestLogger()
     */
    $client->setRequestLogger('fileLogger', $locator->getService('FileRequestLogger'));
    return $client;
};
$config['TaobaoOAuthClient'] = function ($locator) {
    $client = new TaobaoOAuthClient(array('appkey' => DEMO_TAOBAO_APPKEY, 'appsecret' => DEMO_TAOBAO_APPSECRET, 'redirect_uri' => ''));
    return $client;
};
/*
 *  \AlibabaSDK\Aliyun\AliyunClient中,可接收的regionId和gatewayUrl见以下连接:
 * @link https://github.com/aliyun/aliyun-openapi-php-sdk/blob/master/aliyun-php-sdk-core/Regions/EndpointConfig.php
 *
 * 注意,gatewayUrl请自行在前面增加https://
Exemplo n.º 3
0
<?php

use AlibabaSDK\Taobao\TaobaoClient;
use AlibabaSDK\Integrate\FileRequestLogger;
require __DIR__ . '/../CommonHeaderForDemoOnly.php';
$taobaoClient = new TaobaoClient(array('appkey' => DEMO_TAOBAO_APPKEY, 'appsecret' => DEMO_TAOBAO_APPSECRET, 'gatewayUrl' => 'https://eco.taobao.com/router/rest'));
/*
 * 如果需要记录日志,可参照以下代码,
 * 在使用了\AlibabaSDK\Base\CurlRequestTrait的类中:
 *     - 注入实现了\AlibabaSDK\Base\CurlRequestLoggerInterface接口类的实例
 *         (\AlibabaSDK\Integrate\FileRequestLogger为一个示例)
 * 传递的参数请参见方法\AlibabaSDK\Base\CurlRequestLoggerInterface::receiveSignalRequestLogger()
*/
$fileLogger = new FileRequestLogger(array('logDir' => DEMO_LOGDIR));
$taobaoClient->setRequestLogger('fileLogger', $fileLogger);
$response = $taobaoClient->send('alibaba.security.yundun.spam.validate', array('content' => '你好!'));
if (!$response->isOk()) {
    exit("API Error!:" . var_export($response->getError(true)));
}
$result = $response->getResult();
var_export($result);