USPS 指南USPS Guide

USPS IMpb 服务类型码(Service Type Code):面向 API 集成开发者的完全指南Service Type Codes for the Intelligent Mail Package Barcode (IMpb): A Field Guide for USPS API Integrators

如果你在把 USPS 发货集成进履约平台、3PL 系统或电商后端,Intelligent Mail Package Barcode(IMpb,智能邮件包裹条码)就是你生成的所有面单元素里影响最大的一个,而它最不被理解的部分就是 Service Type Code(STC,服务类型码)。STC 是藏在 20 位跟踪码里的一个短数字字段,USPS 靠它判断你实际发的是什么产品、该付多少钱、能看到哪些跟踪事件。弄错的话,面单照样能打印出来,但包裹可能在入网时被拒收、被收取罚金邮资,或者被悄悄抹掉跟踪事件。If you integrate USPS shipping into a fulfillment platform, a 3PL stack, or an ecommerce backend, the Intelligent Mail Package Barcode (IMpb) is the single most consequential label element you will generate, and its least understood field is the Service Type Code (STC). The STC is a short numeric field buried inside the 20-digit tracking code, and USPS uses it to decide what product you actually shipped, what you should have paid, and which tracking events you get to see. Get it wrong and the label prints fine, but the package can be rejected at induction, billed at penalty postage, or silently stripped of tracking events.

这篇指南走完从条码位布局到凌晨两点调试的全过程,那时客户的包裹一个扫描记录都没有。它写给构建和维护 USPS 集成的工程师:31 位条码如何组织、STC 字段如何对应官方码表、MOD 10 校验位怎么算,以及如何把这一切接进一条会大声失败而不是悄悄失败的发货管线。This guide walks the full lifecycle from the barcode's bit layout to the debug session at 2 a.m. when a customer's package shows no scans. It is written for engineers who build or maintain USPS integrations: how the 31-digit barcode is structured, how the STC field maps to the official code table, how the MOD 10 check digit is computed, and how to wire all of it into a shipping pipeline that fails loudly instead of failing quietly.

A USPS parcel with an Intelligent Mail package barcode label passing a scanner at a package sorting facility, conveyor belt, shallow depth of field
IMpb 是寄件人与 USPS 之间的机器可读契约,STC 是其中最容易被忽略的字段The IMpb is the machine-readable contract between the mailer and the Postal Service, and the STC is its most overlooked field

为什么服务类型码如此重要Why the Service Type Code Matters

USPS 从 2013 年 1 月开始分阶段推行商业包裹类别的 IMpb 要求。今天,所有商业 First-Class Mail Parcel、Priority Mail、Priority Mail Express、Parcel Select、Media Mail、Library Mail 和国际包裹产品都必须带 IMpb,才能拿到自动化价格和完整跟踪可见性。条码不是可选的装饰:它是寄件人与邮政服务之间关于"这件邮件是什么"的机器可读契约。USPS began phasing in IMpb requirements for commercial package classes in January 2013. Today, every commercial First-Class Mail Parcel, Priority Mail, Priority Mail Express, Parcel Select, Media Mail, Library Mail, and international package product must carry an IMpb to earn automation pricing and full tracking visibility. The barcode is not optional decoration: it is the machine-readable contract between the mailer and the Postal Service about what the mailpiece is.

在这份契约里,STC 是两位字段(跟踪码第 3-4 位),告诉 USPS 邮件属于哪个产品类别、带哪些附加服务。下游一切都以它为键:入网时的费率校验(付的邮资和产品匹配吗?)、分拣计划(走哪个网络、哪个服务标准?)、通过 Tracking API 暴露的跟踪事件(客户到底能不能看到扫描?)、以及合规审查(90 天后会不会来一张罚金邮资账单?)。Within that contract, the STC is the two-digit field (positions 3-4 of the tracking code) that tells USPS which product class and extra services the mailpiece belongs to. Everything downstream keys off it: the rate validation at induction (does the postage paid match the product?), the sortation plan (which network and service standard apply?), the tracking events exposed through the Tracking API (does the customer see scans at all?), and the compliance review (is a penalty postage bill coming in 90 days?).

