Skip to content

Commit

Permalink
Merge pull request #47 from icowan/master
Browse files Browse the repository at this point in the history
add 互联通系统
  • Loading branch information
icowan authored Apr 28, 2021
2 parents ab5c571 + a95bf11 commit 5adeb65
Show file tree
Hide file tree
Showing 5 changed files with 352 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Cross Border Express for Yii2
- 易仓物流
- 顺丰国际物流
- K5物流系统
- 燕文物流
- 互联通物流

[![Latest Stable Version](https://poser.pugx.org/yiier/yii2-cross-border-express/v/stable)](https://packagist.org/packages/yiier/yii2-cross-border-express)
[![Total Downloads](https://poser.pugx.org/yiier/yii2-cross-border-express/downloads)](https://packagist.org/packages/yiier/yii2-cross-border-express)
Expand Down Expand Up @@ -114,7 +116,21 @@ $config = [
"host" => "",
"clientid" => "",
"token" => "",
],
],
'yw56' => [
"host" => '',
"userId" => '',
"token" => '',
"ossBucket" => '',
"ossAccessKeyId" => '',
"ossAccessKeySecret" => '',
"ossLanDomain" => "oss-accelerate-internal.aliyuncs.com",
"ossWanDomain" => "oss-accelerate.aliyuncs.com",
],
'huiliantong' => [
'host' => "",
'userToken' => ''
]
],
];

Expand Down Expand Up @@ -231,3 +247,4 @@ $express->getOrderFee($orderNumber);
- [速递管家接口文档](http://lfn.rtb56.com/usercenter/manager/api_document.aspx)
- [易仓物流](http://ec.wiki.eccang.com/docs/show/2547)
- [顺丰国际物流](http://docs.uat.trackmeeasy.com/api/)
- [互联通物流系统](http://8.129.12.42:8086/xms/download/api/HLT-XMS-API.docx)
257 changes: 257 additions & 0 deletions src/platforms/HuliantongPlatform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
<?php


namespace yiier\crossBorderExpress\platforms;


use GuzzleHttp\Client;
use nusoap_client;
use yiier\crossBorderExpress\contracts\Order;
use yiier\crossBorderExpress\contracts\OrderFee;
use yiier\crossBorderExpress\contracts\OrderResult;
use yiier\crossBorderExpress\contracts\Transport;
use yiier\crossBorderExpress\CountryCodes;
use yiier\crossBorderExpress\exceptions\ExpressException;

class HuliantongPlatform extends Platform
{
/**
* @var string
*/
private $endpoint = "";

/**
* @var string
*/
private $userToken = "";

/**
* @var Client
*/
private $httpClient;

/**
* @inheritDoc
*/
public function getClient()
{
$this->endpoint = $this->config->get("host") ?: $this->endpoint;
$client = new nusoap_client($this->endpoint . "/xms/services/order?wsdl", true);
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$this->userToken = $this->config->get("userToken");

return $client;
}

/**
* @inheritDoc
*/
public function getTransportsByCountryCode(string $countryCode)
{
// TODO: Implement getTransportsByCountryCode() method.
}

/**
* @param Order $order
* @return OrderResult
* @throws ExpressException
*/
public function createOrder(Order $order): OrderResult
{
$orderResult = new OrderResult();
$parameter = $this->formatOrder($order);
$result = $this->client->call('createAndAuditOrder', [
'createOrderRequest' => $parameter,
"userToken" => $this->userToken,
]);
if (isset($result["success"])) {
if (strtoupper($result["success"]) == "TRUE") {
$trackingNo = "";
if (!empty($result["trackingNo"])) {
$trackingNo = $result['trackingNo'];
}
if (!empty($result["id"])) {
$orderResult->expressNumber = $result['id'];
}
$orderResult->expressTrackingNumber = $trackingNo;
} else {
$error = $result["error"];
$msg = !empty($error['errorCode']) ? $error["errorCode"] . ":" : "";
$msg .= !empty($error['errorInfo']) ? $error["errorInfo"] . ":" : "";
$msg .= !empty($error['solution']) ? $error["solution"] : "";
throw new ExpressException($msg);
}
} else {
throw new ExpressException('订单提交返回失败' . json_encode($result, true), (array)$result);
}
$orderResult->data = json_encode($result, JSON_UNESCAPED_UNICODE);

return $orderResult;
}

/**
* @param string $orderNumber
* @param array $params
* @return string
* @throws ExpressException
*/
public function getPrintUrl(string $orderNumber, array $params = []): string
{
$orderKey = "oid"; // 跟踪单号(trackingNo),订单编号(orderId),客户单号(orderNo)
// 纸张尺寸,
//“1”表示80.5mm × 90mm
//“2”表示105mm × 210mm
//“3”表示A4
//“7”表示100mm × 150mm
//“4”表示102mm × 76mm
//“5”表示110mm × 85mm
//“6”表示100mm × 100mm
//选择打印样式
//1 地址标签打印
//11 报关单
//2 地址标签+配货信息
//3 地址标签+报关单
//12 特殊100mm×100mm地址标签+配货信息+报关单
// return sprintf("%s/xms/client/order_online!printPdf.action?userToken=%s&%s=%s&printSelect=%d&pageSizeCode=%d&showCnoBarcode=%d",
// $this->endpoint, $this->userToken, $orderKey, $orderNumber, 1, 3, 0);
$result = $this->client->call("printOrder", [
'printOrderRequest' => [
"oid" => $orderNumber,
"printSelect" => 3,
"pageSizeCode" => 6,
"showCnoBarcode" => 0,
"downloadPdf" => 0,
"showRecycleTags" => 0
],
"userToken" => $this->userToken,
]);

if (empty($result)) {
throw new ExpressException("网经错误");
}
if (isset($result["success"]) && strtoupper($result["success"]) == "TRUE") {
return $result["url"];
}
throw new ExpressException(sprintf("%s: %s : %s", $result["errorCode"], $result["errorInfo"], $result["solution"]));
}

/**
* @param string $orderNumber
* @return OrderFee
* @throws ExpressException
*/
public function getOrderFee(string $orderNumber): OrderFee
{

$orderFee = new OrderFee();

$key = "orderId";

$result = $this->client->call('lookupOrder', [
"userToken" => $this->userToken,
"lookupOrderRequest" => [
$key => $orderNumber,
]
]);
if (empty($result["success"])) {
throw new ExpressException('订单提交返回失败', (array)$result);
}
if (strtoupper($result["success"]) != "TRUE") {
$error = $result["error"];
$msg = "orderId:{$orderNumber}:";
$msg .= !empty($error['errorCode']) ? $error["errorCode"] . ":" : "";
$msg .= !empty($error['errorInfo']) ? $error["errorInfo"] . ":" : "";
$msg .= !empty($error['solution']) ? $error["solution"] : "";
throw new ExpressException($msg);
}

if (empty($result["order"])) {
return $orderFee;
}

$order = $result["order"];

$orderFee->orderNumber = !empty($order["trackingNo"]) ? $order["trackingNo"] : "";
$orderFee->chargeWeight = $order["balanceWeight"] > 0 ? $order["balanceWeight"] * 1000 : 0; // realWeight 实际重(kg)。 realVolWeight 体积重(kg)。balanceWeight 结算重(kg)。
$orderFee->freight = !empty($order["transportFee"]) ? $order["transportFee"] * 100 : 0;
$orderFee->totalFee = !empty($order["totalFee"]) ? $order["totalFee"] * 100 : 0;
$orderFee->otherFee = !empty($order["otherFee"]) ? $order["otherFee"] * 100 : 0;
$orderFee->customerOrderNumber = !empty($order["orderNo"]) ? $order["orderNo"] : "";
$orderFee->country = $order["currency"];
$orderFee->transportCode = !empty($order["transportWayCode"]) ? $order["transportWayCode"] : "";
$orderFee->transportName = !empty($order["transportWayName"]) ? $order["transportWayName"] : "";
$orderFee->datetime = !empty($order["createTime"]) ? $order["createTime"] : ""; //2019-03-02T18:26:25
$orderFee->data = json_encode($result["order"], JSON_UNESCAPED_UNICODE);

return $orderFee;
}

/**
* @param array $query
* @return array
*/
public function getOrderAllFee(array $query = []): array
{
return [];
}

/**
* 格式化所需要的数据
*
* @param Order $orderClass
* @return array
*/
protected function formatOrder(Order $orderClass): array
{
// 收件人
$declareItems = [];
foreach ($orderClass->goods as $good) {
$declareItems[] = [
'name' => $good->description,
'cnName' => $good->cnDescription,
'pieces' => $good->quantity,
'netWeight' => $good->weight,
'unitPrice' => $good->worth,
'customsNo' => $good->hsCode,
];
}

return [
'orderNo' => $orderClass->customerOrderNo,
'transportWayCode' => $orderClass->transportCode,
'cargoCode' => 'W',
'originCountryCode' => $orderClass->shipper->countryCode,
'destinationCountryCode' => $orderClass->recipient->countryCode,
'pieces' => $orderClass->package->quantity,
'length' => $orderClass->package->length,
'width' => $orderClass->package->height,
'height' => $orderClass->package->height,
'weight' => $orderClass->package->weight,
"shipperCompanyName" => $orderClass->shipper->company,
"shipperName" => $orderClass->shipper->name,
"shipperAddress" => $orderClass->shipper->address,
"shipperTelephone" => $orderClass->shipper->phone,
"shipperMobile" => $orderClass->shipper->phone,
"shipperPostcode" => $orderClass->shipper->zip,
"shipperCity" => $orderClass->shipper->city,
"shipperProvince" => $orderClass->shipper->state,
"shipperStreet" => $orderClass->shipper->address,
"shipperStreetNo" => "",
'consigneeCompanyName' => $orderClass->recipient->company,
'consigneeName' => $orderClass->recipient->name,
'consigneeStreetNo' => "",
'street' => $orderClass->recipient->address,
'city' => $orderClass->recipient->city,
'province' => $orderClass->recipient->state,
'consigneePostcode' => $orderClass->recipient->zip,
'consigneeTelephone' => $orderClass->recipient->phone,
'consigneeMobile' => $orderClass->recipient->phone,
'trackingNo' => $orderClass->customerOrderNo,
'insured' => $orderClass->evaluate > 0 ? "Y" : 'N',
'goodsCategory' => 'O',
'goodsDescription' => $orderClass->package->description,
'declareItems' => $declareItems
];
}
}
1 change: 1 addition & 0 deletions src/platforms/PlatformsName.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class PlatformsName
const SFEXPRESS_PLATFORM = "sfexpress";
const K5_PLATFORM = "k5";
const YW56_PLATFORM = "yw56";
const HULIANTONG_PLATFORM = "huliantong";
}
65 changes: 65 additions & 0 deletions src/platforms/Rtb65Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php


namespace yiier\crossBorderExpress\platforms;


use GuzzleHttp\Client;
use nusoap_client;
use yiier\crossBorderExpress\contracts\Order;
use yiier\crossBorderExpress\contracts\OrderFee;
use yiier\crossBorderExpress\contracts\OrderResult;
use yiier\crossBorderExpress\contracts\Transport;
use yiier\crossBorderExpress\exceptions\ExpressException;

class Rtb65Platform extends Platform
{

/**
* @inheritDoc
*/
public function getClient()
{
// TODO: Implement getClient() method.
}

/**
* @inheritDoc
*/
public function getTransportsByCountryCode(string $countryCode)
{
// TODO: Implement getTransportsByCountryCode() method.
}

/**
* @inheritDoc
*/
public function createOrder(Order $order): OrderResult
{
// TODO: Implement createOrder() method.
}

/**
* @inheritDoc
*/
public function getPrintUrl(string $orderNumber, array $params = []): string
{
// TODO: Implement getPrintUrl() method.
}

/**
* @inheritDoc
*/
public function getOrderFee(string $orderNumber): OrderFee
{
// TODO: Implement getOrderFee() method.
}

/**
* @inheritDoc
*/
public function getOrderAllFee(array $query = []): array
{
// TODO: Implement getOrderAllFee() method.
}
}
11 changes: 11 additions & 0 deletions tests/platforms/HuliantongPlatformTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace platforms;

use yiier\crossBorderExpress\platforms\HuliantongPlatform;
use PHPUnit\Framework\TestCase;

class HuliantongPlatformTest extends TestCase
{

}

0 comments on commit 5adeb65

Please sign in to comment.