diff --git a/CoreCms.Net.Auth/HttpContextUser/AspNetUser.cs b/CoreCms.Net.Auth/HttpContextUser/AspNetUser.cs index 9538aa15..f6710185 100644 --- a/CoreCms.Net.Auth/HttpContextUser/AspNetUser.cs +++ b/CoreCms.Net.Auth/HttpContextUser/AspNetUser.cs @@ -29,6 +29,7 @@ namespace CoreCms.Net.Auth.HttpContextUser public string Name => _accessor.HttpContext.User.Identity.Name; public int ID => GetClaimValueByType("jti").FirstOrDefault().ObjectToInt(); + public string OpenId => GetClaimValueByType("nameid").FirstOrDefault(); public bool IsAuthenticated() { diff --git a/CoreCms.Net.Auth/HttpContextUser/IHttpContextUser.cs b/CoreCms.Net.Auth/HttpContextUser/IHttpContextUser.cs index a43f72ff..150595b0 100644 --- a/CoreCms.Net.Auth/HttpContextUser/IHttpContextUser.cs +++ b/CoreCms.Net.Auth/HttpContextUser/IHttpContextUser.cs @@ -19,6 +19,7 @@ namespace CoreCms.Net.Auth.HttpContextUser { string Name { get; } int ID { get; } + string OpenId { get; } bool IsAuthenticated(); IEnumerable GetClaimsIdentity(); List GetClaimValueByType(string ClaimType); diff --git a/CoreCms.Net.Services/Pay/WeChatPayServices.cs b/CoreCms.Net.Services/Pay/WeChatPayServices.cs index 8a34fbf7..5b928667 100644 --- a/CoreCms.Net.Services/Pay/WeChatPayServices.cs +++ b/CoreCms.Net.Services/Pay/WeChatPayServices.cs @@ -121,8 +121,15 @@ namespace CoreCms.Net.Services return jm; } + if (!string.IsNullOrEmpty(_user.OpenId) && _user.OpenId != user.openid) + { + openId = _user.OpenId; + } + else + { + openId = user.openid; + } - openId = user.openid; } var notifyUrl = config.notifyUrl.EndsWith("/") ? config.notifyUrl + "m-" + config.appId : config.notifyUrl + "/m-" + config.appId; diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index ab32041a..d6f86144 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -248,6 +248,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var claims = new List { new Claim(ClaimTypes.Name, user.nickName), new Claim(JwtRegisteredClaimNames.Jti, user.id.ToString()), + new Claim(JwtRegisteredClaimNames.NameId, response.OpenId), new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_permissionRequirement.Expiration.TotalSeconds).ToString(CultureInfo.InvariantCulture)) }; //用户标识