对 API 集成商来说,STC 是最容易出错、且错误在打印面单时完全不可见的字段。STC 错误的面单看起来完美无缺:条码能扫、地址能打、承运商照样揽收。问题在后面才浮出水面:一个缺失的扫描、一件被拒收的包裹、或一张账单调整。这种不对称正是这篇指南存在的原因:STC 值得和收件地址同等重视,因为它是向 USPS 定义邮件身份的字段。For an API integrator, the STC is the field most likely to be wrong in ways that are invisible at label-print time. A label with the wrong STC looks perfect: the barcode scans, the address prints, the carrier picks it up. The failure surfaces later, as a missing scan, a rejected parcel, or an invoice adjustment. That asymmetry is why this guide exists: the STC deserves the same attention as the destination address, because it is the field that defines the mailpiece to USPS.

31 位 IMpb 的结构解剖Anatomy of the 31-Digit IMpb

IMpb 是一个 31 位条码,由两部分组成:20 位跟踪码和 11 位路由码。跟踪码标识邮件本身和寄件人;路由码以机器可读形式携带目的地址(5 位 ZIP、4 位 ZIP+4、2 位投递点)。带上完整的 11 位路由码才能拿到自动化折扣,所以大多数商业面单是完整 31 位,但更短的路由码(0、5 或 9 位)也合法,只是条码更短。The IMpb is a 31-digit barcode built from two parts: a 20-digit tracking code and an 11-digit routing code. The tracking code identifies the mailpiece and its mailer; the routing code carries the destination address in machine-readable form (5-digit ZIP, 4-digit ZIP+4, 2-digit delivery point). Including the full 11-digit routing code is what earns automation discounts, so most commercial labels carry the full 31 digits, but shorter routing codes (0, 5, or 9 digits) are legal and simply shrink the barcode.

20 位跟踪码拆成五个固定字段。第 1-2 位是条码标识符,IMpb 恒为 "00"。第 3-4 位是服务类型码,即本篇主角。第 5-10 位是 6 位 Mailer ID(MID),或第 5-13 位是 9 位 MID;按 USPS Publication 199 规则,9 位 MID 永远以 9 开头。最后一位之前的剩余位数是序列号:MID 为 6 位时序列号 9 位,MID 为 9 位时序列号 6 位。第 20 位是 MOD 10 校验位。序列号在同一个 MID + STC 组合内必须唯一,复用序列号是后面要讲的经典静默故障之一。The 20-digit tracking code decomposes into five fixed fields. Digits 1-2 are the barcode identifier, always "00" for IMpb. Digits 3-4 are the Service Type Code, the subject of this guide. Digits 5-10 hold a 6-digit Mailer ID (MID), or digits 5-13 hold a 9-digit MID; 9-digit MIDs always begin with "9", per the USPS Publication 199 rules. The remaining digits before the last one are the serial number: 9 digits when the MID is 6 digits, 6 digits when the MID is 9 digits. The final digit, position 20, is the MOD 10 check digit. The serial number must be unique within a given MID and STC combination, and reusing a serial is one of the classic silent failures discussed later.

31 位 IMpb 条码结构图:20 位跟踪码由条码标识符 00、STC 服务类型码、Mailer ID、序列号和 MOD 10 校验位组成,11 位路由码由 ZIP、ZIP+4 和投递点组成31-digit IMpb barcode structure: a 20-digit tracking code made of barcode identifier 00, STC service type code, Mailer ID, serial number and MOD 10 check digit, plus an 11-digit routing code of ZIP, ZIP+4 and delivery point
31 位 IMpb:20 位跟踪码 + 11 位路由码The 31-digit IMpb: a 20-digit tracking code plus an 11-digit routing code

物理上,IMpb 是 4-state 条码:65 根竖条,每根条有四种状态(full bar、ascender、descender、tracker),编码 130 bit 数据加纠错位。作为集成商,你通常不会直接碰符号学;你的条码库或邮资服务商处理它。你真正处理的是数据:20 位跟踪码,以及可选的路由码。Physically, the IMpb is a 4-state barcode: 65 vertical bars, each bar drawn in one of four states (full bar, ascender, descender, tracker), encoding 130 bits of data plus error-correction bits. As an integrator you normally never touch the symbology directly; your barcode library or postage provider handles it. What you do touch is the data: the 20-digit tracking code and, optionally, the routing code.

