- Region 表新增热度列,热门省份优先显示 - 区县下拉按地级市分组、已录区县优先、支持全省搜索 - 组选择内置一组至二十组 - 银行卡号独立行+粗体预览,开户行独立行 - 新增农户类型:农户/个体户/合作社/经营集体/公司 - 身份证正反面支持高拍仪/摄像头OCR与手机扫码上传,附件存本地/OSS - 新增农户头像采集组件(摄像头/本地上传),预留人脸识别收购扩展 - 同名村弹窗提醒(防选错乡镇) - 编辑窗体禁止遮罩/Esc误关,整体加宽适配高频操作 - 修复二维码局域网手机无法访问(监听0.0.0.0、局域网IP识别、Vite代理兜底)
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using System.IdentityModel.Tokens.Jwt;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using AgriculturalPlatform.Api.Models;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
namespace AgriculturalPlatform.Api.Services;
|
|
|
|
public class JwtService(IConfiguration config)
|
|
{
|
|
private readonly string _key = config["Jwt:Key"] ?? "AgriculturalPlatform-Default-Jwt-Secret-Key-2026!";
|
|
private readonly string _issuer = config["Jwt:Issuer"] ?? "AgriculturalPlatform";
|
|
private readonly string _audience = config["Jwt:Audience"] ?? "AgriculturalPlatform.Client";
|
|
|
|
public string Generate(User user)
|
|
{
|
|
var claims = new List<Claim>
|
|
{
|
|
new(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
|
new(ClaimTypes.Name, user.Username),
|
|
new(ClaimTypes.Role, user.Role.ToString()),
|
|
new("realName", user.RealName),
|
|
new("orgId", user.OrgId?.ToString() ?? "")
|
|
};
|
|
|
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_key));
|
|
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
|
var token = new JwtSecurityToken(
|
|
issuer: _issuer,
|
|
audience: _audience,
|
|
claims: claims,
|
|
expires: DateTime.Now.AddDays(7),
|
|
signingCredentials: creds);
|
|
|
|
return new JwtSecurityTokenHandler().WriteToken(token);
|
|
}
|
|
}
|