Skip to content

获取订单文件

接口概述

获取订单关闭时生成的运输单据,以 Base64 编码的 PDF 返回。解码该字符串即可得到 PDF 文件。

订单单据是在 创建并关闭订单 返回之后异步生成的,因此本接口会短暂等待目标文件出现,再决定是否放弃。

请求信息

  • Method: POST
  • Path: /api/order/get-order-file
  • Authentication: Bearer Token

请求头

字段说明
Content-Typeapplication/json
AuthorizationBearer <token>

请求参数

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

参数类型必填说明
job_nostring订单的 Job No,即 创建并关闭订单 返回的 Data.JobNo
typestring要获取的单据类型,取值为 CN35CN38CP84CP87ExportControlFormCN31StatementOfLodgmentCN33ReceptacleManifest 之一。具体有哪些取决于订单的路线和承运商。

请求体示例

json
{
    "job_no": "CN38SG24010001",
    "type": "CN35"
}

认证方式

本接口使用 Bearer Token 认证。

请先通过 获取 Token 取得 Token,并以 Authorization: Bearer <Token> 形式发送。

响应信息

响应为 JSON 格式。

响应格式

字段类型说明
Codeinteger0 表示成功;非 0 表示失败
Messagestring可读的结果说明
Dataobject业务数据;失败时为空数组 []

成功响应

  • Status Code: 200
json
{
    "Code": 0,
    "Message": "Success",
    "Data": {
        "Base64": "JVBERi0xLjcKJeLjz9MKMyAwIG9iago8PAovRmlsdGVyIC9GbGF0ZURlY29kZQ..."
    }
}

示例中的 Base64 值已截断,实际响应包含完整的编码后 PDF。

字段类型说明
Data.Base64string所请求单据的 Base64 编码 PDF。解码后即为 PDF 文件。

错误响应

  • Status Code: 200(业务逻辑错误)或 4xx/5xx(系统错误)
json
{
    "Code": 1,
    "Message": "Order not found!",
    "Data": []
}

结果码

Code说明
0成功
1失败

示例

Bash

bash
BASE_URL="https://api.postal.test.wmgdelivery.com"
TOKEN="your_access_token"

curl -X POST "$BASE_URL/api/order/get-order-file" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"job_no":"CN38SG24010001","type":"CN35"}'

Windows PowerShell

powershell
$BASE_URL = "https://api.postal.test.wmgdelivery.com"
$TOKEN    = "your_access_token"

$body = @{
    job_no = "CN38SG24010001"
    type   = "CN35"
} | ConvertTo-Json

# 单据仍在生成时,服务端可能会把请求挂住一段时间
$response = Invoke-RestMethod -Uri "$BASE_URL/api/order/get-order-file" -Method Post `
    -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $TOKEN"} `
    -TimeoutSec 90

[IO.File]::WriteAllBytes("CN35.pdf", [Convert]::FromBase64String($response.Data.Base64))

Python

python
import base64
import requests

BASE_URL = "https://api.postal.test.wmgdelivery.com"
TOKEN    = "your_access_token"

# 单据仍在生成时,服务端可能会把请求挂住一段时间
resp = requests.post(f"{BASE_URL}/api/order/get-order-file", json={
    "job_no": "CN38SG24010001",
    "type": "CN35",
}, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=90)
payload = resp.json()

with open("CN35.pdf", "wb") as fh:
    fh.write(base64.b64decode(payload["Data"]["Base64"]))

Node.js / TypeScript

typescript
import {writeFileSync} from "node:fs";

const BASE_URL = "https://api.postal.test.wmgdelivery.com";
const TOKEN = "your_access_token";

// 单据仍在生成时,服务端可能会把请求挂住一段时间
const res = await fetch(`${BASE_URL}/api/order/get-order-file`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${TOKEN}`,
  },
  body: JSON.stringify({job_no: "CN38SG24010001", type: "CN35"}),
  signal: AbortSignal.timeout(90_000),
});
const payload = await res.json();

writeFileSync("CN35.pdf", Buffer.from(payload.Data.Base64, "base64"));

PHP

php
<?php
$BASE_URL = 'https://api.postal.test.wmgdelivery.com';
$TOKEN    = 'your_access_token';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $BASE_URL . '/api/order/get-order-file');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $TOKEN,
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'job_no' => 'CN38SG24010001',
    'type'   => 'CN35',
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 单据仍在生成时,服务端可能会把请求挂住一段时间
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
$response = curl_exec($ch);
curl_close($ch);

$payload = json_decode($response, true);
file_put_contents('CN35.pdf', base64_decode($payload['Data']['Base64']));
?>

注意事项

  • 本接口可能阻塞约半分钟。 单据尚未就绪时,服务端会在内部轮询约 25~30 秒,然后返回 The file is being generated. Please try again later。请把客户端超时设置得高于这个值,并在稍等之后再重试,不要立即重试。
  • CN23 是包裹面单而不是订单单据,本接口会拒绝该取值。请改用 获取面单 PDF
  • 并非每个订单都有全部单据类型——具体有哪些取决于订单的路线和承运商。传入的类型合法但该订单不产出时,返回 Type of file not found.(注意末尾有句点);类型名本身不被识别时,返回不带句点的 Type of file not found
  • type 按原样精确匹配,包括大小写:要传 ExportControlForm,不能传 exportcontrolform
  • 只能获取属于当前认证账号的订单;其他账号的 job_no 会被报为 Order not found!
  • 所有参数区分大小写。

错误码

codemessage说明
1Type of file not foundtype 不是可识别的单据名称。
1Order not found!你的账号下不存在该 job_no 的订单。
1Type of file not found.单据类型可识别,但该订单不产出这种单据。
1The file is being generated. Please try again later在服务端的等待窗口内单据尚未生成完成。请稍等后重试。
1Error encountered, please contact tech@wmg-group.com with screenshot of error page for resolution.未预期的服务端错误。
1003Token errorToken 缺失、已过期或被新登录顶替。请重新调用 获取 Token