PHP code example of lecangs / open-api

1. Go to this page and download the library: Download lecangs/open-api 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/ */

    

lecangs / open-api example snippets


use Lecangs\OpenApi\Contracts\Config;
use Lecangs\OpenApi\System\Request\AppUnityRequest;
use Lecangs\OpenApi\Lecangs;
use Lecangs\OpenApi\Constants\ApiUri;

try {
    // 配置访问凭证
    $config = new Config();
    $config->setAccessKey('Your-AccessKey')
           ->setSecretKey('Your-SecretKey')
           ->setIsDev();  // 设置为开发环境,可根据需要调整

    // 请求体
    $body = [
        'pageNum' => '1',
    ];

    // 创建请求实例
    $request = new AppUnityRequest();
    $request->setMethod('post')
            ->setApiUri(ApiUri::INVENTORY_OVERVIEW)
            ->setBody($body);

    // 发起请求并获取响应
    $response = Lecangs::system($config)->appUnity($request);

    // 输出响应结果
    var_dump($response->getData());  // 返回的数据
    var_dump($response->getCode());  // 响应码
    var_dump($response->getMessage());  // 响应消息
} catch (\Exception $e) {
    // 处理异常
    var_dump($e->getMessage());
}

namespace Lecangs\OpenApi\Constants;

class ApiUri {
    const INVENTORY_OVERVIEW = '/oms/inventoryOverview/apiPage';  // 分页查询库存
    const TOC_ORDER_LIST = '/oms/omsTocOrder/listByOrderNos';     // 查询 2C 订单列表
    const CREATE_TOC_ORDER = '/oms/omsTocOrder/create';           // 创建 2C 订单
    const CANCEL_TOC_ORDER = '/oms/omsTocOrder/cancel';           // 取消 2C 订单
}