MinimalApi.Extensions.WeChat 1.0.0-beta

This is a prerelease version of MinimalApi.Extensions.WeChat.
dotnet add package MinimalApi.Extensions.WeChat --version 1.0.0-beta
                    
NuGet\Install-Package MinimalApi.Extensions.WeChat -Version 1.0.0-beta
                    
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="MinimalApi.Extensions.WeChat" Version="1.0.0-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalApi.Extensions.WeChat" Version="1.0.0-beta" />
                    
Directory.Packages.props
<PackageReference Include="MinimalApi.Extensions.WeChat" />
                    
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 MinimalApi.Extensions.WeChat --version 1.0.0-beta
                    
#r "nuget: MinimalApi.Extensions.WeChat, 1.0.0-beta"
                    
#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 MinimalApi.Extensions.WeChat@1.0.0-beta
                    
#: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=MinimalApi.Extensions.WeChat&version=1.0.0-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MinimalApi.Extensions.WeChat&version=1.0.0-beta&prerelease
                    
Install as a Cake Tool

MinimalApi.Extensions.WeChat

微信 网站应用 openapi

准备

微信开放平台注册开发者账号,并拥有一个已审核通过的网站应用,并获得相应的AppID和AppSecret

安装

dotnet add package MinimalApi.Extensions.WeChat

配置

两种配置方式:

  1. 代码中填写
using MinimalApi.Extensions.WeChat;

services.AddWeChatService(o=>
{
	o.AppId = "xxx";
	o.AppSecret = "xxxxx";
});
  1. 配置文件中配置(提供IConfiguration)
{
	"WeChat":{
		"AppId" : "xxx",
		"AppSecret" : "xxxxxx"
	}
}
services.AddWeChatService(configuration.GetSection("WeChat"));

使用

app.MapGet("login",async ([FromService] WeChatService weChatService, string code)=>{
    var response = await weChatService.GetAccessTokenAsync(code);
	return Results.Ok(response);
});

api 列表

方法名 作用
GetAccessTokenAsync 通过code获取网站授权 access_token
RefreshAccessTokenAsync 刷新或续期网站授权 access_token 使用
GetUserInfoAsync 获取用户信息

说明

  1. 支持 aot 编译
  2. 注册了名字为 wx_http_clientHttpClient, 请不要覆盖注册, 通过 httpClientFactory.CreateClient(WeChatOptions.HTTP_CLIENT_NAME) 获取 HttpClient 实例
  3. 可以通过注入 IOptions<WeChatOptions> 获取配置
  4. 为了性能考虑,WeChatService 被注册为单例
Product Compatible and additional computed target framework versions.
.NET 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.  net10.0 was computed.  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.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MinimalApi.Extensions.WeChat:

Package Downloads
MinimalApi.Extensions

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-beta 185 4/20/2025