Skip to content

创建订单

接口说明

提交单个包裹下单。成功后返回 WMG 分配的运单号。

请求信息

  • 方法:POST
  • 路径/openapi/order/create-order
  • 认证方式:标准 OpenAPI token(基于 MD5)

请求头

字段说明
Content-Typeapplication/json
x-auth-name$API_NAME
x-auth-seed$SEED(13 位毫秒级 UNIX 时间戳)
x-auth-token$TOKEN(MD5 哈希)

请求参数

请求体为 JSON 格式。下表按代码中的校验规则整理。

字段名与取值保持英文

字段名与所有取值(如 A/BY/NDDU/DDP)都是接口实际使用的字面量,请勿翻译或改写大小写。

请求体为 JSON 格式,包含以下字段:

参数类型必填说明
custom_tracking_numstring你的内部订单号。只允许字母、数字、-_;最长 32 个字符
recipient_namestring收件人全名;最长 64 个字符
recipient_countrystring收件国家代码,ISO 3166-1 alpha-2(大写,2 位)
recipient_phonestring收件人电话,仅限数字;最长 24 个字符
recipient_addressstring收件详细地址;最长 512 个字符
sender_countrystring寄件国家代码,ISO 3166-1 alpha-2(大写,2 位)
client_sizestring包裹尺寸,格式 长,宽,高(厘米),三个逗号分隔的非负数,如 30,20,10;最长 30 个字符
client_weightfloat包裹重量(范围 0–9999);单位跟随账户配置
declared_valuefloat申报价值;范围 0–9999.99
declared_value_currencystring申报价值币种,ISO 4217 三位字母代码
itemarray商品对象数组 —— 见下方 item[]
postal_codestring条件必填收件人邮编。HK 外的所有目的地均必填。校验前会先剔除非数字字符,再按目的地校验长度(SG = 5–6 位,MY = 4–5 位,KR = 4–5 位,JP = 5–7 位,其他目的地 3–10 位)
recipient_statestring条件必填收件人州/省。仅当 recipient_country = US 时必填;最长 60 个字符
recipient_citystring收件城市;最长 64 个字符
recipient_emailstring收件人邮箱;最长 320 个字符
sender_namestring条件必填寄件人全名。揽件类 service_type 下必填;最长 64 个字符
sender_phonestring条件必填寄件人电话,仅限数字,最长 24 个字符。揽件类 service_type 下必填
sender_addressstring条件必填寄件详细地址,最长 512 个字符。揽件类 service_type 下必填
sender_postal_codestring条件必填寄件人邮编(3–10 位)。揽件类 service_type 下sender_country = HK 外均必填;非揽件类为选填
sender_citystring寄件城市;最长 64 个字符
sender_emailstring寄件人邮箱;最长 320 个字符
service_typestring服务类型代码,3 位。请使用 WMG 为你的账户分配的代码;不传时按纯尾程处理。揽件类服务类型还需一并提供 sender_* 字段
service_codestring承运路由服务代码,3 位。recipient_country = US 时必传且必须是有效代码;SG 时可不传,传了必须有效;其他目的地会被忽略。账户可用的代码请向 WMG 索取
instructionstring派送备注;最长 1024 个字符
cashfloat货到付款金额;0–9999.99;需与 cash_currency 同时提供
cash_currencystring货到付款币种,ISO 4217 三位字母代码;recipient_country = SG 时必须为 SGD;需与 cash 同时提供
supplier_namestring供应商名称;最长 64 个字符
supplier_gstnstring供应商 GST 税号;最长 64 个字符
total_gst_amountfloatGST 总额;0–9999.99
gst_currencystringGST 币种,ISO 4217 三位字母代码
gst_paidstringYN
incoterm_typestring贸易术语:DDUDDP
locker_typestring智能柜处理方式。A = 地址本身已是智能柜地址;B = 普通地址,需转换为最近的智能柜。只接受 AB
locker_stationobject条件必填locker_typeA 时必填。见下方 locker_station

