# Senparc.Weixin: A C# SDK for the Full WeChat Platform

> Senparc.Weixin is an Apache-licensed C# SDK that covers the WeChat ecosystem, including official accounts, mini-programs, enterprise WeChat, and WeChat Pay, across .NET Framework and .NET Core targets from .NET 3.5 through .NET 10. It manages AccessToken automatically and decouples entirely from ASP.NET, allowing use in console, desktop, Blazor, and MAUI applications.

**JeffreySu/WeiXinMPSDK** — 微信全平台 .NET SDK， Senparc.Weixin for C#，支持 .NET Framework 及 .NET Core、.NET 10.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.

- Repository: https://github.com/JeffreySu/WeiXinMPSDK
- Website: https://weixin.senparc.com
- Stars: 8,906 · Forks: 4,341
- Language: C#
- License: Apache-2.0
- Published: 2026-09-21 · Updated: 2026-09-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/jeffreysu-weixinmpsdk

## What Senparc.Weixin Solves and Who Uses It

The WeChat platform exposes a large set of HTTP APIs covering message routing for official accounts, client authorization for mini-programs, payment processing, and access token lifecycle management. Consuming these APIs in raw C# requires handling signature verification, JSON serialization to WeChat's format, and periodic AccessToken refresh, which expires every two hours. Without a wrapper, each of those concerns must be implemented per project.

Senparc.Weixin wraps all of it. The README describes it as covering the full WeChat platform, including official accounts (MP), mini-programs (WxOpen), mini-games, enterprise WeChat (Work), the WeChat Open Platform, WeChat Pay, JS-SDK, and Bluetooth/hardware integrations. The SDK has been maintained since 2013, with version 2026.8.7 released in August 2026.

The intended users are C# developers building server-side backends for WeChat products. The SDK works in any .NET environment: MVC, Razor, WebApi, Console, desktop executables, Blazor, MAUI, and background services. It has no external framework dependency and decouples from ASP.NET entirely.

## Module Structure: Each WeChat Platform Has Its Own Package

The SDK is split into independently published NuGet packages. Each WeChat platform platform maps to its own package: `Senparc.Weixin.MP` for official accounts, `Senparc.Weixin.WxOpen` for mini-programs, `Senparc.Weixin.Work` for enterprise WeChat, `Senparc.Weixin.TenPayV3` for the recommended WeChat Pay V3, and `Senparc.Weixin.Open` for the Open Platform.

For projects that use multiple modules, the README recommends installing `Senparc.Weixin.All`, which brings in all modules in one NuGet reference. Module-specific samples are available under the `/Samples/` folder in the repository, organized by platform (MP, WxOpen, Work, TenPayV2, TenPayV3). The README notes that all modules follow the same registration and configuration pattern, so learning one transfers directly to others.

Cache options are also modular: `Senparc.Weixin.Cache.Redis`, `Senparc.Weixin.Cache.CsRedis`, `Senparc.Weixin.Cache.Memcached`, and `Senparc.Weixin.Cache.Dapr` are available as separate NuGet packages for distributed environments.

## Three Lines to Start: Registering the SDK

The README demonstrates SDK initialization with three code segments, using a public account (MP) as the example.

First, add the SDK services in `Program.cs` above `builder.Build()`:

```csharp
builder.Services.AddSenparcWeixinServices(builder.Configuration);
```

Second, activate the SDK below `builder.Build()`:

```csharp
var registerService = app.UseSenparcWeixin(app.Environment, null, null,
    register => { },
    (register, weixinSetting) =>
    {
        register.RegisterMpAccount(weixinSetting, "account-name");
    });
```

Third, call any API from any location in the application:

```csharp
await CustomApi.SendTextAsync("AppId", "OpenId", "Hello World!");
```

The README states that the SDK manages the full AccessToken lifecycle automatically. Once an AppId is registered, the caller never passes an AccessToken; the SDK retrieves and refreshes it internally. The AppId and other credentials are read from `appsettings.json` through `Senparc.Weixin.Config.SenparcWeixinSetting`.

For projects using the older Startup.cs pattern, `AddSenparcWeixinServices` belongs in `ConfigureServices` and `UseSenparcWeixin` belongs in `Configure`.

## Handling Incoming Messages with CustomMessageHandler

WeChat official accounts deliver user messages and events to a developer endpoint via HTTP callbacks. The SDK processes those callbacks through a message handler class that the developer subclasses.

The README shows a `CustomMessageHandler` that extends `MessageHandler<DefaultMpMessageContext>`:

```csharp
public partial class CustomMessageHandler
    : MessageHandler<DefaultMpMessageContext>
{
    public CustomMessageHandler(Stream inputStream,
        PostModel postModel, int maxRecordCount = 0,
        bool onlyAllowEncryptMessage = false,
        IServiceProvider serviceProvider = null)
        : base(inputStream, postModel, maxRecordCount,
               onlyAllowEncryptMessage, null, serviceProvider)
    {
    }
}
```

