Files
StoreWeb/Modules/Store.Shops/Services/ShopManagementService.Authorization.cs
T
2026-10-29 11:34:35 +08:00

34 lines
1.3 KiB
C#

using System.Text.Json;
using MAX.Framework.Commons;
using MAX.Framework.Validation;
using Microsoft.Extensions.Configuration;
using Store.Shops.Dtos;
using Store.Shops.Entities;
namespace Store.Shops.Services;
public sealed partial class ShopManagementService
{
public async Task<IReadOnlyList<PddClientInfo>> GetPddClients()
{
await Actor();
var clients = configuration.GetSection("Shops:PddClients").Get<List<PddClientInfo>>() ?? [];
if (clients.Count == 0 || clients.Any(c => string.IsNullOrWhiteSpace(c.ClientId)
|| string.IsNullOrWhiteSpace(c.ClientSecret) || string.IsNullOrWhiteSpace(c.RedirectUri)))
throw new AppException("尚未完整配置拼多多应用信息");
return clients;
}
public async Task<JsonElement> GetPddToken(PddTokenRequest request, CancellationToken ct = default)
{
RequestValidator.Validate(request);
var actor = await Actor();
var name = actor.UserName;
var member = "," + name + ",";
if (!await db.Select<PddShopEntity>().Where(s => s.MallId == request.MallId
&& (s.UserName == name || ("," + s.SubUserName + ",").Contains(member))).AnyAsync(ct))
throw new AppException("店铺不存在或无读取令牌权限");
return await e57.GetToken(request.MallId, ct);
}
}