第一个线上版本

development
温天培 2 years ago
parent bf476d7d06
commit f2d16ceb65

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

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

@ -224,6 +224,32 @@
地区名 地区名
</summary> </summary>
</member> </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"> <member name="T:GDZZ.Application.BaseUserService">
<summary> <summary>
基础用户服务 基础用户服务
@ -952,27 +978,6 @@
<param name="input"></param> <param name="input"></param>
<returns></returns> <returns></returns>
</member> </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"> <member name="T:GDZZ.Application.RecruitMessageDto">
<summary> <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(); return await _rep.ToListAsync();
} }
} }
} }

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

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

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

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

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

Loading…
Cancel
Save