ResponseChecker.cs 1005 B

12345678910111213141516171819202122232425262728293031
  1. using System.Reflection;
  2. using Tea;
  3. namespace Alipay.EasySDK.Kernel.Util
  4. {
  5. /// <summary>
  6. /// 响应检查工具类
  7. /// </summary>
  8. public class ResponseChecker
  9. {
  10. public const string SUB_CODE_FIELD_NAME = "SubCode";
  11. /// <summary>
  12. /// 判断一个请求返回的响应是否成功
  13. /// </summary>
  14. /// <param name="response">响应对象</param>
  15. /// <returns>true:成功;false:失败</returns>
  16. public static bool Success(TeaModel response)
  17. {
  18. PropertyInfo propertyInfo = response.GetType().GetProperty(SUB_CODE_FIELD_NAME);
  19. if (propertyInfo == null)
  20. {
  21. //没有SubCode属性的响应对象,通常是那些无需跟网关远程通信的API,只要本地执行完成都视为成功
  22. return true;
  23. }
  24. string subCode = (string)propertyInfo.GetValue(response);
  25. return string.IsNullOrEmpty(subCode);
  26. }
  27. }
  28. }