Bitzsoft.Integrations.Express.ChinaPost 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Bitzsoft.Integrations.Express.ChinaPost --version 1.0.2
                    
NuGet\Install-Package Bitzsoft.Integrations.Express.ChinaPost -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.Express.ChinaPost" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Express.ChinaPost" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Express.ChinaPost" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.Express.ChinaPost --version 1.0.2
                    
#r "nuget: Bitzsoft.Integrations.Express.ChinaPost, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.Express.ChinaPost@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.Express.ChinaPost&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Express.ChinaPost&version=1.0.2
                    
Install as a Cake Tool

Bitzsoft.Integrations.Express.ChinaPost

中国邮政/EMS 物流服务实现 -- 基于《中小电商企业接口规范 V2.7》公共请求信封对接。

功能特性

  • EMS 三要素认证:senderNo + authorization + 公共请求信封(apiCode)
  • 支持运单轨迹查询、白名单订阅、订单接入、订单取消、预估邮费、面单查询
  • 支持按 EMS 常见单号规则的本地承运商识别
  • 统一异常处理,供应商错误码自动映射为 ExpressException
  • 实现 IExpressProvider 统一契约,可无缝替换其他供应商实现

安装

.NET CLI

dotnet add package Bitzsoft.Integrations.Express.ChinaPost

PackageReference

<PackageReference Include="Bitzsoft.Integrations.Express.ChinaPost" Version="1.0.0" />

配置

appsettings.json

{
  "Express": {
    "ChinaPost": {
      "SenderNo": "协议客户号",
      "Authorization": "测试或生产授权码",
      "BaseUrl": "https://api.ems.com.cn",
      "UserCode": "可选用户编码",
      "Version": "V1.0.0",
      "HttpClientName": "ChinaPostExpress"
    }
  }
}
配置项 必填 默认值 说明
SenderNo 是 — EMS 协议客户号
Authorization 是 — 授权码,区分测试和生产
BaseUrl 否 https://api.ems.com.cn EMS API 基地址
UserCode 否 — 用户编码
Version 否 V1.0.0 EMS API 版本
HttpClientName 否 ChinaPostExpress 命名 HttpClient 名称

注册服务

从 IConfiguration 绑定(推荐)

using Bitzsoft.Integrations.Express.ChinaPost;

builder.Services.AddBitzsoftChinaPostExpress(
    builder.Configuration.GetSection("Express:ChinaPost"));

委托配置

builder.Services.AddBitzsoftChinaPostExpress(options =>
{
    options.SenderNo = "your_sender_no";
    options.Authorization = "your_authorization";
});

请求审计

内置 Bitzsoft.Integrations.RequestLogging 出站请求记录管道,默认使用 NullRequestLogStore 不持久化。

// ① 默认:启用记录管道但不持久化(日志丢弃)
services.AddBitzsoftChinaPostExpress(options => { /* ... */ });

// ② 持久化:宿主注册 IRequestLogStore 实现后,所有出站请求自动落库
services.AddRequestLogging<MyRequestLogStore>(opts =>
{
    opts.MaxInMemoryBodyBytes = 64 * 1024; // 仅控制内存/加密临时文件切换,不截断正文
    opts.SensitiveFields.Add("Authorization");
});
services.AddBitzsoftChinaPostExpress(options => { /* ... */ });

使用示例

物流轨迹查询

using Bitzsoft.Integrations.Express.Interfaces;
using Bitzsoft.Integrations.Express.Models;

public class TrackingService
{
    private readonly IExpressProvider _express;

    public TrackingService(IExpressProvider express) => _express = express;

    public async Task TrackAsync(string trackingNumber)
    {
        ExpressTrackingInfo info = await _express.TrackAsync(trackingNumber);
        Console.WriteLine($"状态: {info.State}, 轨迹数: {info.Traces.Count}");

        foreach (var step in info.Traces)
            Console.WriteLine($"[{step.Time:yyyy-MM-dd HH:mm}] {step.Description}");

        // 批量查询
        IReadOnlyList<ExpressTrackingInfo> batch =
            await _express.BatchTrackAsync(new[] { "EA001", "EA002" });
    }
}

