第一个线上版本

development
温天培 2 years ago
parent bf476d7d06
commit f2d16ceb65

@ -11,41 +11,41 @@ namespace GDZZ.Application.Entity
[Description("基础用户")]
public class BaseUser : DEntityBase
{
/// <summary>
/// 租户Id
/// </summary>
public long TenantId { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 用户类型
/// </summary>
public Int16 Type { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 头像链接
/// </summary>
public string AvatarUrl { get; set; }
/// <summary>
/// 用户状态
/// </summary>
public Int16 Status { get; set; }
/// <summary>
/// 微信用户ID
/// </summary>
public string OpenID { get; set; }
/// <summary>
/// 微信唯一ID
/// </summary>
public string WxOfficialOpenId { get; set; }
/// <summary>
/// 开放平台ID
/// </summary>
public string UnionId { get; set; }
/// <summary>
/// 租户Id
/// </summary>
public long TenantId { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 用户类型
/// </summary>
public Int16 Type { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 头像链接
/// </summary>
public string AvatarUrl { get; set; }
/// <summary>
/// 用户状态
/// </summary>
public Int16 Status { get; set; }
/// <summary>
/// 微信用户ID
/// </summary>
public string OpenID { get; set; }
/// <summary>
/// 微信唯一ID
/// </summary>
public string WxOfficialOpenId { get; set; }
/// <summary>
/// 开放平台ID
/// </summary>
public string UnionId { get; set; }
}
}

@ -24,7 +24,11 @@
<ItemGroup>
<Folder Include="Entity\" />
<Folder Include="Service\Auth\" />
<Folder Include="Service\Auth\DTO\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project>

@ -224,6 +224,32 @@
地区名
</summary>
</member>
<member name="F:GDZZ.Application.Service.Auth.AuthService._oauthConfig">
<summary>
获取配置文件
</summary>
</member>
<member name="T:GDZZ.Application.Service.LiveChat.ILiveChatService">
<summary>
即时聊天接口
</summary>
</member>
<member name="T:GDZZ.Application.Service.LiveChat.LiveChatService">
<summary>
即时聊天
</summary>
</member>
<member name="M:GDZZ.Application.Service.LiveChat.LiveChatService.CreateLinkCaht">
<summary>
创建聊天
</summary>
<returns></returns>
</member>
<member name="T:GDZZ.Application.Service.WXPay.IWXPayService">
<summary>
微信支付
</summary>
</member>
<member name="T:GDZZ.Application.BaseUserService">
<summary>
基础用户服务
@ -952,27 +978,6 @@
<param name="input"></param>
<returns></returns>
</member>
<member name="T:GDZZ.Application.Service.LiveChat.ILiveChatService">
<summary>
即时聊天接口
</summary>
</member>
<member name="T:GDZZ.Application.Service.LiveChat.LiveChatService">
<summary>
即时聊天
</summary>
</member>
<member name="M:GDZZ.Application.Service.LiveChat.LiveChatService.CreateLinkCaht">
<summary>
创建聊天
</summary>
<returns></returns>
</member>
<member name="T:GDZZ.Application.Service.WXPay.IWXPayService">
<summary>
微信支付
</summary>
</member>
<member name="T:GDZZ.Application.RecruitMessageDto">
<summary>
招聘消息输出参数

@ -0,0 +1,44 @@
using Furion.DataEncryption;
using Furion.EventBus;
using Furion.FriendlyException;
using Furion;
using GDZZ.Application.Entity;
using GDZZ.Core;
using GDZZ.Core.Entity;
using GDZZ.Core.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GDZZ.Application.Service.Auth
{
public class AuthService
{
private readonly SqlSugarRepository<BaseUser> Baseuser;
/// <summary>
/// 获取配置文件
/// </summary>
private readonly ThirdParty _oauthConfig;
public AuthService(SqlSugarRepository<BaseUser> Baseuser, IOptions<OAuthOptions> options)
{
Baseuser = this.Baseuser;
_oauthConfig = options.Value.Wechat;
}
}
}

@ -93,5 +93,8 @@ namespace GDZZ.Application
{
return await _rep.ToListAsync();
}
}
}

@ -3525,39 +3525,29 @@
AccessToken参数
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.OpenId">
<summary>
用户标识
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.TokenType">
<member name="P:GDZZ.Core.TokenModel.SessionKey">
<summary>
Token 类型
会话密钥
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.AccessToken">
<member name="P:GDZZ.Core.TokenModel.Unionid">
<summary>
AccessToken
平台唯一标识
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.RefreshToken">
<member name="P:GDZZ.Core.TokenModel.ErrCode">
<summary>
用于刷新 AccessToken 的 Token
错误码
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.Scope">
<member name="P:GDZZ.Core.TokenModel.Errmsg">
<summary>
此 AccessToken 对应的权限
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.ExpiresIn">
<summary>
AccessToken 过期时间
错误信息
</summary>
</member>
<member name="P:GDZZ.Core.TokenModel.ErrorDescription">
<member name="P:GDZZ.Core.TokenModel.OpenId">
<summary>
错误的详细描述
用户标识
</summary>
</member>
<member name="M:GDZZ.Core.AccessTokenModelModelExtensions.HasError(GDZZ.Core.TokenModel)">
@ -3593,7 +3583,7 @@
</member>
<member name="M:GDZZ.Core.WechatOAuth.GetAccessTokenAsync(System.String,System.String)">
<summary>
获取微信Token
换取JSCodeSessionKey
</summary>
<param name="code"></param>
<param name="state"></param>
@ -7027,7 +7017,7 @@
</member>
<member name="M:GDZZ.Core.Service.SysOauthService.WechatLoginCallback(System.String,System.String,System.String)">
<summary>
微信登录授权回调
微信登录换取jscode授权回调
</summary>
<param name="code"></param>
<param name="state"></param>

@ -7,47 +7,72 @@ namespace GDZZ.Core;
/// </summary>
public class TokenModel
{
/// <summary>
/// 用户标识
/// </summary>
[JsonPropertyName("openid")]
public string OpenId { get; set; }
/// <summary>
/// Token 类型
/// 会话密钥
/// </summary>
[JsonPropertyName("token_type")]
public string TokenType { get; set; }
[JsonPropertyName("session_key")]
public string SessionKey { get ;set; }
/// <summary>
/// AccessToken
/// 平台唯一标识
/// </summary>
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }
[JsonPropertyName("unionid")]
public string Unionid { get; set; }
/// <summary>
/// 用于刷新 AccessToken 的 Token
/// 错误码
/// </summary>
[JsonPropertyName("refresh_token")]
public string RefreshToken { get; set; }
[JsonPropertyName("errcode")]
public int ErrCode { get; set; }
/// <summary>
/// 此 AccessToken 对应的权限
/// 错误信息
/// </summary>
[JsonPropertyName("scope")]
public string Scope { get; set; }
[JsonPropertyName("errmsg")]
public string Errmsg { get; set; }
/// <summary>
/// AccessToken 过期时间
/// 用户标识
/// </summary>
[JsonPropertyName("expires_in")]
public dynamic ExpiresIn { get; set; }
[JsonPropertyName("openid")]
public string OpenId { get; set; }
/// <summary>
/// 错误的详细描述
/// </summary>
[JsonPropertyName("error_description")]
public string ErrorDescription { get; set; }
///// <summary>
///// Token 类型
///// </summary>
//[JsonPropertyName("token_type")]
//public string TokenType { get; set; }
///// <summary>
///// AccessToken
///// </summary>
//[JsonPropertyName("access_token")]
//public string AccessToken { get; set; }
///// <summary>
///// 用于刷新 AccessToken 的 Token
///// </summary>
//[JsonPropertyName("refresh_token")]
//public string RefreshToken { get; set; }
///// <summary>
///// 此 AccessToken 对应的权限
///// </summary>
//[JsonPropertyName("scope")]
//public string Scope { get; set; }
///// <summary>
///// AccessToken 过期时间
///// </summary>
//[JsonPropertyName("expires_in")]
//public dynamic ExpiresIn { get; set; }
///// <summary>
///// 错误的详细描述
///// </summary>
//[JsonPropertyName("errordescription")]
//public string ErrorDescription { get; set; }
}
public static class AccessTokenModelModelExtensions
@ -59,8 +84,6 @@ public static class AccessTokenModelModelExtensions
/// <returns></returns>
public static bool HasError(this TokenModel accessTokenModel)
{
return accessTokenModel == null ||
string.IsNullOrEmpty(accessTokenModel.AccessToken) ||
!string.IsNullOrEmpty(accessTokenModel.ErrorDescription);
return accessTokenModel == null || string.IsNullOrEmpty(accessTokenModel.Errmsg);
}
}