item[] 的每个元素必须包含:

参数类型必填说明
descriptionstring商品描述;最长 255 个字符
unitPricefloat单价;≥ 0
quantitynumber数量;≥ 0
weightfloat商品重量;≥ 0
currencystring币种,ISO 4217 三位字母代码
totalValuefloat商品总价;≥ 0
countryOfOriginstring原产国代码,ISO 3166-1 alpha-2(2 位)
itemHSCodestring海关 HS 编码;最长 255 个字符
productURLstring商品页面 URL;最长 500 个字符

locker_station

参数类型必填说明长度
zipcodestring智能柜邮编≤ 16 个字符
station_namestring网点名称≤ 64 个字符
station_addressstring网点地址≤ 255 个字符
address_detailstring地址补充说明≤ 255 个字符
distancefloat距离
station_codestring网点代码≤ 10 个字符

请求体示例

json
{
  "custom_tracking_num": "ORDER-20260501-001",
  "recipient_name": "Jane Smith",
  "recipient_country": "SG",
  "recipient_phone": "6591234567",
  "recipient_address": "123 Orchard Road",
  "recipient_city": "Singapore",
  "recipient_email": "jane@example.com",
  "postal_code": "238858",
  "sender_country": "SG",
  "client_size": "30,20,10",
  "client_weight": 1.5,
  "declared_value": 99.99,
  "declared_value_currency": "SGD",
  "item": [
    {
      "description": "Electronics",
      "itemHSCode": "8471300000",
      "quantity": 1,
      "unitPrice": 99.99,
      "weight": 1.5,
      "currency": "SGD",
      "totalValue": 99.99
    }
  ]
}

Token 生成说明

token 只由凭证和 seed 计算得出 —— 请求参数不参与

seed  = "1746700000000"   (13 位毫秒时间戳)
token = md5( strtolower(api_name) + api_key + seed )

认证

本接口使用标准 OpenAPI 认证(MD5 token)。

完整的认证说明与多语言示例见认证与签名

响应信息

响应为 JSON 格式。

响应结构

字段类型说明
codeinteger结果码。0 = 成功,1 = 失败
messagestring结果描述
dataobject下单结果

成功响应

  • HTTP 状态码:200
json
{
  "code": 0,
  "message": "success",
  "data": {
    "custom_tracking_num": "C240719112805334a634B",
    "wmg_tracking_num": "WGC000000000233",
    "date_time": "2024-07-19T13:34:26+08:00",
    "status": "",
    "error": []
  }
}
字段类型说明
data.custom_tracking_numstring回显你传入的内部订单号
data.wmg_tracking_numstringWMG 分配的运单号
data.date_timestring下单时间(ISO 8601,UTC+8)
data.statusstring下单状态
data.errorarray单条错误信息,无错误时为空数组

失败响应

  • HTTP 状态码:200(业务错误)或 4xx/5xx(系统错误)
json
{
  "code": 1,
  "message": "Client Size invalid",
  "data": []
}

