WeiXinAuthentication 1.0.1
See the version list below for details.
dotnet add package WeiXinAuthentication --version 1.0.1
NuGet\Install-Package WeiXinAuthentication -Version 1.0.1
<PackageReference Include="WeiXinAuthentication" Version="1.0.1" />
paket add WeiXinAuthentication --version 1.0.1
#r "nuget: WeiXinAuthentication, 1.0.1"
// Install WeiXinAuthentication as a Cake Addin #addin nuget:?package=WeiXinAuthentication&version=1.0.1 // Install WeiXinAuthentication as a Cake Tool #tool nuget:?package=WeiXinAuthentication&version=1.0.1
本文参考了 QQConnect
asp.net core2.0 QQ登录、微信登录
基于Microsoft.AspNetCore.Authentication.OAuth实现(aspnet/Security2.0)
微信开方平台 网站微信登录在这里申请
特别提醒,网站要接入微信登录(具体有两种情况:1.在微信客户端外浏览网站打开微信登录时是先显示一个二维码,用户使用微信客户端扫码后在微信客户端内会显示一个授权界面,用户授权后,网站会自动跳转到你设置的回调地址。2.在微信内浏览网站时用户微信登录,当用户点了微信登录后会直接转到授权界面,用户授权后,网站会自动跳转到你设置的回调地址)是在开放平台申请,必须要开通开发者资质,也就是说300RMB是必须的,不然创建的网站应用通过后也无法使用(可以先创建应用再申请资质,只不过开发者资质下来之前没法用)。
很多人不知道跑到微信公众平台申请测试帐号,告诉你没用的,网站应用使用微信登录只能在开放平台申请,而且在开发者资质下来之前测试都没法测试。那些跑去申请微信公众平台测试帐号的大概是被网上有些文章给误导了,微信公众平台的确有提供微信登录的接口,但是,此登录非彼登录,它这个只适用于在微信服务号内嵌网站使用的微信登录,只有服务号才有,订阅号是没有的。
总结一句话就是:微信开放平台和微信公众平台都有提供网站用微信登录的接口,前者适用于任何网站,后者只适用于微信服务号的内嵌网站。
使用方法
微信
//appsettings.json
{
"Authentication": {
"WeChat": {
"AppId": "你申请的微信应用AppID",
"AppSecret": "你申请的微信应用AppSecret"
}
},
//省略....
}
//Startup.cs
services.AddAuthentication().AddWeChat(wechatOptions => {
wechatOptions.AppId = Configuration["Authentication:WeChat:AppId"];
wechatOptions.AppSecret = Configuration["Authentication:WeChat:AppSecret"];
}) ;
注意如果你有多个后端服务器,需要使用真实的分布式缓存
services.AddAuthentication()
.AddWeChat(wechatOptions => {
wechatOptions.AppId = configuration["Authentication:WeChat:AppId"];
wechatOptions.AppSecret = configuration["Authentication:WeChat:AppSecret"];
//启用使用分布式缓存,一般不需要设定
wechatOptions.UseCachedStateDataFormat = true;
})
services.AddDistributedMemoryCache();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.