|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using BWP.B3WeChat; |
|
|
|
using BWP.B3WeChat.Entities; |
|
|
|
using Forks.Utils; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
@ -14,6 +15,9 @@ namespace BWP.B3WeChat.Utils |
|
|
|
{ |
|
|
|
public static class InOutMessageUtil |
|
|
|
{ |
|
|
|
|
|
|
|
static Logger logger = new Logger("InOutMessageUtil"); |
|
|
|
|
|
|
|
static string token; |
|
|
|
|
|
|
|
static string TOKEN |
|
|
|
@ -36,12 +40,13 @@ namespace BWP.B3WeChat.Utils |
|
|
|
string uriStr = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", config.AppID, config.AppSecret); |
|
|
|
|
|
|
|
WebClient client = new WebClient(); |
|
|
|
|
|
|
|
string responseBody = string.Empty; |
|
|
|
logger.Info("GetToken_uriStr:" + uriStr); |
|
|
|
try |
|
|
|
{ |
|
|
|
byte[] bytes = client.DownloadData(uriStr); |
|
|
|
string responseBody = Encoding.UTF8.GetString(bytes); |
|
|
|
JavaScriptSerializer jsonHelper = new JavaScriptSerializer(); |
|
|
|
responseBody = Encoding.UTF8.GetString(bytes); |
|
|
|
JavaScriptSerializer jsonHelper = new JavaScriptSerializer(); logger.Info("GetToken_responseBody:" + responseBody); |
|
|
|
TokenObject obj = jsonHelper.Deserialize<TokenObject>(responseBody); |
|
|
|
if (obj != null) |
|
|
|
{ |
|
|
|
@ -50,6 +55,7 @@ namespace BWP.B3WeChat.Utils |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
logger.Info("GetToken_ERROR:" + responseBody); |
|
|
|
throw e; |
|
|
|
} |
|
|
|
return token; |
|
|
|
@ -167,6 +173,7 @@ namespace BWP.B3WeChat.Utils |
|
|
|
{ |
|
|
|
StreamReader reader = new StreamReader(request.InputStream); |
|
|
|
String xmlData = reader.ReadToEnd(); |
|
|
|
logger.Info("GetMessage_xmlData:" + xmlData); |
|
|
|
object obj = null; |
|
|
|
MessageType type = XmlUtil.Deserialize<MessageType>(xmlData); |
|
|
|
if (type.MsgType == MsgType.文本) |
|
|
|
@ -239,9 +246,11 @@ namespace BWP.B3WeChat.Utils |
|
|
|
} |
|
|
|
}; |
|
|
|
string postData = jsonHelper.Serialize(body); |
|
|
|
logger.Info("GenerateEQCode_body:" + body); |
|
|
|
string data = string.Empty; |
|
|
|
try |
|
|
|
{ |
|
|
|
logger.Info("GenerateEQCode_uriStr:" + uriStr); |
|
|
|
byte[] byteArray = Encoding.UTF8.GetBytes(postData); |
|
|
|
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(uriStr)); |
|
|
|
webRequest.Method = "post"; |
|
|
|
@ -251,11 +260,12 @@ namespace BWP.B3WeChat.Utils |
|
|
|
newStream.Write(byteArray, 0, byteArray.Length); |
|
|
|
newStream.Close(); |
|
|
|
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); |
|
|
|
data = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd(); |
|
|
|
result = jsonHelper.Deserialize<QRCodeResult>(data); |
|
|
|
data = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();logger.Info("GenerateEQCode_data:" + data); |
|
|
|
result = jsonHelper.Deserialize<QRCodeResult>(data); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
logger.Info("GenerateEQCode_ERROR:" + data); |
|
|
|
throw e; |
|
|
|
} |
|
|
|
if (result != null && !string.IsNullOrEmpty(result.ticket)) |
|
|
|
|