PHP code example of is4ngle / alibaba-open-sdk

1. Go to this page and download the library: Download is4ngle/alibaba-open-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

is4ngle / alibaba-open-sdk example snippets


use Is4ngle\AlibabaOpen\Client;
use Is4ngle\AlibabaOpen\Config\Credentials;
use Is4ngle\AlibabaOpen\Api\Fenxiao\ProductKeywordsSearchRequest;

$client = new Client(new Credentials($appKey, $appSecret, $accessToken));

// 方式一:Request 对象(推荐,参数有类型和注释提示)
$req = new ProductKeywordsSearchRequest();
$req->keywords = '保温杯';
$req->pageNum = 1;
$req->pageSize = 20;
$req->filter = ['fxBrandOffer'];           // 分销品牌黑标

$resp = $client->execute($req);
if ($resp->isSuccess()) {
    $offers = $resp->result();             // 商品数组(含代发价/阶梯价/包邮/星级)
} else {
    $resp->getErrorCode();                 // 业务错误
    $resp->getRaw();                       // 原始响应兜底
}

// 方式二:通用直调(未封装/调试)
$resp = $client->call('com.alibaba.trade', 'alibaba.trade.getBuyerOrderList', 1, ['page' => 1]);
bash
php bin/generate.php /path/to/官方SDK目录    # 必传:open.1688.com SDK 生成器下载的官方包根目录
php bin/generate.php /path/to/官方SDK目录 --dry-run    # 只看清单