zhengyiming
2025-04-09 a4b53ae88b588b099cf0e334f99d74d229f7fdc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using LifePayment.Application.Contracts;
using LifePayment.Domain.Shared;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
 
namespace LifePayment.HttpApi
{
    public class ChannelFilterAttribute : Attribute, IAsyncActionFilter
    {
 
        public ChannelFilterAttribute()
        {
 
        }
 
 
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (!context.ActionDescriptor.IsControllerAction())
            {
                await next();
                return;
            }
 
            var checkerService = context.GetRequiredService<ILifePayService>();
 
            foreach (var argument in context.ActionArguments)
            {
                // 检查参数类型是否为 ChannelsBaseInput
                if (argument.Value is ChannelsBaseInput model)
                {
                    // 获取 Channel 参数的值
                    string channelValue = model.CheckChannelId;
                    if (!string.IsNullOrEmpty(channelValue))
                    {
                        var result = await checkerService.CheckChannelsStatus(channelValue);
                        if (result)
                        {
                            await next();
                        }
                        else
                        {
                            throw new UserFriendlyException("没有对应的渠道");
                        }
 
                    }
                    else
                    {
                        throw new UserFriendlyException("没有对应的渠道");
                    }
                }
            }
 
 
        }
 
 
    }
}