From c097c496883f14421f232bf29a9dd11b99a66634 Mon Sep 17 00:00:00 2001 From: yashen Date: Tue, 13 Sep 2016 10:39:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=BE=AE=E4=BF=A1=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- B3WeChat/Entities/ErrorObject.cs | 10 +++++++++- B3WeChat/Entities/TokenObject.cs | 3 ++- B3WeChat/Utils/InOutMessageUtil.cs | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) 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 741e7d0..2ca0121 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;