Skip to content

An ASP.NET Core authentication middleware: WeixinOpen for https://open.weixin.qq.com (微信开放平台/微信扫码登录)

License

Notifications You must be signed in to change notification settings

myvas/AspNetCore.Authentication.WeixinOpen

Repository files navigation

Myvas.AspNetCore.Authentication Family

QQConnect GitHub (Pre-)Release Date NuGet

  • WeixinOpen: this repo

WeixinOpen GitHub (Pre-)Release Date NuGet

WeixinAuth GitHub (Pre-)Release Date NuGet

What's this?

An ASP.NET Core authentication middleware for https://open.weixin.qq.com (微信开放平台/微信扫码登录)

  • 须微信开放平台(open.weixin.qq.com)账号。
  • 用户可使用微信扫码并确认后登入网站。

How to Use?

0.Create account

在微信开放平台(https://open.weixin.qq.com)上创建网站应用,配置授权回调域(例如:auth.myvas.com ),记下AppId,获取AppSecret。

1.nuget

2.Configure

    app.UseAuthentication();

3.ConfigureServices

services.AddAuthentication()
    // using Myvas.AspNetCore.Authentication;
    .AddWeixinOpen(options => 
    {
        options.AppId = Configuration["WeixinOpen:AppId"];
        options.AppSecret = Configuration["WeixinOpen:AppSecret"];

        options.CallbackPath = "/signin-weixinopen"; //默认
    };
说明:
(1)同一用户在同一微信公众号即使重复多次订阅/退订,其OpenId也不会改变。
(2)同一用户在不同微信公众号中的OpenId是不一样的。
(3)若同时运营了多个微信公众号,可以在微信开放平台上开通开发者账号,并在“管理中心/公众账号”中将这些公众号添加进去,就可以获取到同一用户在这些公众号中保持一致的UnionId。

Dev

Demo