有一个困惑值得现在就说清:面单上打印的人眼可读跟踪号是跟踪数据的显示渲染,不是第二个标识符。不同面单软件对数字的分组方式不同,你在打印面单上看到的前几位数字不能用来可靠地读 STC。你的集成的权威值,也是 USPS Tracking API 期望的值,是条码里编码的 20 位跟踪码。解析结构化字段,永远不要解析打印出来的前缀。One confusion worth clearing up now: the human-readable tracking number printed on the label is a display rendering of the tracking data, not a second identifier. Different label software groups the digits differently, and the leading digits you see on a printed label are not a reliable way to read the STC. The authoritative value for your integration, and the value the USPS Tracking API expects, is the 20-digit tracking code as encoded in the barcode. Parse the structured fields, never the printed prefix.

解码服务类型码字段Decoding the Service Type Code Field

STC 占据跟踪码第 3-4 位,紧跟 "00" 条码标识符之后。语义上它标识产品类别和附加服务(签名确认、保险、挂号等),既不是寄件人也不是目的地。同一个寄件人发往同一个 ZIP 的两件包裹,如果邮资产品不同,就必须带不同的 STC;这正是 USPS 校验邮件所需要的信息。The STC occupies positions 3-4 of the tracking code, immediately after the "00" barcode identifier. Semantically it identifies the product class and any extra services (signature confirmation, insurance, registered, and so on), not the shipper and not the destination. Two packages to the same ZIP from the same mailer with different postage products must carry different STCs; that is exactly the information USPS needs to validate the mailpiece.

码段分几个大族。国内包裹服务在 030-061:First-Class Mail Parcel 在 030-034,Priority Mail 在 040-048,Parcel Select 在 050-053 和 058,Media Mail / Library Mail 在 060-061。Priority Mail Express 独占 100-180 区段。国际产品在区段顶端,930-961:930-932 是 Priority Mail International,940 是 Priority Mail Express International,950 是 First-Class Package International Service。The codes fall into broad families. Domestic package services live in 030-061: First-Class Mail Parcel in 030-034, Priority Mail in 040-048, Parcel Select in 050-053 and 058, and Media Mail / Library Mail in 060-061. Priority Mail Express occupies its own band, 100-180. International products sit at the top of the range, 930-961, with 930-932 for Priority Mail International, 940 for Priority Mail Express International, and 950 for First-Class Package International Service.

USPS 下游系统在三个地方消费 STC。费率校验在入网时把面单上的邮资和 STC 隐含的产品对账。分拣计划用它把包裹路由进正确的网络和服务标准。跟踪可见性用它决定发布哪些事件:First-Class 包裹有基础扫描事件,带签名确认的产品会在 Tracking API 里露出签名事件。格式错误或不匹配的 STC 可以独立地让这三项校验中的任何一项失败,这就是为什么一个错误码能产生如此令人困惑的症状。USPS downstream systems consume the STC in three places. Rate validation checks the postage on the label against the product implied by the STC at induction. The sortation plan uses it to route the parcel into the correct network and service standard. Tracking visibility uses it to decide which events are published: a First-Class parcel gets basic scan events, while a product with signature confirmation surfaces the signature event in the Tracking API. A malformed or mismatched STC can fail any of these three checks independently, which is why a wrong code can produce such confusing symptoms.

服务类型码表The Service Type Code Tables

权威清单是 USPS PostalPro 上发布的《Service Type Codes for Intelligent Mail Package Barcode (IMpb)》文档[1]。表格用三位码渲染以便阅读(030、040、100、930),而且会随产品变化不断更新,所以要把它当作移动靶,在你的集成文档里钉一份带日期的副本。The authoritative list is the "Service Type Codes for Intelligent Mail Package Barcode (IMpb)" document published on USPS PostalPro[1]. The table is rendered with three-digit codes for readability (030, 040, 100, 930), and it is updated over time as products change, so treat it as a moving target and pin a dated copy into your integration documentation.

