Skip to content

获取运单号

接口说明

用你自己的订单号(下单时提交的 custom_tracking_num)反查 WMG 分配的运单号。手上只有内部单号时用这个接口。

请求信息

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

请求头

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

请求参数

参数类型必填说明
custom_tracking_numstring下单时提交的内部订单号

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": {
        "barcode": "WGC000000000044"
    }
}
字段类型说明
data.barcodestring该内部单号对应的 WMG 运单号

失败响应

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

常见错误:

  • 认证失败 → code 1;具体 message 取决于失败原因(如 x-auth-token: INVALIDx-auth-seed: TIMEOUT)—— 见认证与签名
  • 单号不存在 → code 1,message 为 Order Not Found!

结果码

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 -G "https://api.test.wmgdelivery.com/v1/openapi/order/get-barcode" \
  --data-urlencode "custom_tracking_num=ORDER-20260501-001" \
  -H "x-auth-name: $API_NAME" \
  -H "x-auth-seed: $SEED" \
  -H "x-auth-token: $TOKEN"

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") })

$headers = @{
    "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/get-barcode?custom_tracking_num=ORDER-20260501-001" `
    -Method Get -Headers $headers
$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 = {
    'x-auth-name':  API_NAME,
    'x-auth-seed':  SEED,
    'x-auth-token': TOKEN,
}

resp = requests.get(
    'https://api.test.wmgdelivery.com/v1/openapi/order/get-barcode',
    params={'custom_tracking_num': 'ORDER-20260501-001'},
    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 url = new URL('https://api.test.wmgdelivery.com/v1/openapi/order/get-barcode');
url.searchParams.set('custom_tracking_num', 'ORDER-20260501-001');

const resp = await fetch(url.toString(), {
    headers: {
        'x-auth-name':  API_NAME,
        'x-auth-seed':  SEED,
        'x-auth-token': TOKEN,
    },
});
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);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.test.wmgdelivery.com/v1/openapi/order/get-barcode?' . http_build_query(['custom_tracking_num' => 'ORDER-20260501-001']));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'x-auth-name: '  . $API_NAME,
    'x-auth-seed: '  . $SEED,
    'x-auth-token: ' . $TOKEN,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);
echo json_encode(json_decode($response, true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
?>

注意事项

  • custom_tracking_num 必须与下单时提交的值完全一致。
  • 认证 token 不包含请求参数,只用凭证和 seed 计算。
  • x-auth-seed 必须是 13 位毫秒级 UNIX 时间戳,且与服务器时间相差不超过 ±10 分钟。
  • 所有参数区分大小写。

错误码

codemessage说明
1认证错误消息认证失败;具体 message 取决于失败原因 —— 完整清单见认证与签名
1Order Not Found!当前客户下不存在该 custom_tracking_num 对应的订单