/**
  * 最基础用法,以测试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);
 }
Example #2
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);