国内表覆盖日常电商产品。First-Class Mail Parcel 跨 030-034,含非营利和高密度定价变体。Priority Mail 跨 040-048,含零售、商业费率与 hold-for-pickup 变体。Parcel Select 跨 050-053 加 058,覆盖 3PL 和区域承运商交给 USPS 做末端派送的合并入网产品。Media Mail 是 060,Library Mail 是 061。Priority Mail Express 占 100-180,区段更宽,因为它要编码零售/商业、统一费率与 open-and-distribute 变体。The domestic table covers the everyday ecommerce products. First-Class Mail Parcel spans 030-034, with variants for nonprofit and high-density pricing. Priority Mail spans 040-048, including retail and commercial rates and hold-for-pickup variants. Parcel Select spans 050-053 plus 058, covering the consolidated-entry products that 3PLs and regional carriers hand to USPS for final-mile delivery. Media Mail is 060 and Library Mail is 061. Priority Mail Express occupies 100-180, a wider band because it encodes retail/commercial, flat-rate, and open-and-distribute variants.

国际表更小,但同样承重。Priority Mail International 是 930、931、932(零售、商业基础、商业增强)。Priority Mail Express International 是 940。First-Class Package International Service 是 950,950-961 区段的邻近码用于变体。新产品上线时,USPS 会分配新码;例如 Ground Advantage 时代的整合就重排了国内表。在通过你的集成发新产品之前,对照当前官方表核对你邮资服务商映射的 STC。在仓库里留一份本地、带日期的 PDF 副本是廉价的保险。The international table is smaller but just as load-bearing. Priority Mail International is 930, 931, and 932 (retail, commercial base, and commercial plus). Priority Mail Express International is 940. First-Class Package International Service is 950, with adjacent codes in the 950-961 band used for variants. When a new product launches, USPS assigns it new codes; the Ground Advantage-era consolidation, for example, reshuffled the domestic table. Before you ship a new product through your integration, verify the STC your postage provider maps to it against the current official table. Keeping a local, dated copy of the PDF in your repo is cheap insurance.

MOD 10 校验位The MOD 10 Check Digit

跟踪码第 20 位是 MOD 10 校验位,用来捕获转录和编码错误。USPS 用加权方案:对 19 个数据位交替赋权重 3 和 1,从最右侧数据位(第 19 位)开始权重 3,向左推进。加权求和,取总和模 10,校验位等于 10 减余数,若结果为 10 则取 0。The 20th digit of the tracking code is a MOD 10 check digit that catches transcription and encoding errors. USPS uses a weighted scheme: assign weights of 3 and 1 alternately to the 19 data digits, starting with weight 3 on the rightmost data digit (position 19) and moving left. Sum the weighted digits, take the sum modulo 10, and the check digit is 10 minus that remainder, where a result of 10 becomes 0.

用一个合成跟踪码做完整示例:条码标识符 "00"、STC "04"(Priority Mail 族)、6 位 MID "001234"、序列号 "567890123"。19 个数据位是 0 0 0 4 0 0 1 2 3 4 5 6 7 8 9 0 1 2 3,从右到左交替权重为 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3。Here is a worked example on a synthetic tracking code: barcode identifier "00", STC "04" (Priority Mail family), 6-digit MID "001234", serial "567890123". The 19 data digits are 0 0 0 4 0 0 1 2 3 4 5 6 7 8 9 0 1 2 3, and the alternating weights, applied right to left, are 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3.

加权和是 0+0+0+4+0+0+3+2+9+4+15+6+21+8+27+0+3+2+9,等于 113。113 mod 10 是 3,所以校验位是 10 减 3,即 7。完整跟踪码因此是 00040012345678901237。这个号码是演示用的构造品,不要用于真实发货。The weighted sum is 0+0+0+4+0+0+3+2+9+4+15+6+21+8+27+0+3+2+9, which equals 113. Since 113 mod 10 is 3, the check digit is 10 minus 3, or 7. The complete tracking code is therefore 00040012345678901237. This number is a construction for illustration; do not reuse it for a real shipment.