@ -14,7 +14,7 @@ namespace GDZZ.Core;
public class WechatOAuth : IWechatOAuth, ISingleton
{
private readonly string _authorizeUrl = "https://open.weixin.qq.com/connect/oauth2/authorize";
private readonly string _accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
private readonly string _accessTokenUrl = "https://api.weixin.qq.com/sns/jscode2session";
private readonly string _refreshTokenUrl = "https://api.weixin.qq.com/sns/oauth2/refresh_token";
private readonly string _userInfoUrl = "https://api.weixin.qq.com/sns/userinfo";
@ -46,23 +46,26 @@ public class WechatOAuth : IWechatOAuth, ISingleton
}
/// <summary>
/// 获取微信Token
/// 换取JSCodeSessionKey
/// </summary>
/// <param name="code"></param>
/// <param name="state"></param>
/// <returns></returns>
public async Task<TokenModel> GetAccessTokenAsync(string code, string state = "")
public async Task<TokenModel> GetAccessTokenAsync(string code, string state = "")
{
var param = new Dictionary<string, string>()
{
["appid"] = _oauthConfig.app_id,
["secret"] = _oauthConfig.app_key,
["code"] = code,
["js_code"] = code,
["grant_type"] = "authorization_code"
};
var accessTokenModel = await $"{_accessTokenUrl}?{param.ToQueryString()}".GetAsAsync<TokenModel>();
if (accessTokenModel.HasError())
throw Oops.Oh($"{ accessTokenModel.ErrorDescription}");
throw Oops.Oh($"{ accessTokenModel.Errmsg}");
//获取用户信息
return accessTokenModel;
}
@ -101,7 +104,7 @@ public class WechatOAuth : IWechatOAuth, ISingleton
};
var refreshTokenModel = await $"{_refreshTokenUrl}?{param.ToQueryString()}".GetAsAsync<TokenModel>();
if (refreshTokenModel.HasError())
throw Oops.Oh($"{ refreshTokenModel.ErrorDescription}");
throw Oops.Oh($"{ refreshTokenModel.Errmsg}");
return refreshTokenModel;
}
}