常见错误:

  • 认证失败 → code 1;具体 message 取决于失败原因(如 x-auth-token: INVALIDx-auth-seed: TIMEOUT)—— 见认证与签名
  • 字段缺失或不合法 → code 1,返回字段校验消息(如 client_weight requirerecipient_country invalid
  • 内部单号重复 → code 1,message 为 custom_tracking_num (XXX) already exist(注意 exist 没有 s)
  • 服务代码无效 → code 1,message 为 Service code invalid(US)或 Service code (XXX) invalid(SG)
  • 目的国不支持 → code 1,message 为 recipient_country(XX) not allow
  • 商品明细校验失败 → code 1,message 为 Item <row> <field> <reason>(如 Item 1 unitPrice require

结果码

Code说明
0成功
1失败

调用示例

Bash

bash
API_NAME="your_api_name"
API_KEY="your_api_key"
SEED=$(date +%s%3N)
TOKEN=$(printf '%s' "$(echo -n "$API_NAME" | tr '[:upper:]' '[:lower:]')${API_KEY}${SEED}" | md5sum | cut -d' ' -f1)

curl -X POST "https://api.test.wmgdelivery.com/v1/openapi/order/create-order" \
  -H "Content-Type: application/json" \
  -H "x-auth-name: $API_NAME" \
  -H "x-auth-seed: $SEED" \
  -H "x-auth-token: $TOKEN" \
  -d '{
    "custom_tracking_num": "ORDER-20260501-001",
    "recipient_name": "Jane Smith",
    "recipient_country": "SG",
    "recipient_phone": "6591234567",
    "recipient_address": "123 Orchard Road",
    "recipient_city": "Singapore",
    "recipient_email": "jane@example.com",
    "postal_code": "238858",
    "sender_country": "SG",
    "client_size": "30,20,10",
    "client_weight": 1.5,
    "declared_value": 99.99,
    "declared_value_currency": "SGD",
    "item": [{"description": "Electronics", "itemHSCode": "8471300000", "quantity": 1, "unitPrice": 99.99, "weight": 1.5, "currency": "SGD", "totalValue": 99.99}]
  }'

Windows PowerShell

powershell
$API_NAME = "your_api_name"
$API_KEY  = "your_api_key"
$SEED     = [string]([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())

$raw   = [System.Text.Encoding]::UTF8.GetBytes($API_NAME.ToLower() + $API_KEY + $SEED)
$md5   = [System.Security.Cryptography.MD5]::Create().ComputeHash($raw)
$TOKEN = -join ($md5 | ForEach-Object { $_.ToString("x2") })

$body = [ordered]@{
    custom_tracking_num     = "ORDER-20260501-001"
    recipient_name          = "Jane Smith"
    recipient_country       = "SG"
    recipient_phone         = "6591234567"
    recipient_address       = "123 Orchard Road"
    recipient_city          = "Singapore"
    recipient_email         = "jane@example.com"
    postal_code             = "238858"
    sender_country          = "SG"
    client_size             = "30,20,10"
    client_weight           = 1.5
    declared_value          = 99.99
    declared_value_currency = "SGD"
    item                    = @(@{ description = "Electronics"; itemHSCode = "8471300000"; quantity = 1; unitPrice = 99.99; weight = 1.5; currency = "SGD"; totalValue = 99.99 })
} | ConvertTo-Json -Depth 5 -Compress

$headers = @{
    "Content-Type" = "application/json"
    "x-auth-name"  = $API_NAME
    "x-auth-seed"  = $SEED
    "x-auth-token" = $TOKEN
}

$response = Invoke-RestMethod `
    -Uri "https://api.test.wmgdelivery.com/v1/openapi/order/create-order" `
    -Method Post -Headers $headers -Body $body
$response | ConvertTo-Json -Depth 10

Python

python
import hashlib, time
import requests

API_NAME = 'your_api_name'
API_KEY  = 'your_api_key'
SEED     = str(int(time.time() * 1000))
TOKEN    = hashlib.md5((API_NAME.lower() + API_KEY + SEED).encode()).hexdigest()

headers = {
    'Content-Type': 'application/json',
    'x-auth-name':  API_NAME,
    'x-auth-seed':  SEED,
    'x-auth-token': TOKEN,
}

body = {
    'custom_tracking_num':     'ORDER-20260501-001',
    'recipient_name':          'Jane Smith',
    'recipient_country':       'SG',
    'recipient_phone':         '6591234567',
    'recipient_address':       '123 Orchard Road',
    'recipient_city':          'Singapore',
    'recipient_email':         'jane@example.com',
    'postal_code':             '238858',
    'sender_country':          'SG',
    'client_size':             '30,20,10',
    'client_weight':           1.5,
    'declared_value':          99.99,
    'declared_value_currency': 'SGD',
    'item': [{'description': 'Electronics', 'itemHSCode': '8471300000', 'quantity': 1, 'unitPrice': 99.99, 'weight': 1.5, 'currency': 'SGD', 'totalValue': 99.99}],
}

resp = requests.post('https://api.test.wmgdelivery.com/v1/openapi/order/create-order', json=body, headers=headers)
print(resp.json())

Node.js / TypeScript

typescript
import crypto from 'node:crypto';

const API_NAME = 'your_api_name';
const API_KEY  = 'your_api_key';
const SEED     = String(Date.now());
const TOKEN    = crypto.createHash('md5').update(API_NAME.toLowerCase() + API_KEY + SEED).digest('hex');

const body = JSON.stringify({
    custom_tracking_num:     'ORDER-20260501-001',
    recipient_name:          'Jane Smith',
    recipient_country:       'SG',
    recipient_phone:         '6591234567',
    recipient_address:       '123 Orchard Road',
    recipient_city:          'Singapore',
    recipient_email:         'jane@example.com',
    postal_code:             '238858',
    sender_country:          'SG',
    client_size:             '30,20,10',
    client_weight:           1.5,
    declared_value:          99.99,
    declared_value_currency: 'SGD',
    item: [{ description: 'Electronics', itemHSCode: '8471300000', quantity: 1, unitPrice: 99.99, weight: 1.5, currency: 'SGD', totalValue: 99.99 }],
});

const resp = await fetch('https://api.test.wmgdelivery.com/v1/openapi/order/create-order', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'x-auth-name':  API_NAME,
        'x-auth-seed':  SEED,
        'x-auth-token': TOKEN,
    },
    body,
});
console.log(JSON.stringify(await resp.json(), null, 2));