校验位错误时,条码无法通过校验。取决于失败发生在哪里,包裹可能被入网扫描器拒收、不产生跟踪事件、或被当作无法投递退回寄件人。因为校验位是确定性的,坏校验位几乎总是代码 bug(字段长度错误、数字交换、序列号被截断),而不是随机故障。从你在服务端生成跟踪码的那天起,就该在测试套件里加一个校验位验证器。When the check digit is wrong, the barcode will not validate. Depending on where the failure happens, the parcel may be rejected by the induction scanner, fail to generate tracking events, or be returned to the mailer as undeliverable. Because the check digit is deterministic, a bad check digit is almost always a code bug (wrong field length, swapped digits, a serial number that was truncated) rather than a random glitch, and it is worth adding a check-digit validator to your test suite the day you start generating tracking codes server-side.

把 STC 集成进你的发货管线Integrating STC Into Your Shipping Pipeline

最干净的集成是避免自己生成跟踪码:邮资服务商的 API 会为你要报价的产品返回跟踪号,也就返回了 STC。这是大多数 rate-and-label API 的默认方式,能消灭一整类 bug,因为服务商拥有 MID、序列号分配和校验位。你的工作简化为信任返回值,并记录它用于对账。The cleanest integration avoids generating tracking codes yourself: your postage provider's API returns the tracking number, and therefore the STC, for the product you quoted. This is the default for most rate-and-label APIs and eliminates an entire class of bugs, because the provider owns the MID, the serial allocation, and the check digit. Your job reduces to trusting the returned value and logging it for reconciliation.

如果你在服务端生成跟踪码,就要承担全部责任:来自 USPS 的合法 MID、全网络的序列号唯一性、正确的校验位,以及最关键的一点,与所报产品匹配的 STC。从内部产品目录到 STC 的映射必须是一等公民的查找表,对照官方 PostalPro 表校验,并配一个测试:未映射的产品走到面单生成时测试必须失败。If you generate tracking codes server-side, you take on the full responsibility: a valid MID from USPS, serial-number uniqueness across your fleet, correct check digit, and, critically, an STC that matches the product you quoted. The mapping from your internal product catalog to the STC must be a first-class lookup table, verified against the official PostalPro table, with a test that fails when an unmapped product reaches label generation.

打印前跑一遍校验清单:STC 与所报产品匹配;跟踪码正好 20 位;校验位通过;该 MID + STC 下序列号未被用过;条码数据长度在 20 到 31 位之间,取决于是否包含路由码。测试环境应使用 USPS 测试码和测试 MID,让预发面单永远不会以真实 STC 进入生产网络。Before printing, run a validation checklist: the STC matches the quoted product; the tracking code is exactly 20 digits; the check digit verifies; the serial has not been used before for this MID and STC; and the barcode data length is between 20 and 31 digits depending on whether you include the routing code. Test environments should use USPS test codes and test MIDs so a staging label never enters the live network under a real STC.

排查常见 STC 故障Debugging Common STC Failures

大多数 STC 故障落在少数几种模式里。类别错配最常见:Priority Mail 的报价却打印了 Parcel Select 的 STC,或合并入网产品贴了零售码。坏校验位通常追溯到序列号生成中的截断或数字交换。复用的序列号会让错误包裹产生跟踪事件,或干脆没有事件。不以 9 开头的 9 位 MID 表面即非法,有些服务商 API 会拒绝,另一些会悄悄编码。Most STC failures fall into a small set of patterns. The class mismatch is the most common: a Priority Mail quote printed with a Parcel Select STC, or a consolidated-entry product labeled with a retail code. A bad check digit usually traces to a truncation or swapped digits in serial generation. A reused serial number produces tracking events for the wrong package or none at all. And a 9-digit MID that does not start with "9" is invalid on its face, which some provider APIs reject and others quietly encode.

症状特征很重要。入网被拒意味着扫描器无法解析产品:先对照码表查 STC。跟踪了一天然后静默的包裹,往往指向序列号冲突。从第一条扫描起就没有事件,通常是上游校验位失败,包裹被当作未知条码处理。几周后的一张罚金邮资账单,是类别错配通过入网后的经典迟到症状。The symptom signature matters. A label rejected at induction means the scanner could not resolve the product: check the STC against the table first. A package that tracks for a day and then goes silent often points to a serial collision. No events at all from the first scan usually means a check-digit failure upstream, so the parcel is being handled as an unknown barcode. A penalty postage invoice weeks later is the classic late symptom of a class mismatch that passed induction.

