diff --git a/B3WeChat/Entities/ErrorObject.cs b/B3WeChat/Entities/ErrorObject.cs
index 4239fe1..cdf0a97 100644
--- a/B3WeChat/Entities/ErrorObject.cs
+++ b/B3WeChat/Entities/ErrorObject.cs
@@ -7,7 +7,15 @@ namespace BWP.B3WeChat.Entities
{
public class ErrorObject
{
- public string errcode { get; set; }
+ public int errcode { get; set; }
public string errmsg { get; set; }
+
+ public bool IsError
+ {
+ get
+ {
+ return errcode > 0;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/B3WeChat/Entities/TokenObject.cs b/B3WeChat/Entities/TokenObject.cs
index a4604f8..5e3052b 100644
--- a/B3WeChat/Entities/TokenObject.cs
+++ b/B3WeChat/Entities/TokenObject.cs
@@ -8,9 +8,10 @@ namespace BWP.B3WeChat.Entities
///
/// Token对象
///
- public class TokenObject
+ public class TokenObject:ErrorObject
{
public string access_token { get; set; }
public string expires_in { get; set; }
+
}
}
\ No newline at end of file
diff --git a/B3WeChat/Utils/InOutMessageUtil.cs b/B3WeChat/Utils/InOutMessageUtil.cs
index 9f2c56c..4706b9e 100644
--- a/B3WeChat/Utils/InOutMessageUtil.cs
+++ b/B3WeChat/Utils/InOutMessageUtil.cs
@@ -48,6 +48,10 @@ namespace BWP.B3WeChat.Utils
responseBody = Encoding.UTF8.GetString(bytes);
JavaScriptSerializer jsonHelper = new JavaScriptSerializer(); logger.Info("GetToken_responseBody:" + responseBody);
TokenObject obj = jsonHelper.Deserialize(responseBody);
+ if (obj.IsError)
+ {
+ throw new Exception(string.Format("{0}:{1}", obj.errcode, obj.errmsg));
+ }
if (obj != null)
{
token = obj.access_token;