Myvas.AspNetCore.Weixin
9.0.0
dotnet add package Myvas.AspNetCore.Weixin --version 9.0.0
NuGet\Install-Package Myvas.AspNetCore.Weixin -Version 9.0.0
<PackageReference Include="Myvas.AspNetCore.Weixin" Version="9.0.0" />
<PackageVersion Include="Myvas.AspNetCore.Weixin" Version="9.0.0" />
<PackageReference Include="Myvas.AspNetCore.Weixin" />
paket add Myvas.AspNetCore.Weixin --version 9.0.0
#r "nuget: Myvas.AspNetCore.Weixin, 9.0.0"
#addin nuget:?package=Myvas.AspNetCore.Weixin&version=9.0.0
#tool nuget:?package=Myvas.AspNetCore.Weixin&version=9.0.0
Myvas.AspNetCore.Weixin
This solution is working around the Tencent WeChat (also known as Weixin) platform APIs, designed to streamline integration and enhance developer productivity.
微信公众平台/接口调用服务:在微信公众平台上申请服务号或订阅号后,经配置部署可提供自定义菜单、即时信息交流、微信网页授权、模板消息通知等接口调用及搭建站点。
获取配置参数 Options
微信公众平台:https://mp.weixin.qq.com
开发/基本配置/公众号开发信息
- 获取AppId,作为参数
<WeixinOptions>.AppId
- 获取AppSecret,作为参数
<WeixinOptions>.AppSecret
- 获取AppId,作为参数
开发/基本配置/服务器配置:修改设置 | 启用
- 在“服务器地址(URL)”中,填写地址: http://xxx.xxx/wx or https://xxx.xxx/wx,将二级虚拟路径(`"/wx"`)作为参数`<WeixinSiteOptions>.Path`
- 在“网站Token”中,填写一串较长的随机字符串,作为参数
<WeixinSiteOptions>.WebsiteToken
- 在“消息加解密密钥EncodingAESKey”中,若空则初始化一个,作为参数
<WeixinMessageProtectionOptions>.EncodingAESKey
- 在“消息加解密方式”中,建议选择“安全模式”。其他选项有"明文模式"和"兼容模式"。当且仅当您选择"安全模式"时,将参数
<WeixinMessageProtectionOptions>.StrictMode
设置为true
。
微信接口服务容器 WeixinBuilder
// (1.1) AddWeixinCore(...) to inject WeixinMemoryCacheProvider, IWeixinAccessTokenApi, IWeixinJsapiTicketApi, IWeixinCardTicketApi.
// (1.2) AddWeixin(...) to inject WeixinMemoryCachProvider and all APIs (see the list below).
services.AddWeixin(o => {
o.AppId = Configuration["Weixin:AppId"];
o.AppSecret = Configuration["Weixin:AppSecret"];
//o.Backchannel = _testServer.CreateClient(); // For testing using a fake TestServer
})
//(2.1) The default injection in AddWeixinCore and AddWeixin to provide a memory cache provider implemented IWeixinCacheProvider as default.
//.AddWeixinMemoryCacheProvider()
// (2.2) To replace with a better distribution cache provider. (recommended)
.AddWeixinRedisCacheProvider(...)
// (2.3) Or, replace with your implementation of IWeixinCacheProvider.
//.AddWeixinCacheProvider<TWeixinCacheProvider>()
;
- 微信接口服务注入
<IServiceCollection>.AddWeixin(Action<WeixinOptions>)
: 注入所有接口<IServiceCollection>.AddWeixinCore(Action<WeixinOptions>)
: 注入基础会话接口
- 基础会话接口:
- 数据管理接口:
IWeixinUserApi
:IWeixinUserProfileApi
:IWeixinUserGroupApi
:IWeixinGroupApi
:
- 其他业务接口:
IWeixinCommonApi
:IWeixinMenuApi
:IWeixinMediaApi
:IWeixinCustomerSupportApi
:IWeixinGroupMessageApi
:IWeixinQrcodeApi
:IWeixinWifiApi
:
- Cache providers:
- Memory cache provider:
AddWeixinMemoryCacheProvider
(Default injected inAddWeixin(...)
andAddWeixinCore(...)
) - Redis cache provider:
AddWeixinRedisCacheProvider(Action<RedisCacheOptions>)
- Customization of cache provider:
AddWeixinCacheProvider<TWeixinCacheProvider>
whereTWeixinCacheProvider
should implementIWeixinCacheProvider
forIWeixinExpirableValue
type.
- Memory cache provider:
微信公众号服务站点-中间件 WeixinSiteMiddleware
Use the
WeixinSiteMiddleware
:app.UseWeixinSite();
用于搭建微信公众号服务站点
- 接收微信公众号上行的消息和事件: Usage
- 发送(客服)响应类消息(须有上行消息,并在48小时内回复)
- 发送模板消息(须预先定义并申请消息模板),模板存储及管理
微信公众号服务站点-接口服务容器 WeixinSiteBuilder
Dependency Injection:
IServiceCollection
// <WeixinBuilder> // (1) Add services for .AddWeixinSite(o => { o.Path = Configuration.GetValue("Weixin:Path", "/wx"); // optional, default is "/wx" o.WebsiteToken = Configuration["Weixin:WebsiteToken"]; o.Debug = Configuration.GetValue<bool>("Weixin:Debug", false); // optional, default is false (Do NOT allow `微信web开发者工具(wechatdevtools)` and other browsers to access) }) // (2) 上下行消息加解密 .AddMessageProtection(o => { o.EncodingAESKey = Configuration["Weixin:EncodingAESKey"]; o.StrictMode = Configuration.GetValue<bool>("Weixin:StrictMode", false); // default is false (compatible with ClearText) // (1) 若填写错误,将导致您在启用“兼容模式”或“安全模式”时无法正确解密(及加密); // (2) 若您使用“微信公众平台测试号”部署,您应当注意到其不支持消息加解密,此时须用空字符串或不配置。 }) // (3.1) The default injection in AddWeixinSite to provide a debug output on received Weixin messages and events. //.AddWeixinDebugEventSink() // (3.2) To replace with an implementation with persistance in database. // 自动存储上行消息及事件 .AddWeixinEfCore<TWeixinDbContext>(o => { // 启用订阅者名单同步服务 o.EnableSyncForWeixinSubscribers = true; // default is false // 执行同步服务的时间间隔 o.SyncIntervalInMinutesForWeixinSubscribers = 10; // min is 3 minutes }) // 使用自定义数据类型 //.AddWeixinEfCore<TWeixinDbContext, TWeixinSubscriber>(o => ...) //.AddWeixinEfCore<TWeixinDbContext, TWeixinSubscriber, TKey>(o => ...) // (3.3) Or, replace with your implementation of IWeixinEventSink. //.AddWeixinEventSink<TWeixinCacheProvider>() // (4) 接口服务:发送客服响应消息 .AddWeixinPassiveResponseMessaging(o => { o.TrySmsOnFailed = true; // default is false }) // (5) 接口服务:发送模板消息 .AddWeixinTemplateMessaging(o => { o.MaxRetryTimes = 5; // default is 3 });
Demo
http://demo.auth.myvas.com (debian.9-x64)
For Developers
WeixinEfCoreEventSink
samples/WeixinSiteSample
- Install the EF Core Tools (globally)
dotnet tool install --global dotnet-ef
- Create Migrations (Run in dir: samples/WeixinSiteSample)
dotnet ef migrations add InitialCreate
- Visual Studio 2022
- Visual Studio Code
- C#, IntelliCode, .NET Install Tool (Microsoft)
- XML Tools (Josh Johnson)
- .NET Core User Secrets (Adrian Wilczyński)
- ResX Editor (Dominic Vonk)
- Markdown All in One (Yu Zhang)
- Testing on:
- 微信开发者工具
- 微信公众平台
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 3.1.4)
- Microsoft.Extensions.Caching.Memory (>= 3.1.4)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 3.1.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 3.1.4)
- System.Net.Http.Json (>= 3.2.0)
-
.NETStandard 2.0
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 3.1.4)
- Microsoft.Extensions.Caching.Memory (>= 3.1.4)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 3.1.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 3.1.4)
- System.Net.Http.Json (>= 3.2.0)
-
.NETStandard 2.1
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 3.1.4)
- Microsoft.Extensions.Caching.Memory (>= 3.1.4)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 3.1.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 3.1.4)
- System.Net.Http.Json (>= 3.2.0)
-
net5.0
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
- Microsoft.Extensions.Caching.Memory (>= 5.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 5.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 5.0.0)
- System.Net.Http.Json (>= 5.0.0)
-
net6.0
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 6.0.0)
- Microsoft.Extensions.Caching.Memory (>= 6.0.2)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- System.Net.Http.Json (>= 6.0.0)
-
net7.0
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.0)
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging (>= 7.0.0)
- System.Net.Http.Json (>= 7.0.0)
-
net8.0
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- System.Net.Http.Json (>= 8.0.0)
-
net9.0
- AutoMapper (>= 10.1.1)
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging (>= 9.0.0)
- System.Net.Http.Json (>= 9.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Myvas.AspNetCore.Weixin:
Package | Downloads |
---|---|
Myvas.AspNetCore.Weixin.Jssdk
Myvas.AspNetCore.Weixin.Jssdk |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
9.0.0 | 130 | 3/31/2025 | |
9.0.0-rc.7 | 53 | 3/29/2025 | |
9.0.0-rc.6 | 465 | 3/25/2025 | |
9.0.0-rc.5 | 482 | 3/25/2025 | |
9.0.0-rc.3 | 174 | 3/23/2025 | |
9.0.0-rc.1 | 200 | 3/19/2025 | |
9.0.0-preview.25 | 122 | 3/22/2025 | |
9.0.0-preview.24 | 185 | 3/21/2025 | |
9.0.0-preview.23 | 199 | 3/18/2025 | |
9.0.0-preview.22 | 194 | 3/18/2025 | |
9.0.0-preview.21 | 198 | 3/17/2025 | |
9.0.0-preview.18 | 213 | 3/17/2025 | |
9.0.0-preview.17 | 191 | 3/17/2025 | |
9.0.0-preview.14 | 118 | 3/15/2025 | |
9.0.0-preview.13 | 163 | 3/14/2025 | |
9.0.0-preview.12 | 196 | 3/13/2025 | |
9.0.0-preview.11 | 202 | 3/12/2025 | |
9.0.0-preview.10 | 200 | 3/12/2025 | |
9.0.0-preview.9 | 208 | 3/10/2025 | |
9.0.0-preview.8 | 203 | 3/9/2025 | |
9.0.0-preview.7 | 179 | 3/9/2025 | |
9.0.0-preview.6 | 250 | 3/6/2025 | |
9.0.0-preview.5 | 253 | 3/5/2025 | |
3.1.100.8 | 979 | 12/14/2019 | |
3.1.100.5 | 736 | 12/13/2019 | |
2.2.403 | 701 | 11/1/2019 |