调试时先解码:写一个小解码器,把 20 位跟踪码拆成五个字段并重算校验位,然后对照官方表核 STC、对照你的 USPS 记录核 MID。在生成代码里修 bug,不要手工改条码:从固定代码路径打印的面单会在规模上复现同样的缺陷。把失败的跟踪号加进回归套件,让校验位验证器和 STC 映射测试在每次部署时运行。When you debug, decode first: write a small decoder that splits the 20-digit tracking code into its five fields and recomputes the check digit, then verify the STC against the official table and the MID against your USPS record. Fix the bug in the generation code, not by hand-editing the barcode: a label that prints from a fixed code path will reproduce the same defect at scale. Add the failing tracking number to your regression suite, and let the check-digit validator and STC mapping test run on every deploy.

STC 只是二十位里的两位,但正是它决定了"一张能发出去的面单"和"一件被 USPS 识别的邮件"之间的差别。搭好结构、核对代码、验证校验位,你的集成就不会出现在罚金邮资的收件箱里。The STC is two digits out of twenty, but it is the field that makes the difference between a label that ships and a mailpiece that USPS recognizes. Build the structure, verify the code, and validate the check digit, and your integration will stay out of the penalty-postage inbox.

常见问题FAQ

STC 是 20 位跟踪码第 3-4 位的两位字段,告诉 USPS 邮件属于哪个产品类别、带哪些附加服务。USPS 用它做入网费率校验、分拣规划和跟踪事件可见性。STC 错误可能导致拒收、罚金邮资或跟踪事件缺失,尽管面单打印一切正常。The STC is the two-digit field at positions 3-4 of the 20-digit tracking code that tells USPS which product class and extra services a mailpiece belongs to. USPS uses it for rate validation at induction, sortation planning, and tracking event visibility. A wrong STC can cause rejection, penalty postage, or missing tracking events even though the label prints fine.
20 位跟踪码的构成是:00(条码标识符)+ 2 位 STC + 6 位或 9 位 Mailer ID + 9 位或 6 位序列号 + 1 位 MOD 10 校验位。STC 就是第 3、4 位。不要从打印面单的前缀去读,面单软件对数字的分组方式不同。解析服务商返回或条码编码的结构化 20 位值。The 20-digit tracking code is: 00 (barcode identifier) + 2-digit STC + 6- or 9-digit Mailer ID + 9- or 6-digit serial + 1-digit MOD 10 check digit. The STC is the 3rd and 4th digits. Do not read it from the printed label prefix; label software groups digits differently. Parse the structured 20-digit value your provider returns or your barcode encodes.
对 19 个数据位从最右侧(第 19 位)开始交替赋权重 3 和 1,加权求和后取模 10,校验位等于 (10 - 余数) mod 10。示例:合成码 00040012345678901237 的加权和是 113,校验位为 10 - 3 = 7。Assign weights 3 and 1 alternately to the 19 data digits, starting with 3 on the rightmost digit (position 19). Sum the weighted digits, take the sum modulo 10, and the check digit is (10 - remainder) mod 10. Example: the synthetic code 00040012345678901237 has a weighted sum of 113, so the check digit is 10 - 3 = 7.
症状取决于哪一项下游校验失败:入网被拒(扫描器无法解析产品)、跟踪事件缺失或中断,或错配通过入网后几周收到罚金邮资账单。因为面单打印正常,故障通常被发现得很晚。打印前要对照官方 PostalPro 表验证 STC 映射。The symptoms depend on which downstream check fails: rejection at induction (the scanner cannot resolve the product), missing or truncated tracking events, or a penalty postage invoice weeks later if the mismatch passed induction. Because the label prints normally, the failure is usually discovered late. Validate the STC mapping against the official PostalPro table before printing.

想跳过 STC 映射和校验位的坑?Skip the STC mapping and check-digit traps?

EasyShippingX 把 USPS 面单生成、STC 映射、跟踪号校验和跟踪同步固化到发货流程里,让你的集成从第一张面单起就符合 USPS 规范。EasyShippingX bakes USPS label generation, STC mapping, tracking number validation, and tracking sync into your shipping flow, so your integration is USPS-compliant from the first label.

Get Rate Comparison
Get Rate Comparison