@ -86,7 +86,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
//var accessToken = await _jwtBearerManager.CreateTokenAdmin(user);
var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>
{
{ClaimConst.CLAINM_USERID, user.Id},
{ClaimConst.CLAINM_USERID, user.Id},
{ClaimConst.TENANT_ID, user.TenantId},
{ClaimConst.CLAINM_ACCOUNT, user.Account},
{ClaimConst.CLAINM_NAME, user.Name},

@ -35,7 +35,7 @@ public class SysOauthService : ISysOauthService, IDynamicApiController, ITransie
}
/// <summary>
/// 微信登录授权回调
/// 微信登录换取jscode授权回调
/// </summary>
/// <param name="code"></param>
/// <param name="state"></param>
@ -48,7 +48,7 @@ public class SysOauthService : ISysOauthService, IDynamicApiController, ITransie
throw Oops.Oh(error_description);
var accessTokenModel = await _wechatOAuth.GetAccessTokenAsync(code, state);
//var userInfoModel = await _wechatOAuth.GetUserInfoAsync(accessTokenModel.AccessToken, accessTokenModel.OpenId);
//var userInfoModel = await _wechatOAuth.GetUserInfoAsync(accessTokenModel, accessTokenModel.OpenId);
await _httpContext.Response.WriteAsJsonAsync(accessTokenModel);
}

@ -59,8 +59,8 @@
},
"OAuth": {
"Wechat": {
"app_id": "wx2959fdd3abc05362",
"app_key": "829f65b2be0652bcd50ea8cb820fd7fa",
"app_id": "wx422d9d8b4939f68c",
"app_key": "3d9a78ee2808836e63311cc5fa1ee317",
"redirect_uri": "http://127.0.0.1:56868/oauth/wechatcallback",
"scope": "snsapi_userinfo"
}

Loading…
Cancel
Save