订阅轨迹推送

ExpressSubscriptionResult sub = await _express.SubscribeAsync(
    trackingNumber: "EA001",
    callbackUrl: "https://yourapp.com/express/callback");

核心类型一览

类型 说明
ChinaPostExpressProvider 中国邮政/EMS 物流服务实现(IExpressProvider)
ChinaPostOptions EMS 配置选项(SenderNo / Authorization / BaseUrl / UserCode / Version / HttpClientName)
IExpressProvider 通用物流操作契约(抽象层)
ExpressTrackingInfo 物流轨迹查询结果
ExpressContact 快递联系人信息(含 EMS 扩展字段)

实现状态

方法 EMS 接口 apiCode 状态
TrackAsync 运单轨迹信息获取 040001 已实现
BatchTrackAsync 无批量接口 — 并发调用 TrackAsync
SubscribeAsync 白名单订阅 020005 已实现
CreateShipmentAsync 订单接入 020003 已实现
CancelShipmentAsync 订单取消 020006 已实现
GetQuoteAsync 预估邮费 050005 已实现
GenerateWaybillAsync 面单查询 010004 已实现
DetectCarrierAsync 无官方识别接口 — 本地规则识别

EMS 扩展参数

ExpressShipmentOrder.Extra 可传 EMS 特有字段:

Key 说明
logisticsOrderNo 客户内部物流订单号;不传则自动生成
waybillNo 预分配运单号;不传则由订单接入接口分配
ecommerceUserId 电商客户标识;不传则自动生成
bizProductNo 业务产品分类,默认 1(特快专递)
contentsAttribute 内件性质,默认 3(物品)
waybillTemplateType 面单模板类型,默认 129
getWaybillUrl 设置为 true 时请求面单下载 URL

取消订单时 EMS 需同时传 logisticsOrderNo 和 waybillNo。统一接口只有 orderId 参数,因此可传:

logisticsOrderNo|waybillNo|cancelReason

或 JSON:

{"logisticsOrderNo":"O202203281508328002352578560","waybillNo":"1295838760599","cancelReason":"客户取消"}

依赖

包 说明
Bitzsoft.Integrations.Express 抽象层(IExpressProvider 接口与模型)
Bitzsoft.Integrations.Compatibility 基础工具库
Bitzsoft.Integrations.RequestLogging 出站请求记录管道
Microsoft.Extensions.Configuration.Abstractions 配置抽象
Microsoft.Extensions.Http IHttpClientFactory(Typed Client 连接池)
Microsoft.Extensions.Options.ConfigurationExtensions Options 配置节点绑定

注意事项

  • EMS 要求地址使用国标全称,例如 浙江省、杭州市
  • 统一模型中的重量单位为千克,Provider 会转换为 EMS 的克
  • GetQuoteAsync 使用 EMS 国内特快物品默认产品代码 112104302300991
  • GenerateWaybillAsync 若未在 Extra["waybillNo"] 中传单号,会先调用订单接入接口创建订单,再查询面单
  • IExpressProvider 使用 TryAddSingleton 注册,如需同时注册多个供应商请单独引用并自行解析

相关包

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Express.ChinaPost:

Package Downloads
Bitzsoft.Integrations.Express.All

快递物流服务聚合包 — 包含所有供应商实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 136 9/23/2026
1.0.3 118 9/22/2026
1.0.2 137 8/29/2026
1.0.1 157 8/3/2026
1.0.0 155 8/2/2026
1.0.0-alpha.10 78 7/26/2026
1.0.0-alpha.9 86 7/12/2026
1.0.0-alpha.8 82 7/1/2026
1.0.0-alpha.7 98 6/16/2026
1.0.0-alpha.6 108 6/16/2026
1.0.0-alpha.5 85 6/14/2026
1.0.0-alpha.3 85 6/7/2026