Developers override methods corresponding to individual message types or event types. The README notes this same pattern applies to enterprise WeChat and mini-program customer service messages, with only the base class changing per platform. API namespace conventions follow the official WeChat API path structure, and parameter names align with WeChat's documentation to make source lookup straightforward.

## Limitations and Cases Where This SDK Does Not Fit

Senparc.Weixin is a server-side SDK. It does not provide a client library for running WeChat SDK calls from a mobile device or a browser. The mini-program frontend, which runs in WeChat's client environment, uses a different JavaScript SDK provided by Tencent. Senparc.Weixin handles the backend API that the mini-program communicates with.

WeChat Pay V2 is supported but the README explicitly marks it as not recommended, directing new projects to the V3 package instead. Projects inheriting V2 integrations should be aware that V2 is a maintenance-only path.

The SDK is specific to the WeChat and WeChat enterprise platforms. It does not cover other messaging platforms and cannot be repurposed as a general messaging SDK. For multi-channel applications that integrate both WeChat and other platforms, Senparc.Weixin addresses only the WeChat side.

## Senparc.Weixin vs Direct WeChat API Calls

The raw WeChat Open Platform provides HTTP endpoints that any HTTP client can call. The difference in using Senparc.Weixin is the elimination of the infrastructure code: signature verification on incoming webhooks, JSON deserialization into typed C# objects, AccessToken caching and refresh, retry logic, and error-code handling must all be written once per project when calling the raw API directly.

Senparc.Weixin makes those decisions for you. The AccessToken is managed automatically. API return types are typed C# objects rather than raw JSON. The message handler pattern enforces a consistent dispatch model for incoming webhook events.

The cost of that convenience is version coupling: when WeChat adds or modifies an API, the application must wait for the SDK to publish an updated NuGet package before using the new endpoint directly through typed methods. The README's module breakdown means that a WeChat Pay API change requires a new `Senparc.Weixin.TenPayV3` release, while the MP module can release independently.

## Maintenance History and Licensing

The README states that the project has been continuously maintained since 2013, which by 2026 represents over thirteen years of updates. The latest release is 2026.8.7, published on August 6, 2026. The last commit to the master branch was on 2026-09-10. Development follows the versioning convention of year.month.patch.

The SDK is licensed under Apache-2.0. Commercial use, modification, and redistribution are permitted under that license. The repository includes bilingual documentation: the primary README is in Chinese, and an English version is available at readme.en.md. Module-specific documentation lives under the `/docs/` directory, and online samples run at sdk.weixin.senparc.com.

The README announces that samples integrating AI scenarios are being progressively published. The `Samples with AI/` folder contains examples of AI chatbot WeChat integration. The repository also includes a benchmarks directory and an `eng/` directory for engineering tooling. Continuous integration runs through both Azure Pipelines (azure-pipelines.yml) and AppVeyor (appveyor.yml), covering the range of .NET target frameworks the SDK supports.

The SDK supports long text auto-shard sending, which the README describes as automatically splitting responses that exceed WeChat's single-message length limits into multiple sequential messages. This is documented in the release notes as a response to generative AI use cases that produce long output.

## Conclusion

Senparc.Weixin suits any .NET developer who needs to integrate WeChat official account messaging, mini-program backend, enterprise WeChat, or WeChat Pay into a C# application. The SDK's design assumes hosting on servers accessible to the WeChat platform webhook, so local development without a public endpoint requires a tunneling setup that the SDK itself does not provide. Before starting, confirm that the WeChat platform API version (V2 vs V3 for WeChat Pay) matches the NuGet package you install.

## FAQ

### How does Senparc.Weixin handle WeChat AccessToken?

The SDK manages AccessToken automatically throughout its lifecycle. Callers pass only the AppId; the SDK retrieves, caches, and refreshes the AccessToken internally. Configuration such as AppId and AppSecret is read from appsettings.json through SenparcWeixinSetting.

### Which NuGet package should I install to start with Senparc.Weixin?

For a single platform, install the module-specific package such as Senparc.Weixin.MP for official accounts or Senparc.Weixin.WxOpen for mini-programs. For projects using multiple WeChat platforms, install Senparc.Weixin.All to bring in all modules with one reference.

### Does Senparc.Weixin support WeChat Pay V3?

Yes. The WeChat Pay V3 module is available as the NuGet package Senparc.Weixin.TenPayV3, and the README recommends it for all new projects. The older V2 module remains available as Senparc.Weixin.TenPayV2 but is explicitly marked as not recommended.

## Sources

- [JeffreySu/WeiXinMPSDK on GitHub](https://github.com/JeffreySu/WeiXinMPSDK)
- [License: Apache-2.0](https://github.com/JeffreySu/WeiXinMPSDK/blob/master/LICENSE)
- [Project website](https://weixin.senparc.com)
- [README](https://github.com/JeffreySu/WeiXinMPSDK/blob/master/README.md)
- [Releases](https://github.com/JeffreySu/WeiXinMPSDK/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/jeffreysu-weixinmpsdk