PHP

php
<?php
$API_NAME = 'your_api_name';
$API_KEY  = 'your_api_key';
$SEED     = (string)(time() * 1000);
$TOKEN    = md5(strtolower($API_NAME) . $API_KEY . $SEED);

$body = [
    'custom_tracking_num'     => 'ORDER-20260501-001',
    'recipient_name'          => 'Jane Smith',
    'recipient_country'       => 'SG',
    'recipient_phone'         => '6591234567',
    'recipient_address'       => '123 Orchard Road',
    'recipient_city'          => 'Singapore',
    'recipient_email'         => 'jane@example.com',
    'postal_code'             => '238858',
    'sender_country'          => 'SG',
    'client_size'             => '30,20,10',
    'client_weight'           => 1.5,
    'declared_value'          => 99.99,
    'declared_value_currency' => 'SGD',
    'item'                    => [
        ['description' => 'Electronics', 'itemHSCode' => '8471300000', 'quantity' => 1, 'unitPrice' => 99.99, 'weight' => 1.5, 'currency' => 'SGD', 'totalValue' => 99.99],
    ],
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.test.wmgdelivery.com/v1/openapi/order/create-order');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'x-auth-name: '  . $API_NAME,
    'x-auth-seed: '  . $SEED,
    'x-auth-token: ' . $TOKEN,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
curl_close($ch);
echo json_encode(json_decode($response, true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
?>

注意事项

  • custom_tracking_num 在同一客户下必须唯一,重复会被拒绝。
  • client_size 三个数字的顺序系统会自动从大到小重排。
  • 认证 token 不包含请求参数,只用凭证和 seed 计算。
  • x-auth-seed 必须是 13 位毫秒级 UNIX 时间戳,且与服务器时间相差不超过 ±10 分钟。
  • 所有参数区分大小写。

错误码

codemessage说明
1认证错误消息认证失败;具体 message 取决于失败原因 —— 完整清单见认证与签名
1custom_tracking_num (XXX) already exist该内部单号在当前客户下已存在。注意 exist 没有结尾的 s
1Service code invalidrecipient_country = USservice_code 未传或不是可识别的代码
1Service code (XXX) invalidrecipient_country = SG 且传入的 service_code 不是可识别的代码
1recipient_country(XX) not allow该收件国代码不在平台允许的国家清单内
1Item <row> <field> <reason>item[] 中某一项校验失败,<row> 为行号、<field> 为字段名
1字段校验消息其他字段级校验失败(必填、长度、格式、枚举)