diff --git a/readme.en.md b/readme.en.md index 092122ad26..98b65b03c4 100644 --- a/readme.en.md +++ b/readme.en.md @@ -1,139 +1,221 @@ -Senparc.Weixin SDK + -Senparc.Weixin —— Wechat .NET SDK +Senparc.Weixin —— WeChat .NET SDK ================= -[![Build status](https://mysenparc.visualstudio.com/Senparc%20SDK/_apis/build/status/Weixin%20SDK/Senparc.Weixin%20master-pipeline-status)](https://mysenparc.visualstudio.com/Senparc%20SDK/_build/latest?definitionId=40) +[![Build status](https://mysenparc.visualstudio.com/Senparc%20SDK/_apis/build/status/Weixin%20SDK/Senparc.Weixin%20Dev-%E5%86%85%E9%83%A8-%E8%87%AA%E5%8A%A8-.Net6)](https://mysenparc.visualstudio.com/Senparc%20SDK/_build/latest?definitionId=36) [![NuGet](https://img.shields.io/nuget/dt/Senparc.Weixin.svg)](https://www.nuget.org/packages/Senparc.Weixin) [![GitHub commit activity the past week, 4 weeks, year](https://img.shields.io/github/commit-activity/4w/JeffreySu/WeiXinMPSDK.svg)](https://github.com/JeffreySu/WeiXinMPSDK/commits/master) +![Static Badge](https://img.shields.io/badge/.NET-8.0-blue) [![license](https://img.shields.io/github/license/JeffreySu/WeiXinMPSDK.svg)](http://www.apache.org/licenses/LICENSE-2.0) -[[中文]](readme.md) - -> Wechat is the most famous IM APP in China which has more than 1 billion active users and more than ten million Official Accounts. - -By using Senparc.Weixin SDK, you can develop all wechat platform applications, including Official Account, Mini Programm, Mini Game, Enterprise Account, Open Platform, Wechat Pay, JS-SDK, Wechat IoT/Bluetooth, etc. - -Now, Senparc.Weixin has been supported almost all of the API for Wechat's all modules. It supports mutipule .Net targets [.NET 3.5 / 4.0 / 4.5 / .NET Standard 2.x / .NET Core 2.x / .NET Core 3.x / .NET 6.0](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer). - -Senparc.Weixin SDK is the most widly used .NET Wechat SDK. Also it is one of the most popular .NET open source project in China. - -For more than 10 years, we have been keeping the project constantly updated, share the complete source code and design ideas without reservation. Hopefully more people will benefit from it, understand and disseminate the spirit of open source. Grateful to the friends who helped us along the way! - -If you like and hope us to continue to optimize this project, please give us a Star:) - -## Notice -> :trophy: 《[2020-2021 Outstanding Contributors of Senparc Developer Community Shortlist](https://github.com/JeffreySu/WeiXinMPSDK/issues/2454)》 has been published. Please check and register the information before 13/9/2021 10:24 AM :smile:
-> 🔒 [TenPay V3 Module](https://github.com/JeffreySu/WeiXinMPSDK/tree/master/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3) has been released!
-> ⚡ Sample has already supported for .NET 6.0, [Click Here](Samples/net6-mvc) !
-> 🍦 [file.api.weixin.qq.com Domain name officially disabled(2020.9.15)](https://developers.weixin.qq.com/community/develop/doc/0002245dcdc8c06f36fa6a47d56400), please update to the latest version!
- -## How to use documentation - -::: warning precondition -Requirement [Node.js](https://nodejs.org/en/) >= 8.6 -::: - -**Readings:** The Node version can be managed using NVM, Download[NVM](https://github.com/coreybutler/nvm-windows/releases)。 - -1. Install yarn using Node - - ``` bash - npm install -g yarn - ``` - -2. Installation project dependent run (project source root run) - - ``` bash - yarn install - ``` - -3. Run document project - - ``` bash - yarn docs:dev - ``` - -## Start:Separate document by module - -Module | URL -----|---- -Official Accounty (MP) | https://sdk.weixin.senparc.com/Docs/MP/ -Mini Program (WxOpen) | https://sdk.weixin.senparc.com/Docs/WxOpen/ -Entripise Account (Work) | https://sdk.weixin.senparc.com/Docs/Work/ -TenPay V3 (Recommended) | https://sdk.weixin.senparc.com/Docs/TenPayV3/ -TenPay V2 (Not Recommended) | https://sdk.weixin.senparc.com/Docs/TenPayV2/ - - - - -Index ----------------- - -* [SDK Modules](#sdk-modules) -* [Personalize your WeChat project Sample](#personalize-your-wechat-project-sample) -* [Resources](#resources) -* [:book: Senparc official tutorials](#senparc-official-tutorials) -* [Contribute Code](#contribute-code) -* [Develop with .net Core](#develop-with-net-core) -* [Follow Demo Official Account(SenparcRobot)](#follow-demo-official-accountsenparcrobot) -* [Project folder description (under src folder)](#project-folder-description-under-src-folder) -* [Sample folder description (under Samples folder)](#sample-folder-description-under-samples-folder) -* [Senparc.Weixin.MP.Sample Key Code](#senparcweixinmpsample-key-code) - * [/Controllers/WeixinController.cs](#controllersweixincontrollercs) - * [How to handle WeChat Official Account request?](#how-to-handle-wechat-official-account) -* [Use Nuget to install the project](#use-nuget-to-install-the-project) - * [How to handle WeChat Official Account?](#how-to-handle-wechat-official-account) - * [How to handle WeChat Mini Program (include Mini Game)?](#how-to-handle-wechat-mini-program-include-mini-game) - * [How to enhance the functionality of ASP.NET MVC project?](#how-to-enhance-the-functionality-of-aspnet-mvc-project) - * [How to handle WeChat Corporate Account?](#how-to-handle-wechat-corporate-account) - * [How to handle Corporate Wechat?](#how-to-handle-corporate-wechat) - * [How to handle Wechat Open Platform?](#how-to-handle-wechat-open-platform) - * [How to use distributed cache?](#how-to-use-distributed-cache) -* [How to develop Mini Program?](#how-to-develop-mini-program) - -* [Branch Description](#branch-description) -* [Thanks for Contributors](#thanks-for-contributors) -* [Donate](#donate) -* [Stargazers over time](#stargazers-over-time) -* [License](#license) +[![Senparc.Weixin](https://img.shields.io/nuget/vpre/Senparc.Weixin?label=Senparc.Weixin)](https://www.nuget.org/packages/Senparc.Weixin/) +[![Senparc.Weixin.MP](https://img.shields.io/nuget/vpre/Senparc.Weixin.MP?label=Senparc.Weixin.MP)](https://www.nuget.org/packages/Senparc.Weixin.MP/) +[![Senparc.Weixin.MP.Middleware](https://img.shields.io/nuget/vpre/Senparc.Weixin.MP.Middleware?label=Senparc.Weixin.MP.Middleware)](https://www.nuget.org/packages/Senparc.Weixin.MP.Middleware/) +[![Senparc.Weixin.MP.Mvc](https://img.shields.io/nuget/vpre/Senparc.Weixin.MP.Mvc?label=Senparc.Weixin.MP.Mvc)](https://www.nuget.org/packages/Senparc.Weixin.MP.Mvc/) +[![Senparc.Weixin.WxOpen](https://img.shields.io/nuget/vpre/Senparc.Weixin.WxOpen?label=Senparc.Weixin.WxOpen)](https://www.nuget.org/packages/Senparc.Weixin.WxOpen/) +[![Senparc.Weixin.WxOpen.Middleware](https://img.shields.io/nuget/vpre/Senparc.Weixin.WxOpen.Middleware?label=Senparc.Weixin.WxOpen.Middleware)](https://www.nuget.org/packages/Senparc.Weixin.WxOpen.Middleware/) +[![Senparc.Weixin.Work](https://img.shields.io/nuget/vpre/Senparc.Weixin.Work?label=Senparc.Weixin.Work)](https://www.nuget.org/packages/Senparc.Weixin.Work/) +[![Senparc.Weixin.Work.Middleware](https://img.shields.io/nuget/vpre/Senparc.Weixin.Work.Middleware?label=Senparc.Weixin.Work.Middleware)](https://www.nuget.org/packages/Senparc.Weixin.Work.Middleware/) +[![Senparc.Weixin.TenPay](https://img.shields.io/nuget/vpre/Senparc.Weixin.TenPay?label=Senparc.Weixin.TenPay)](https://www.nuget.org/packages/Senparc.Weixin.TenPay/) +[![Senparc.Weixin.TenPayV3](https://img.shields.io/nuget/vpre/Senparc.Weixin.TenPayV3?label=Senparc.Weixin.TenPayV3)](https://www.nuget.org/packages/Senparc.Weixin.TenPayV3/) +[![Senparc.Weixin.Open](https://img.shields.io/nuget/vpre/Senparc.Weixin.Open?label=Senparc.Weixin.Open)](https://www.nuget.org/packages/Senparc.Weixin.Open/) +[![Senparc.Weixin.AspNet](https://img.shields.io/nuget/vpre/Senparc.Weixin.AspNet?label=Senparc.Weixin.AspNet)](https://www.nuget.org/packages/Senparc.Weixin.AspNet/) +[![Senparc.Weixin.Cache.Redis](https://img.shields.io/nuget/vpre/Senparc.Weixin.Cache.Redis?label=Senparc.Weixin.Cache.Redis)](https://www.nuget.org/packages/Senparc.Weixin.Cache.Redis/) +[![Senparc.Weixin.Cache.CsRedis](https://img.shields.io/nuget/vpre/Senparc.Weixin.Cache.CsRedis?label=Senparc.Weixin.Cache.CsRedis)](https://www.nuget.org/packages/Senparc.Weixin.Cache.CsRedis/) +[![Senparc.Weixin.Cache.Memcached](https://img.shields.io/nuget/vpre/Senparc.Weixin.Cache.Memcached?label=Senparc.Weixin.Cache.Memcached)](https://www.nuget.org/packages/Senparc.Weixin.Cache.Memcached/) +[![Senparc.WebSocket](https://img.shields.io/nuget/vpre/Senparc.WebSocket?label=Senparc.WebSocket)](https://www.nuget.org/packages/Senparc.WebSocket/) -The library contains the source code (the Core logic is exactly the same) that includes .Net 3.5/4.0/4.5/.NET Standard 2.0/.NET Core/.NET 6/.NET 7. -* Use Visual Studio 2022 open Demo(support for all .NET Versions):.NET 7.0 - [Senparc.Weixin.Sample.Net7.sln](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/All/net7-mvc) (referenced source code, recommanded) -* Use other versions of Visual Studio to open the Demo (support .net 4.5 only) : -[Senparc.Weixin.MP.Sample.sln](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/All/net45-mvc) -* Use Visual Studio 2019 to open Console Demo(.NET Core):[Senparc.Weixin.MP.Sample.Consoles.vs2019.sln](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/All/console) - - -SDK Modules ----------------- - -| # | Module Libraries | DLL | Nuget | Support .NET Versions -|---|---------------------|------------------|-------|------------------------------- -| 1| Base Library |Senparc.Weixin.dll | [![Senparc.Weixin][1.1]][1.2]
[![Senparc.Weixin][nuget-img-base]][nuget-url-base] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 2| Official Account /
JSSDK
ect. |Senparc.Weixin.MP.dll | [![MP][2.1]][2.2]
[![MP][nuget-img-mp]][nuget-url-mp] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 3| [Mini Program
(s.p. Mini Game)
(indep. proj.)](https://github.com/JeffreySu/WxOpen) |Senparc.Weixin.WxOpen.dll | [![WxOpen][9.1]][9.2]
[![WxOpen][nuget-img-wxopen]][nuget-url-wxopen] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 4| Tencent Pay(TenPay) |Senparc.Weixin.TenPay.dll | [![TenPay][12.1]][12.2]
[![TenPay][nuget-img-tenpay]][nuget-url-tenpay] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 5| Tencent Pay(TenPay) V3 |Senparc.Weixin.TenPayV3.dll | [![TenPayV3][13.1]][13.2]
[![TenPay][nuget-img-tenpayv3]][nuget-url-tenpayv3] | ![.NET 4.5][net45N] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 6| ASP.NET MVC Extension |Senparc.Weixin.MP.MVC.dll         | [![MP.MVC][3.1]][3.2]
[![Mvc][nuget-img-mvc]][nuget-url-mvc] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 7| Corporate Account |Senparc.Weixin.QY.dll | [![QY][4.1]][4.2]
[![QY][nuget-img-qy]][nuget-url-qy] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 8| Corporate Wechat |Senparc.Weixin.Work.dll | [![Work][5.1]][5.2]
[![Work][nuget-img-work]][nuget-url-work] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 9| Open Platform |Senparc.Weixin.Open.dll | [![Open][6.1]][6.2]
[![Open][nuget-img-open]][nuget-url-open]| ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 10| Redis Distributed Cache |Senparc.Weixin.Cache.
Redis.dll | [![Cache.Redis][7.1]][7.2]
[![Redis][nuget-img-redis]][nuget-url-redis] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 11| Memcached
Distributed Cache |Senparc.Weixin.Cache.
Memcached.dll | [![Cache.Memcached][8.1]][8.2]
[![MC][nuget-img-mc]][nuget-url-mc] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] -| 12| [WebSocket
(indep. proj.)](https://github.com/JeffreySu/Senparc.WebSocket)  |Senparc.WebSocket.dll | [![Senparc.WebSocket][10.1]][10.2]
[![WebSocket][nuget-img-ws]][nuget-url-ws] | ![.NET 4.5][net45Y] ![.NET Standard 2.0/2.1][core20Y] ![.NET Core][netcore] ![.NET 5.0 / 6.0][net6] - - -#### Legend - -| ![.NET 4.5][net45Y] | ![.NET Standard 2.x][core20Y] | ![.NET Core][netcore] | ![.NET 5.0 / 6.0][net6] -|--|--|--|--| -| .NET 4.6.2 | .NET Standard 2.0 / 2.1 | .NET Core 2.x / 3.x | .NET 5.0 / .NET 6.0 / .NET 7.0 +[[中文]](readme.md) -> Tip:
-> 1. ![.NET 3.5][net35Y] ![.NET 4.0][net40Y] last stable release [click here](https://github.com/JeffreySu/WeiXinMPSDK/releases/tag/v16.6.15) (minimum .NET 4.5.1 support from November 7, 2021), since May 1, 2019 to stop updating. -> 2. The .NET Framework 4.5 update is scheduled to end on December 31, 2024. It's strongly advice you to use .NET 3.1 or .NET 6.0+ for new projects.
-> If you are still using .NET Framework, it is recommended that upgrade .NET Framework applications to .NET Framework 4.8+ before January 12, 2027, when .NET Framework 4.6.2 will be officially stopped Support ([see more] (https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework)) +With Senparc.Weixin, you can easily and quickly develop applications for the Wechat platform, including Wechat Official Accounts, Mini Programs, Mini Games, Enterprise Accounts, Open Platforms, Wechat Pay, JS-SDK, Wechat Hardware/Bluetooth, and more. The demo of this project is also suitable for beginners to learn .NET programming. + +Currently, Senparc.Weixin supports almost all Wechat platform modules and interfaces, and supports multiple frameworks such as .NET 3.5 / 4.0 / 4.5 / .NET Standard 2.x / .NET Core 2.x / .NET Core 3.x / .NET 6.0 / .NET 7.0 / .NET 8.0. It is compatible with all environments including MVC, Razor, WebApi, Console (command line), desktop applications (.exe), Blazor, MAUI, and background services, and is completely decoupled from external frameworks. + +Senparc.Weixin SDK is currently the most widely used Wechat .NET SDK and one of the most popular .NET open source projects in China. + +Since its inception in 2013, we have been continuously updating the project and sharing the complete source code and design ideas without reservation, hoping that more people can benefit from it, understand and spread the spirit of open source, and help the open source cause in China! We are grateful to all the friends who have helped us along the way! + +If you like this project and want us to continue improving it, please give us a ★Star :) + +## 🔔 Announcement + +> ⚡ Sample now supports .NET 8.0 (backward compatible), [click here to view](/Samples/All/net8-mvc)!
+> 🔒 [Wechat Pay V3 module (V1.0)](https://github.com/JeffreySu/WeiXinMPSDK/tree/master/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3) is now online! [Nuget](https://www.nuget.org/packages/Senparc.Weixin.TenPayV3)
+> 🎠 Fully support automatic segmentation and sending of long text messages, more: [《Auto Reply Long Text Messages to Adapt to AIGC Applications》](https://www.cnblogs.com/szw/p/weixin-large-text-response.html)
+ + + + +## 🌟 Start: Separate documentation for each module + Sample code examples + +Module | Link +----|---- +Official Account | https://sdk.weixin.senparc.com/Docs/MP/ +Mini Program | https://sdk.weixin.senparc.com/Docs/WxOpen/ +Enterprise Wechat | https://sdk.weixin.senparc.com/Docs/Work/ +Wechat Pay V3 (recommended) | https://sdk.weixin.senparc.com/Docs/TenPayV3/ +Wechat Pay V2 (not recommended) | https://sdk.weixin.senparc.com/Docs/TenPayV2/ + +> Note:
+> 1. The above module examples include both documentation and runnable code templates (just need to configure Wechat parameters without modifying any code). +> 2. The configuration, registration, and interface calling methods in the examples are consistent. Once you learn how to develop one module, you can apply the same knowledge to other modules. The Hello World example below uses Official Account as an example, but it can be extended to other modules as well. +> 3. More complete development documentation is provided in the [/docs](/docs/) directory for advanced development, [click here to view](/docs/). + +## 🚀 Hello World: Start your Wechat development journey with 3 lines of code! + +> Note:
+> 1. The following source code is located in the [`/Samples/MP/`](/Samples/MP/) folder, using Wechat Official Account as an example. Once you learn how to develop for Official Account, you can apply the same knowledge to other modules (Mini Program, Enterprise Wechat, Wechat Pay, etc.). +> 2. To view other module or integration examples, you can check the independent samples in the [`/Samples/`](/Samples/) folder or the integration samples in the [`/Samples/All/`](/Samples/All/) folder (for advanced users). + + +### Startup code (just 2 lines of code): +1. Add configuration above `builder.Build()` in Program.cs: +``` C# +builder.Services.AddSenparcWeixinServices(builder.Configuration); +``` +> Corresponds to ConfigureServices() method in Startup.cs. + +2. Enable configuration below `builder.Build()` in Program.cs: +``` C# +var registerService = app.UseSenparcWeixin(app.Environment, null, null, register => { }, + (register, weixinSetting) => +{ + // Register Official Account information (can be executed multiple times to register multiple Official Accounts) + register.RegisterMpAccount(weixinSetting, "Senparc Network Assistant Official Account"); +}); +``` +> Corresponds to Configure() method in Startup.cs. + +### Call advanced interfaces (just 1 line of code): +You can call interfaces (using Customer Service interface as an example) at any position in the program: +``` C# +await CustomApi.SendTextAsync("AppId", "OpenId", "Hello World!"); +``` +> Tips:
+> 1. Senparc.Weixin SDK automatically manages the AccessToken throughout its life cycle, so during development, you only need to provide the AppId without worrying about AccessToken expiration, etc. +> 2. Registration information such as AppId can be automatically obtained from `Senparc.Weixin.Config.SenparcWeixinSetting`, and the relevant parameters are configured in `appsettings.json`. +> 3. The above method also supports synchronous calls: Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(). +> 4. All interface namespaces are defined according to the official API path rules, and the parameter naming is kept as consistent as possible with the documentation (especially the return parameters), making it easier for developers to quickly locate and test, and reduce the likelihood of bugs. + +With the above code, you can call interfaces for all Wechat modules! Continue reading for more skills. + +### How to use the messaging capability of Official Accounts? +Official Accounts provide a messaging window by default, which can send different types of messages and interact with programs using text, images, voice, etc. + +The following example also applies to the messaging of Enterprise Wechat and Mini Program Customer Service, just two steps! + +#### Step 1: Create a custom MessageHandler to control message processing logic: + +
+CustomMessageHandler.cs + + +``` C# +using Senparc.NeuChar.Entities; +using Senparc.Weixin.MP.Entities; +using Senparc.Weixin.MP.Entities.Request; +using Senparc.Weixin.MP.MessageContexts; +using Senparc.Weixin.MP.MessageHandlers; + +namespace Senparc.Weixin.Sample.MP +{ + /// + /// Custom MessageHandler + /// Inherits from MessageHandler and overrides the corresponding request handling methods + /// + public partial class CustomMessageHandler : MessageHandler + { + public CustomMessageHandler(Stream inputStream, PostModel postModel, int maxRecordCount = 0, + bool onlyAllowEncryptMessage = false, IServiceProvider serviceProvider = null) + : base(inputStream, postModel, maxRecordCount, onlyAllowEncryptMessage, null, serviceProvider) + { + } + + /// + /// Default message for all unhandled types + /// + /// + public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage) + { + //ResponseMessageText can also be News or other types + var responseMessage = this.CreateResponseMessage(); + responseMessage.Content = $"You sent a message, but the program did not specify a processing procedure"; + return responseMessage; + } + + public override Task OnImageRequestAsync(RequestMessageImage requestMessage) + { + //Handle image requests... + } + + public override Task OnLocationRequestAsync(RequestMessageLocation requestMessage) + { + //Handle location requests... + } + } +} +``` +
+ + +#### Step 2: Request the CustomMessageHandler: + +We provide two ways to request the CustomMessageHandler: `Middleware` (recommended) and `Controller (or WebApi)`. You can choose either one. Taking Middleware as an example, after enabling the configuration in Program.cs, add the following code to register the MessageHandler: +``` C# +app.UseMessageHandlerForMp("/WeixinAsync", + (stream, postModel, maxRecordCount, serviceProvider) + => new CustomMessageHandler(stream, postModel, maxRecordCount, false, serviceProvider), + options + => + { + options.AccountSettingFunc = context => Senparc.Weixin.Config.SenparcWeixinSetting; + }); +``` + +At this point, you can use [https://YourDomain/WeixinAsync](https://sdk.weixin.senparc.com/WeixinAsync) to configure in the Wechat Official Account backend [Settings and Development]>[Basic Configuration]>Server Address (URL), and the corresponding Token is set in [appsettings.json](/Samples/MP/Senparc.Weixin.Sample.MP/appsettings.json#L36) (also applicable to Enterprise Wechat and Mini Program, please refer to the corresponding [Sample](/Samples/)). + +In addition, you can also use the `Controller (or WebApi)` method to have more precise control over the entire message processing process (or use it in .NET Framework), [click here to view](https://github.com/JeffreySu/WeiXinMPSDK/wiki/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8MessageHandler%E7%AE%80%E5%8C%96%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86%E6%B5%81%E7%A8%8B). + +Now you have mastered the basic skills required to develop for Wechat platforms. Keep reading for more resources: + + + +## 📇 More Indexes + +* [🏹 Libraries for each module](#-libraries-for-each-module) +* [💾 Source code project folder description (under src folder)](#-source-code-project-folder-description-under-src-folder) +* [🖥️ Samples folder description (under Samples folder)](#%EF%B8%8F-samples-folder-description-under-samples-folder) +* [🎨 Resources](#-resources) +* [📖 Senparc Official Book Tutorial](#-senparc-official-book-tutorial) +* [🖥️ Senparc Official Video Tutorial](#-senparc-official-video-tutorial) +* [🧪 Follow the test account (SenparcRobot)](#-follow-the-test-account-senparcrobot-to-experience-the-features) +* [✋ Contribute to the code](#-contribute-to-the-code) +* [👩‍🏫 How to develop using .NET Core](#-how-to-develop-using-net-core) +* [↕️ Install via Nuget](#-install-via-nuget) +* [🏬 How to deploy](#-how-to-deploy) +* [🍴 Description of important branches](#-description-of-important-branches) +* [🍟 Thanks to contributors](#-thanks-to-contributors) +* [💰 Donate](#-donate) +* [⭐ Star Count](#-star-count) +* [📎 License](#-license) + +This repository contains the source code for multiple versions including .NET Framework/.NET Standard 2.0+/.NET Core 3.1/.NET 6/.NET 7/.NET 8: + +* Use Visual Studio 2022 to open the demo (supports all versions): .NET 8.0 - [Senparc.Weixin.Sample.Net7.sln](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/All/net8-mvc) (includes recommended source code references) +* Use Visual Studio 2019 or higher to open the .NET Framework demo: [Senparc.Weixin.MP.Sample.Net45.sln](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/All/net45-mvc/) (does not include source code, only references the libraries) +* Use Visual Studio 2019 or higher to open the command line Console demo (.NET Core): [Senparc.Weixin.MP.Sample.Consoles.vs2019.sln](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/All/console) + +#### Legend +| ![.NET 4.6][net46Y] | ![.NET Standard 2.x][core20Y] | ![.NET 5.0 / 6.0 / 7.0 / 8.0][net8] +|--|--|--| +| .NET Framework 4.6.2+ | .NET Standard 2.0 / 2.1 | .NET 8.0, backward compatible with .NET 5.0-7.0 + +> Tip:
+> 1. Starting from May 1, 2019, .NET Framework 3.5 and 4.0 will no longer receive updates. The last stable version of .NET Framework 3.5 + 4.0 can be found [here](https://github.com/JeffreySu/WeiXinMPSDK/releases/tag/v16.6.15).
+> 2. Starting from April 3, 2022, .NET Framework 4.5 has been upgraded to 4.6.2. The last stable version of .NET Framework 4.5 can be found [here](https://github.com/JeffreySu/WeiXinMPSDK/releases/tag/v16.17.9).
+> 3. If you are still using .NET Framework, it is recommended to upgrade your application to .NET Framework 4.8+ by January 12, 2027, as official support for .NET Framework 4.6.2 will end by then ([source](https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework)). [1.1]: https://img.shields.io/nuget/v/Senparc.Weixin.svg?style=flat @@ -163,23 +245,11 @@ SDK Modules [13.1]: https://img.shields.io/nuget/v/Senparc.Weixin.TenPayV3.svg?style=flat [13.2]: https://www.nuget.org/packages/Senparc.Weixin.TenPayV3 -[net35Y]: https://img.shields.io/badge/3.5-Y-yellowgreen.svg -[net35N]: https://img.shields.io/badge/3.5-N-lightgrey.svg -[net40Y]: https://img.shields.io/badge/4.0-Y-yellowgreen.svg -[net40N]: https://img.shields.io/badge/4.0-N-lightgrey.svg -[net40N-]: https://img.shields.io/badge/4.0----lightgrey.svg -[net45Y]: https://img.shields.io/badge/4.5-Y-brightgreen.svg -[net45N]: https://img.shields.io/badge/4.5-N-lightgrey.svg -[net45N-]: https://img.shields.io/badge/4.5----lightgrey.svg -[net461Y]: https://img.shields.io/badge/4.6.1-Y-brightgreen.svg -[net461N]: https://img.shields.io/badge/4.6.1-N-lightgrey.svg -[coreY]: https://img.shields.io/badge/standard2.0-Y-brightgreen.svg -[coreN]: https://img.shields.io/badge/standard2.0-N-lightgrey.svg -[coreN-]: https://img.shields.io/badge/standard2.0----lightgrey.svg -[core20Y]: https://img.shields.io/badge/standard%202.x-Y-brightgreen.svg -[core20N]: https://img.shields.io/badge/standard%202.x-N-lightgrey.svg -[netcore]: https://img.shields.io/badge/.Net%20Core-Y-brightgreen.svg -[net6]: https://img.shields.io/badge/6.0-Y-brightgreen.svg +[net46Y]: https://img.shields.io/badge/.NET%20Framework%204.6+-Y-brightgreen.svg +[net46N]: https://img.shields.io/badge/.NET%20Framework%204.6+-N-lightgrey.svg +[net46N-]: https://img.shields.io/badge/.NET%20Framework%204.6+----lightgrey.svg +[core20Y]: https://img.shields.io/badge/.NET%20Standard2.x-Y-brightgreen.svg +[net8]: https://img.shields.io/badge/.NET%208.0-Y-brightgreen.svg [nuget-img-base]: https://img.shields.io/nuget/dt/Senparc.Weixin.svg @@ -207,507 +277,424 @@ SDK Modules [nuget-img-ws]: https://img.shields.io/nuget/dt/Senparc.WebSocket.svg [nuget-url-ws]: https://www.nuget.org/packages/Senparc.WebSocket -## Functional Support -* Supported all Wechat 8.x APIs, includes customize menu / personalized menu, template message, material APIs, group message, multi-customer service, TenPay, MerChant, cards APIs, ect. -* Supported Wechat Official Account, MiniProgram, MiniProgram-Game, Enterpaise Account, Open Platform modules. -* Supported user dialogue context, to solve application service can not use Session to handle users' dialogues. -* Fully supported latest APIs for Wechat Official Account, Corporate Account(Corporate Wechat), TenPay V2/V3, Open Platform. -* Supported Distributed Cache Strategy with high scalability. -* - -> All updates will ensure downward compatibility unless otherwise specified. So you can cover new DLLs directly or use Nuget to manage packages(highly recommend). - -## Personalize your WeChat project Sample - - Web version:view course。 - -WeChatSampleBuilder - - - -> Notice: using the WeChatSampleBuilder tool simply makes it easier for you to test and learn the Sample code, not to generate a complete production environment project. If you need to build a production environment project, refer to the full Demo or other tutorials. It is recommended to use an existing system framework, such as [NeuCharFramework](https://github.com/NeuCharFramework/NCF). - - -resources ----------------- -1. Senparc.Weixin SDK Official Site: https://weixin.senparc.com/ -2. Online Demo Site:https://sdk.weixin.senparc.com/ -3. Blog tutorial: https://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html -4. WeChat technology exchange community: https://weixin.senparc.com/QA -5. Online editing tool for Customize menu: https://sdk.weixin.senparc.com/Menu -6. Online test tool for Messages: https://sdk.weixin.senparc.com/SimulateTool -7. Online test tool for Cache:https://sdk.weixin.senparc.com/Cache/Test -8. chm documentation download:https://sdk.weixin.senparc.com/Document -9. Source code and the latest updates -: https://github.com/JeffreySu/WeiXinMPSDK -10. WeChat development resources: https://github.com/JeffreySu/WeixinResource -11. *Depth Analysis of WeChat Development* reading system:https://book.weixin.senparc.com -12. Buy *Depth Analysis of WeChat Development*:[https://item.jd.com/12220004.html](https://book.weixin.senparc.com/book/link?code=github-homepage-resource-en) -13. Video Course:[https://github.com/JeffreySu/WechatVideoCourse](https://github.com/JeffreySu/WechatVideoCourse) - - -* Technical communication QQ group: - -> 5th group(Official Account): 377815480 -> 14th Group(Video Course Student Group):588231256
-> (Official Account): 289181996
-> 10th Group(Distributed Cache): 246860933
-> 12th Group(Mini Program): 108830388
-> 16h Group(Open Platform): 860626938
-> *`the following groups are full:`*
-> `1st group:300313885(full),2nd group:293958349(full),3rd group:342319110(full)`
-> `4th group:372212092(full),6th group:425898825(full)`
-> `7th group:482942254(full),8th group:106230270(full),9th group:539061281(full)`
-> `11th group:553198593(full),13th group: 183424136(full),15th Group:289181996(full)` - -* Business contact QQ:498977166 - - - -If this project is useful to you, we welcome any form of donations from all parties, including participation in project code updates or feedback. Thank you! - - - -donate: [Enter](http://sdk.weixin.senparc.com#donate) - - -Senparc official tutorials ----------------- - - - - -> By Jeffrey Su and Senparc team took 2 years to complete the development of WeChat book have been published, the book's full name is: *Depth Analysis of WeChat Development: the efficient development of the Official Account and Mini Program*, the auxiliary reading system has been on the line: [BookHelper](http://book.weixin.senparc.com)。
-> Welcome to buy genuine books:[【Buy】](https://book.weixin.senparc.com/book/link?code=github-homepage)
-> The branch of code snapshot for the book published version [BookVersion1](https://github.com/JeffreySu/WeiXinMPSDK/tree/BookVersion1)。 - - - -### Follow Demo Official Account(SenparcRobot): -|Senparc Helper Official Account|Senparc Helper Mini-Program| BookHelper | -|--|--|--| -| | | | - - -## Develop with .Net Core - -> Current branch including .NET Framework 4.5 / 4.6.1 及 .NET Core 2.0 + 2.1 / .NET 5.0 + 6.0 full version codes. For the assembly which has been stoped update version, please see snapshot [release](https://github.com/JeffreySu/WeiXinMPSDK/releases).
-> .NET Framework 4.5 Demo under `/src/Samples/All/net45-mvc` directory,
-> .NET 6.0 (backward compatibility with.NET 5.0 and.NET Core 3.1 and lower versions) Demo under `/Samples/All/net6-mvc` directory.

-> Attention: in the above Samples, the Sample in 'net6-MVC' directly references the source code of each module, which can be compiled with 'Release' to generate a compatible SDK library for different versions of Senaprc.Weixin SDK. - - - -> All of the following introduction use the example of the .NET Framework 4.5. - -## Contribute Code - -> If you need to use or modify the program source code, recommended to Fork. We also welcome you to modify the generic version of Pull Request. - -1. Fork -2. Create your own branch (`git checkout -b my-new-feature`) -3. Submit your changes (`git commit -am'Added some feature'`) -4. Submit modify records to a remote warehouse (`git push origin `git` my-new-feature`) -5. And then go to the `my-new-feature` branch of the `git` on GitHub site, launch Pull Request -(Please refer to `Developer` branch, not directly submitted to the `master` branch) - - -## Project folder description (under src folder) - -| Folder | Description | -|--------|--------| -|[Senparc.WebSocket](src/Senparc.WebSocket) |WebSocket Module| -|[Senparc.Weixin.Cache](src/Senparc.Weixin.Cache) |Senparc.Weixin.Cache.Memcached.dll 、 Senparc.Weixin.Cache.Redis.dll Distributed Cache extension solutions| -|[Senparc.Weixin.AspNet](src/Senparc.Weixin.AspNet) |Senparc.Weixin.AspNet.dll library support for Web project| -|[Senparc.Weixin.MP.MvcExtension](src/Senparc.Weixin.MP.MvcExtension) |Senparc.Weixin.MP.MvcExtension.dll source code, extension for ASP.NET MVC | -|[Senparc.Weixin.MP](src/Senparc.Weixin.MP) |Senparc.Weixin.MP.dll, Official Account SDK source code| -|[Senparc.Weixin.MP.Middleware](src/Senparc.Weixin.MP.Middleware) |Senparc.Weixin.MP.Middleware.dll,Official Account Middleware source code| -|[Senparc.Weixin.Open](src/Senparc.Weixin.Open) |Senparc.Weixin.Open.dll, 3rd Open Platform SDK source code| -|[Senparc.Weixin.QY](src/Senparc.Weixin.QY) |Senparc.Weixin.QY.dll, Corporate Account SDK source code| -|[Senparc.Weixin.Work](src/Senparc.Weixin.Work) |Senparc.Weixin.Work.dll Corporate Wechat SDk source code| -|[Senparc.Weixin.Work.Middleware](src/Senparc.Weixin.Work.Middleware) |Senparc.Weixin.Work.Middleware.dll Corporate Wechat Middleware source code| -|[Senparc.Weixin.WxOpen](src/Senparc.Weixin.WxOpen) |Senparc.Weixin.WxOpen.dll Mini Program SDK source code. Include Mini Game.| -|[Senparc.Weixin.WxOpen.Middleware](src/Senparc.Weixin.WxOpen.Middleware) |Senparc.Weixin.WxOpen.Middleware.dll Mini Program Middleware source code.| -|[Senparc.Weixin](src/Senparc.Weixin) |all Senparc.Weixin.[x].dll base library source code| - - -## Sample folder description (under Samples folder) - -| Folder | Description | SDK Library Reference -|--------|--------|-------| -|[MP](Samples/MP/) | Official Account Sample | Source Code -|[TenPayV2](Samples/TenPayV2/) | Tencent Payment V1 & V2 Sample | Source Code -|[TenPayV3](Samples/TenPayV3/) | Tencent Payment V3(TenPay APIv3) Sample | Source Code -|[Work](Samples/Work/) | Enterprice Account Sample | Source Code -|[WxOpen](Samples/WxOpen/) | Mini-Program Sample | Source Code -|[Shared](Samples/Shared) | All Sample's common shared files -|[All](Samples/All/) | Including integration of all subordinate modules: Official Account, Mini-Program, Enterprice Account, Tencent Payment(V2 & V3 & APIv3). Recommended project references for integrating multiple platforms
(advanced references) | -| ┣ [All/net45-mvc](Samples/All/net45-mvc) |Demo, can be released directly(.NET Framework 4.5 + ASP.NET MVC)| Nuget Packages | Nuget Package -| ┣ [All/console](Samples/All/console) | Console Demo(.NET Core)| Source Code -| ┗ [All/net6-mvc](Samples/All/net6-mvc) |Demo, can be released directly(.NET 6.0), compatible with .NET 5.0 and .NET Core | Source Code - - -Senparc.Weixin.MP.Sample Key Code --------------- -> Note: This is MVC projct, you can learn corresponding file in WebForm project. - -### /Controllers/WeixinController.cs - -The following Token needs to be synchronized with the Token synchronization in the background Settings of the WeChat Official Account Site(https://mp.weixin.qq.com). You can set the Token string in database or config file like `Web.cofing`. It's strongly recommend to use complex string, because the request is easy to forge while the Token is cracked. - -```C# -public readonly string Token = "weixin"; -``` - -The following Action (Get) is used to receive and return the validation results of the WeChat background Url without any changes. Address such as http://domain/Weixin or http://domain/Weixin/Index -```C# -/// -/// WeChat background validation Url (Get request), such as http://weixin.senparc.com/weixin -/// -[HttpGet] -[ActionName("Index")] -public ActionResult Get(PostModel postModel, string echostr) -{ - if (CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token)) - { - return Content(echostr); //返回随机字符串则表示验证通过 - } - else - { - return Content("failed:" + postModel.Signature + "," - + MP.CheckSignature.GetSignature(postModel.Timestamp, postModel.Nonce, Token) + "。" + - "If you see this message in browser, that means this url address can be used in Wechat Official Account background setting for validation Url. Please note that the Token is consistent."); - } -} -``` -In above methods, PostModel is an entity including Signature, Timestamp, Nonce (by WeChat server via the incoming request Url parameter), AppId and Token, EncodingAESKey and a series of internal sensitive information (need to pass it in) entity class. PostModel also used in the rear. - - -The following Action (Post) used to receive Post request from WeChat server (usually initiated by the user), if necessary, here before you Get only provide WeChat background save Url validation, every Post must revalidate, otherwise it's easy to forge the request. - -```C# -/// -/// After the user sends the message, the WeChat platform automatically posts a request to this place and waits for the response XML -/// -[HttpPost] -[ActionName("Index")] -public ActionResult Post(PostModel postModel) -{ - if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token)) - { - return Content("Parameter error!"); - } - ... -} -``` -### How to handle WeChat Official Account request? - -Senparc.Weixin.MP provides two ways to process requests, [traditional methos](https://github.com/JeffreySu/WeiXinMPSDK/wiki/处理微信信息的常规方法) and [MessageHandler](https://github.com/JeffreySu/WeiXinMPSDK/wiki/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8MessageHandler%E7%AE%80%E5%8C%96%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86%E6%B5%81%E7%A8%8B) (recommended). - -The above two methods have been described in more detail in the wiki, which is a simple example of the MessageHandler method. - - -The MessageHandler process is very simple: -``` C# -[HttpPost] -[ActionName("Index")] -public ActionResult Post(PostModel postModel) -{ - if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token)) - { - return Content("Parameter error!"); - } - - postModel.Token = Token; - postModel.EncodingAESKey = EncodingAESKey;//Be consistent with your Settings in the background - postModel.AppId = AppId;//Be consistent with your Settings in the background - - - var messageHandler = new CustomMessageHandler(Request.InputStream, postModel);//Receive messages (first step) - - messageHandler.Execute();//Processing (step 2) - - return new FixWeixinBugWeixinResult(messageHandler);//Return (step 3) -} -``` -In addition to the postModel assignment, the receipt (step 1), processing (step 2), and return (step 3) will only need one line of code. - -CustomMessageHandler in the code above is a custom class that inherits from Senparc.Weixin.MP.MessageHandler.cs. MessageHandler is an abstract class that contains the request perform a variety of different types of abstract methods (such as text, voice, location, pictures, etc.), we only need to create your own CustomMessageHandler in each of these methods is implemented.The newly built CustomMessageHandler.cs is as follows: - -```C# -using System; -using System.IO; -using Senparc.Weixin.MP.MessageHandlers; -using Senparc.Weixin.MP.Entities; - -namespace Senparc.Weixin.MP.Sample.CustomerMessageHandler -{ - public class CustomMessageHandler : MessageHandler - { - public public CustomMessageHandler(Stream inputStream, PostModel postModel, int maxRecordCount = 0) - : base(inputStream, postModel, maxRecordCount) - { - - } - - public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage) - { - //ResponseMessageText can also be other types like News - var responseMessage = CreateResponseMessage(); - responseMessage.Content = "This message is from DefaultResponseMessage。"; - return responseMessage; - } - - public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage) - { - //... - } - - public override IResponseMessageBase OnVoiceRequest(RequestMessageVoice requestMessage) - { - //... - } - - //More OnXX methods that are not overridden will return the result in DefaultResponseMessage by default. - .... - } -} -``` - -OnTextRequest and OnVoiceRequest correspond to different request types, such as receiving text and voice. - -For example, we need to respond to text type requests, just perfect the OnTextRequest method: -```C# - public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage) - { - //TODO: the logic can be dealt with to the Service details, reference OnLocationRequest method or /Service/LocationSercice.cs - var responseMessage = CreateResponseMessage(); - responseMessage.Content = string.Format("You just sent the message:{0}", requestMessage.Content); - return responseMessage; - } -``` - -In this way, when the CustomMessageHandler executes the Messagehandler.execute(), it will automatically call the above code and return the ResponseMessage in the code to return the information if it finds that the type of the request information is Text. ResponseMessage can be any type under the IResponseMessageBase interface (including text, news, multimedia, etc.). - -Starting with v0.4.0, the MessageHandler adds support for user Session context, which can be used to resolve defects on the server that can't use Session to manage user sessions. Details:[User context WeixinContext and MessageContext](https://github.com/JeffreySu/WeiXinMPSDK/wiki/%E7%94%A8%E6%88%B7%E4%B8%8A%E4%B8%8B%E6%96%87WeixinContext%E5%92%8CMessageContext) - -Use Nuget to install the project --------------- -### How to handle WeChat Official Account? - -* Nuget Address: https://www.nuget.org/packages/Senparc.Weixin.MP - -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.MP -``` - - -### How to handle WeChat Mini Program (include Mini Game)? - -Senparc.Weixin.WxOpen encapsulates the message and API of WeChat mini programs, keeping the development process of the Official Account request consistent. This module also support Mini Game. - -* Nuget Address: https://www.nuget.org/packages/Senparc.Weixin.WxOpen - -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.WxOpen -``` - -### How to enhance the functionality of ASP.NET MVC Project? - -Senparc.Weixin.MP.MVC has done more optimization for ASP.NET MVC project, including convenient browser environment judgment, official bug fix, etc. - -* Nuget Address: https://www.nuget.org/packages/Senparc.Weixin.MP.MVC - -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.MP.MVC -``` - -### How to handle WeChat Corporate Account? - -Senparc.Weixin.QY.dll for `Corporate Account` encapsulation were conducted for the relevant functions, operation process remain the same with WeChat Official Account SDK (Senparc.Weixin.MP) . - -* Nuget Address: https://www.nuget.org/packages/Senparc.Weixin.QY - -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.QY -``` - -> Note: QY has been stopped updating with the WeChat Corporate Account and has been seamlessly ported to Work (Corporate WeChat). - - -### How to handle Corporate Wechat? - -Senparc.Weixin.Work.dll for `Corporate Wechat` encapsulation were conducted for the relevant functions, operation process remain the same with WeChat Official Account SDK (Senparc.Weixin.MP) and WeChat Corporate Account (Senparc.Weixin.QY.dll). - -* Nuget Address: https://www.nuget.org/packages/Senparc.Weixin.Work - -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.Work -``` - - -### How to handle Wechat Open Platform? - - -Senparc.Weixin.Open.dll is encapsulatied all Open Platform APIs , message operation process remain the same with WeChat Official Account SDK (Senparc.Weixin.MP), some other special message process please read the official document, then compares Demo in the Senparc.Weixin.MP.Sample project. - -* Nuget Address: https://www.nuget.org/packages/Senparc.Weixin.Open - -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.Open -``` - - -### How to use distributed cache? - -Senparc. Weixin SDK provides the perfect caching policy interface, use the default native cache implementation, it also provides a Redis and Memcached expansion plans, you can also add your own caching strategies according to the same rules. - - -* Redis Cache Extension package Nuget address:https://www.nuget.org/packages/Senparc.Weixin.Cache.Redis -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.Senparc.Weixin.Cache.Redis -``` - -* Memcached Cache Extension package Nuget address:https://www.nuget.org/packages/Senparc.Weixin.Cache.Memcached -* Package Manager Command: -``` -PM> Install-Package Senparc.Weixin.Senparc.Weixin.Cache.Memcached -``` - - -How to develop Mini Program? --------------- -The back-end architecture of the mini program is highly consistent with the Official Account, -Only use the Nuget installation[Senparc.Weixin.WxOpen](https://www.nuget.org/packages/Senparc.Weixin.WxOpen) to start your Mini Program develop. - -Senparc.Weixin.WxOpen currently contains all the information processing, AccessToken management, template message, QR code generation, etc. - - - - Welcome developers to Pull Request for modules that are not completed or need to be added. - - -Branch Description --------------- - -|  Branch   |     Description         -|-----------|--------------- -| master   | Officially published main branch, usually this branch is stable, can be used in production environment. -| Developer | 1, development branch, the branch for the Beta version, usually we submit the new version to this branch first, the stable version will push to the master branch. If you want to sneak peek in new function, you can use this branch.
2, this branch is compatible with the.net 4.5 /.net core /.net core 2.0 version, and it is recommended that Pull Request to this branch, not master - -| BookVersion1 | this branch is code snapshot for book *[Depth Analysis of WeChat Development](https://book.weixin.senparc.com/book/link?code=github-homepage2)* . -| DotNET-Core_MySQL | this branch shows the integration with [Pomelo.EntityFrameworkCore.MySql](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql) in .NET Core environment. -| NET4.0     | Support for .Net 4.0 only, this branch has stopped updating in 2017. The latest code of .Net 4.0 is updated with the master/Developer branch - -| NET3.5     | Support for.Net 3.5 only, which stopped updating in 2015. The latest code is updated with the master/Developer branch -| Developer-Senparc.SDK | This branch is used only for the Senparc team internal test, you can ignore this one. - - - -Thanks for Contributors --------------- -Thanks to the developers who have contributed to this project, you have not only perfected this project, but also made a contribution to Open Source Enterprise. Thank you! -[Click Here](https://github.com/JeffreySu/WeiXinMPSDK/blob/master/Contributors.md) to see the list. - -Donate --------------- -If this project is useful to you, we welcome any form of contributions, including participation in project code updates or feedback.Thank you! - -Donate: +## Feature Support + +* Most of the WeChat 8.x APIs are supported, including WeChat Pay, custom menu/personalized menu, template message interface, material upload interface, mass message interface, customer service interface, payment interface, WeChat store interface, card interface, invoice interface, etc. +* Support for WeChat Official Accounts, Mini Programs, Enterprise Accounts, Open Platforms, WeChat Pay, and other modules. +* Support for user session context (solving the problem of using Session to process user information on the server). +* Full support for the latest APIs of WeChat Official Accounts, Mini Programs, Enterprise Accounts (WeChat Work), WeChat Pay V2/V3, and Open Platforms. +* Support for distributed caching and caching strategy extension (default support: local cache, Redis, Memcached, can be freely extended), no need to worry about the type of cache used during development, can be freely switched in the configuration file or during runtime. + +> 1. The official APIs are perfectly integrated, and all upgrades will try to ensure backward compatibility unless otherwise specified. So you can safely use or directly upgrade (overwrite) the latest DLLs. It is recommended to use [NuGet](https://www.nuget.org/) for updates.
+> 2. You can also modify and compile the code yourself. Open the [Senparc.Weixin.Sample.Net6.sln](/Samples/All/net6-mvc/) or [Senparc.Weixin.Sample.Net8.sln](/Samples/All/net8-mvc/) solution to see all the source code. When the compilation mode is `Release`, a local NuGet package will be automatically generated (default generated in the `/src/BuildOutPut/` folder). + +## 💾 Explanation of Source Code Project Folders (under the src folder) + +
+Expand + + +| Folder | Description | +|--------|--------| +|[Senparc.WebSocket](src/Senparc.WebSocket/)|WebSocket module| +|[Senparc.Weixin.Cache](src/Senparc.Weixin.Cache) |Senparc.Weixin.Cache.Memcached.dll, Senparc.Weixin.Cache.Redis.dll, and other distributed cache extension solutions| +|[Senparc.Weixin.AspNet](src/Senparc.Weixin.AspNet) |Senparc.Weixin.AspNet.dll, a class library specifically for web support| +|[Senparc.Weixin.MP.MvcExtension](src/Senparc.Weixin.MP.MvcExtension) |Senparc.Weixin.MP.MvcExtension.dll source code, an extension package for MVC projects | +|[Senparc.Weixin.MP](src/Senparc.Weixin.MP) |Senparc.Weixin.MP.dll WeChat Official Account SDK source code| +|[Senparc.Weixin.MP.Middleware](src/Senparc.Weixin.MP.Middleware) |Senparc.Weixin.MP.Middleware.dll WeChat Official Account message middleware source code| +|[Senparc.Weixin.Open](src/Senparc.Weixin.Open) |Senparc.Weixin.Open.dll Third-party Open Platform SDK source code| +|[Senparc.Weixin.TenPay](src/Senparc.Weixin.TenPay) |Senparc.Weixin.TenPay.dll & Senparc.Weixin.TenPayV3.dll source code for WeChat Pay [V2](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay) and [V3](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3)| +|[Senparc.Weixin.Work](src/Senparc.Weixin.Work) |Senparc.Weixin.Work.dll Enterprise WeChat SDK source code| +|[Senparc.Weixin.Work.Middleware](src/Senparc.Weixin.Work.Middleware) |Senparc.Weixin.Work.Middleware.dll Enterprise WeChat message middleware source code| +|[Senparc.Weixin.WxOpen](src/Senparc.Weixin.WxOpen) |Senparc.Weixin.WxOpen.dll WeChat Mini Program SDK source code, including Mini Games| +|[Senparc.Weixin.WxOpen.Middleware](src/Senparc.Weixin.WxOpen.Middleware) |Senparc.Weixin.WxOpen.Middleware.dll WeChat Mini Program message middleware source code, including Mini Games| +|[Senparc.Weixin](src/Senparc.Weixin) |Source code for all Senparc.Weixin.[x].dll basic libraries| +
+ +[Enter Folder](/src/) + +## 🖥️ Explanation of Samples Folder (under the Samples folder) + +The usage of all modules in the Senparc.Weixin SDK is highly consistent, including the configuration process, AccessToken management, message processing, service messages, API calls, etc. You only need to refer to the usage of any module (it is recommended to start with `Official Accounts` or `Mini Programs`), and you can apply the same principles to other modules. + +From the following samples, you can learn about the configuration and usage of each independent module. Just open the `.sln` solution file in the corresponding folder to view the source code and run it to see the documentation. The `All` folder contains more comprehensive and advanced feature demonstrations. + +| Folder | Description | SDK Reference Method | +|--------|--------|----| +|[MP](/Samples/MP/) | Official Accounts | NuGet Package +|[TenPayV2](/Samples/TenPayV2/) | WeChat Pay V1 and V2 | NuGet Package +|[TenPayV3](/Samples/TenPayV3/) | WeChat Pay V3 (TenPay APIv3) | NuGet Package +|[Work](/Samples/Work/) | Enterprise Accounts | NuGet Package +|[WxOpen](/Samples/WxOpen/) | Mini Programs | NuGet Package +|[Shared](/Samples/Shared) | Shared files required by all samples +|[All](/Samples/All/) | A mixed scenario demonstration that includes all functions of WeChat Official Accounts, Mini Programs, WeChat Pay, Enterprise Accounts, etc., recommended for projects that integrate multiple platforms or require deep development (advanced) | +| ┣ [All/console](/Samples/All/console) |Command Line Console Demo (.NET Core)| NuGet Package +| ┣ [All/net45-mvc](/Samples/All/net45-mvc) |Demo that can be directly published and used (.NET Framework 4.5 + ASP.NET MVC)| NuGet Package +| ┣ [All/net6-mvc](/Samples/All/net6-mvc) |Demo that can be directly published and used (.NET 6.0), compatible with .NET 5.0 and .NET Core | Source Code +| ┣ [All/net7-mvc](/Samples/All/net7-mvc) |Demo that can be directly published and used (.NET 7.0), compatible with .NET 5.0, 6.0, and .NET Core | Source Code +| ┗ [All/net8-mvc](/Samples/All/net8-mvc) |Demo that can be directly published and used (.NET 8.0), compatible with .NET 5.0, 6.0, 7.0, and .NET Core | Source Code + +[Enter Samples Folder](/Samples/) + + + + + + + +## 🎨 Resources + +1. Official website: https://weixin.senparc.com/ +2. Online demo (for .NET 8.0, backward compatible with .NET 6.0, 7.0, and .NET Core): https://sdk.weixin.senparc.com/ +3. WeChat development tutorials: https://www.cnblogs.com/szw/p/weixin-course-index.html +4. WeChat technical community: https://weixin.senparc.com/QA +5. Custom menu online editor: https://sdk.weixin.senparc.com/Menu +6. Online message testing tool: https://sdk.weixin.senparc.com/SimulateTool +7. Cache testing tool: https://sdk.weixin.senparc.com/Cache/Test +8. chm help document download: https://sdk.weixin.senparc.com/Document +9. Source code and latest updates: https://github.com/JeffreySu/WeiXinMPSDK +10. WeChat development resource collection: https://github.com/JeffreySu/WeixinResource +11. Auxiliary system for reading "In-depth Analysis of WeChat Development": https://book.weixin.senparc.com +12. Purchase "In-depth Analysis of WeChat Development": [https://item.jd.com/12220004.html](https://book.weixin.senparc.com/book/link?code=github-homepage-resource) +13. "Rapid Development of WeChat Official Accounts and Mini Programs" video tutorial: [https://github.com/JeffreySu/WechatVideoCourse](https://github.com/JeffreySu/WechatVideoCourse) + +* Technical communication QQ groups: + +>Group 1 (Official Accounts): 300313885
+>Group 14 (Video Course Students): 588231256
+>Group 10 (Distributed Cache): 246860933
+>Group 12 (Mini Programs): 108830388
+>Group 16 (Open Platform): 860626938
+>*`The following groups are full:`*
+>`Group 2: 293958349 (Full), Group 3: 342319110 (Full)`
+>`Group 4: 372212092 (Full), Group 5: 377815480 (Full), Group 6: 425898825 (Full)`
+>`Group 7: 482942254 (Full), Group 8: 106230270 (Full), Group 9: 539061281 (Full)`
+>`Group 11: 553198593 (Full), Group 13: 183424136 (Open Platform, Full), Group 15: 289181996 (Full)`
+ +* Business contact QQ: 498977166 + + + +If this project is helpful to you, we welcome any form of donation or participation in code updates and feedback. Thank you! + +Donation: [Enter](http://sdk.weixin.senparc.com#donate) + +## 📖 Senparc Official Book Tutorial + + + +> The Wechat development book, titled "In-Depth Analysis of Wechat Development: Efficient Development Secrets for Official Accounts and Mini Programs," completed by Jeffrey Su and the Senparc team after 2 years of effort, has been published. The book comes with an auxiliary reading system: [BookHelper](http://book.weixin.senparc.com).
+> Welcome to purchase the genuine book: [【Buy Genuine】](https://book.weixin.senparc.com/book/link?code=github-homepage)
+> The code snapshot of the book's publication version is in the branch [BookVersion1](https://github.com/JeffreySu/WeiXinMPSDK/tree/BookVersion1). + + +## 💻 Senparc Official Video Tutorial + +> In order to help everyone understand Wechat development details more intuitively and learn Wechat development and various tricks in .NET development process, we have established the "Senparc Classroom" group and launched Wechat development video courses, which cover the following two parts:
+> 1. Wechat development basic skills
+> 2. Case study of official accounts and mini programs
+> +> The total course duration is 60 lessons, with additional episodes.
+> Currently, the videos are available on NetEase Cloud Classroom, with well-produced content and abundant materials. The course has been selected as an "A" level course. [【Watch Videos】](https://book.weixin.senparc.com/book/videolinknetease?code=github-homepage), [【View Course Code and Slides】](https://github.com/JeffreySu/WechatVideoCourse). + + +## 🧪 Follow the test account to experience the functions (SenparcRobot): + +|Senparc Network Assistant Official Account|Senparc Network Assistant Mini Program|BookHelper| +|--|--|--| +| | | | + + +## ✋ Contribute Code + +> If you need to use or modify the source code of this project, it is recommended to Fork first. You are also welcome to submit a Pull Request for the general version you modified. + +1. Fork +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Added some feature'`) +4. Push to the remote `git` repository (`git push origin my-new-feature`) +5. Go to the `my-new-feature` branch of your `git` remote repository on the github website and submit a Pull Request +(Submit to the `Developer` branch instead of the `master` branch directly) + + + + +## 👩‍🏫 How to develop with .NET Core + +> The current branch includes the full version of .NET Framework 4.6.2+ and .NET 6.0/7.0/8.0 code (snapshot of versions that are no longer updated can be found in [release](https://github.com/JeffreySu/WeiXinMPSDK/releases)).
+> The Demo for .NET Framework is located in the `/src/Samples/All/net45-mvc` directory, and
+> 【Recommended】The Demo for .NET 8.0 (compatible with .NET 5.0, 6.0, 7.0, and .NET Core 3.1 and lower versions) is located in the `/Samples/All/net8-mvc` directory.

+> Note:
+> 1. In the above Samples, the `net8-mvc` Sample directly references the source code of each module, and can generate a Senaprc.Weixin SDK library compatible with different versions after being compiled with `Release`.
+> 2. You can also use the Demo for .NET 6.0 (compatible with .NET 5.0 and .NET Core 3.1 and lower versions) located in the `/Samples/All/net6-mvc` directory if you want. + +## ↕️ Install via Nuget to the project + +The Nuget installation methods for each module: [Installing the SDK into the project using Nuget](https://github.com/JeffreySu/WeiXinMPSDK/wiki/Installing-the-SDK-into-the-project-using-Nuget) + +## 🏬 Deployment guide + +### 1) Deploy to Azure App Service + +[App Service](https://docs.microsoft.com/zh-cn/azure/app-service/azure-web-sites-web-hosting-plans-in-depth-overview) is a Web service launched by Microsoft Azure, which has good support for .NET. The deployment steps are detailed in: [Deploy the Wechat site to Azure](https://github.com/JeffreySu/WeiXinMPSDK/wiki/Deploy-the-Wechat-site-to-Azure). + +### 2) Deploy to any server via FTP + +Install an FTP service (FileZilla Server is recommended) on the Web server, and directly upload the compiled code from the local machine (the corresponding code in the [Samples](https://github.com/JeffreySu/WeiXinMPSDK/tree/master/Samples) is [Senparc.Weixin.Sample.Net7](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/net7-mvc), [Senparc.Weixin.Sample.Net6](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/net6-mvc), or [Senparc.Weixin.Sample.NetCore3](https://github.com/JeffreySu/WeiXinMPSDK/tree/Developer/Samples/netcore3.1-mvc)). After compilation, you can use it directly without modifying the code. If you use Azure App Service or other cloud services, FTP is usually enabled as well. + + + + +## 🍴 Important Branches + +|  Branch   |     Description         +|-----------|--------------- +| master   | The main branch for official releases. This branch is usually more stable and can be used in production environments. +| Developer | 1. The development branch. This branch is usually the Beta version, and new versions are developed in this branch before being pushed to the master branch. If you want to get a sneak peek of new features, you can use this branch.
2. This branch is compatible with .NET 4.5 / .NET Core / .NET Core 2.0 versions at the same time. It is recommended to submit Pull Requests for code to this branch instead of the master branch. +| BookVersion1 | This branch is a code snapshot of the book [In-Depth Analysis of Wechat Development: Efficient Development Secrets for Official Accounts and Mini Programs](https://book.weixin.senparc.com/book/link?code=github-homepage2) publication. +| DotNET-Core_MySQL | This branch is a demonstration branch for integrating [Pomelo.EntityFrameworkCore.MySql](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql) framework in .NET Core environment. +| NET4.0     | Branch that only supports .NET 4.0. This branch was stopped updating in 2017. The latest code for .NET 4.0 is synchronized with the master / Developer branch. +| NET3.5     | Branch that only supports .NET 3.5. This branch was stopped updating in 2015. The latest code for .NET 3.5 is synchronized with the master / Developer branch. +| Developer-Senparc.SDK | This branch is only used for internal testing of the Senparc team and can be ignored. + + +## 🍟 Acknowledgments + +Thanks to the developers who contributed to this project. You have not only improved this project, but also made a contribution to the Chinese open source community. Thank you! The list can be found [here](https://github.com/JeffreySu/WeiXinMPSDK/blob/master/Contributors.md). + +## 💰 Donations + +If this project is useful to you, we welcome any form of donation, including participating in project code updates or providing feedback. Thank you! + +Donate: + [![donate](http://sdk.weixin.senparc.com/Images/T1nAXdXb0jXXXXXXXX_s.png)](http://sdk.weixin.senparc.com#donate) -## Stargazers over time +## ⭐ Star Quantity Statistics + [![starcharts stargazers over time](https://starchart.cc/JeffreySu/WeiXinMPSDK.svg)](https://starchart.cc/JeffreySu/WeiXinMPSDK) +## 📎 License -License --------------- Apache License Version 2.0 ``` @@ -724,3 +711,4 @@ either express or implied. See the License for the specific language governing p and limitations under the License. ``` Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md +