PHP code example of yiier / yii2-cross-border-express

1. Go to this page and download the library: Download yiier/yii2-cross-border-express 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/ */

    

yiier / yii2-cross-border-express example snippets




$config = [
    // HTTP 请求的超时时间(秒)
    'timeout' => 5.0,

    // 可用的平台配置
    'platforms' => [
       'santai' => [
            'appKey' => 'xxx',
            'token' => 'xxx',
            'userId' => 'xxx'
        ],
        'yuntu' => [
            'account' => 'xxx',
            'secret' => 'xxx',
        ],
        'feite' => [
            'token' => 'xxx',
            'syncPlatformId' => '', // 订单同步平台标识(一般指第三方平台标识,格式类似:scb.logistics.flyt)
            'accountId' => 'xxx',
            'password' => '',
            'printUsername' => '', // 面单接口需要
            'printPassword' => '' // 面单接口需要
        ],
        'hualei' => [
            'host' => '',
            'print_host' => '',
            'customer_id' => '', # 如果customer_id和customer_user_id不为空可不填username及password
            'customer_user_id' => '',
            'username' => '',
            'password' => '',
        ],
        'jiyou' => [
            'host' => '',
            'user_token' => ''
        ],
        'wanb' => [
            "host" => "http://api-sbx.wanbexpress.com",
            "account_no" => "",
            "token" => "",
            "warehouse_code" => "",
            "oss_wan_domain" => "oss-cn-beijing.aliyuncs.com",
            "oss_lan_domain" => "oss-cn-beijing-internal.aliyuncs.com",
            "oss_bucket" => "",
            "oss_access_key_id" => "",
            "oss_access_key_secret" => "",
        ],
        'courierbutler' => [
            "host" => "http://lfn.rtb56.com",
            "app_token" => "",
            "app_key" => "",
        ],
        'eccang' => [
            "appKey" => "",
            "appToken" => "",
            "host" => ""
        ],
        'sfexpress' => [
            "accesscode" => "",
            "username" => "",
            "checkword" => "",
            "platform_code" => "",
        ], 
		'k5' => [
            "host" => "",
            "clientid" => "",
            "token" => "",
        ],
        'yw56' => [
            "host" => '',
            "userId" => '',
            "token" => '',
            "ossBucket" => '',
            "ossAccessKeyId" => '',
            "ossAccessKeySecret" => '',
            "ossLanDomain" => "oss-accelerate-internal.aliyuncs.com",
            "ossWanDomain" => "oss-accelerate.aliyuncs.com",
        ],
        'huiliantong' => [
            'host' => "",
            'userToken' => ''
        ]
    ],
];

$express = new \yiier\crossBorderExpress\Express($config, 'santai');
    


$expressOrder = new \yiier\crossBorderExpress\contracts\Order();
$expressOrder->customerOrderNo = 'xxx';
$expressOrder->transportCode = 'xxx';

$goods[] = new \yiier\crossBorderExpress\contracts\Goods();
$goods->description = 'xxx';
$goods->cnDescription = 'xxx';
$goods->quantity = 'xxx';
$goods->weight = 'xxx';
$goods->hsCode = 'xxx';
$goods->enMaterial = 'cotton';
$goods->cnMaterial = '棉';
$goods->worth = 1; // 1美元;
$goods->sku = 'xxx'; // 云途某些渠道需要
        
$expressOrder->goods = $goods;
$expressOrder->evaluate = 1; // 1美元
$expressOrder->taxesNumber = 'xxx'; // 税号
$expressOrder->isRemoteConfirm = 1; // 是否同意收偏远费
$expressOrder->isReturn = 1; // 是否退件
$expressOrder->withBattery = 0; // 是否带电池

$package = new \yiier\crossBorderExpress\contracts\Package();
$package->description = 'xxxx';
$package->quantity = 1;
$package->weight = 'xxx';
$package->declareWorth = 1; // 1美元
$expressOrder->package = $package;


$recipient = new \yiier\crossBorderExpress\contracts\Recipient();
$recipient->countryCode = 'xx';
$recipient->name = 'xx';
$recipient->address = 'xx';
$recipient->city = 'xx';
$recipient->state = 'xx';
$recipient->zip = 'xx';
$recipient->phone = 'xx';
$expressOrder->recipient = $recipient;

$shipper = new \yiier\crossBorderExpress\contracts\Shipper();
$shipper->countryCode = 'CN';
$shipper->name = 'xxx';
$shipper->company = 'xxx';
$shipper->address = 'xxx';
$shipper->city = 'xxx';
$shipper->state = 'xxx';
$shipper->zip = 'xx';
$shipper->phone = 'xxx';
$expressOrder->shipper = $shipper;
    
// 发货
$express->createOrder($expressOrder);


$countryCode = 'US';
$item = [];
if (!empty($transports = $express->getTransportsByCountryCode($countryCode))) {
    foreach ($transports as $transport) {
        // 带跟踪号的物流方式
        $item[$transport->code] = [
            'code' => $transport->code,
            'name' => $transport->cnName,
            'is_tracking_no' => (int)$transport->ifTracking,
            'data' => $transport->data,
        ];
    }
}
return $item;


$orderNumber = 'xxx';
$express->getPrintUrl($orderNumber);


$orderNumber = 'xxx';
$express->getOrderFee($orderNumber);

php composer.phar