chengkun
2025-06-05 4080b5997b38ca84b3b203c7101dcadb97b76925
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
using System.Reflection;
using Tea;
 
namespace Alipay.EasySDK.Kernel.Util
{
    /// <summary>
    /// 响应检查工具类
    /// </summary>
    public class ResponseChecker
    {
        public const string SUB_CODE_FIELD_NAME = "SubCode";
 
        /// <summary>
        /// 判断一个请求返回的响应是否成功
        /// </summary>
        /// <param name="response">响应对象</param>
        /// <returns>true:成功;false:失败</returns>
        public static bool Success(TeaModel response)
        {
            PropertyInfo propertyInfo = response.GetType().GetProperty(SUB_CODE_FIELD_NAME);
            if (propertyInfo == null)
            {
                //没有SubCode属性的响应对象,通常是那些无需跟网关远程通信的API,只要本地执行完成都视为成功
                return true;
            }
 
            string subCode = (string)propertyInfo.GetValue(response);
            return string.IsNullOrEmpty(subCode);
        }
    }
}