/// <summary> /// 消息转发到客服 /// </summary> /// <param name="instanse"></param> /// <returns></returns> public string TransferCustomerService(PubRecAbstract instanse) { string strResult = string.Empty; if (isCustomerMsg) { strResult = string.Format(@"<xml><ToUserName>{0}</ToUserName><FromUserName>{1}</FromUserName><CreateTime>1399197672</CreateTime><MsgType><![CDATA[transfer_customer_service]]></MsgType></xml>", instanse.FromUserName, instanse.ToUserName); } return("success!@!" + strResult); }
/// <summary> /// 消息处理 /// </summary> /// <param name="postStr"></param> /// <param name="sMsgSignature"></param> /// <param name="pTimeStamp"></param> /// <param name="pNonce"></param> /// <returns></returns> public string ProcessMsg(string postStr, string sMsgSignature, string pTimeStamp, string pNonce) { string sMsgType = string.Empty; string sEventType = string.Empty; string sResult = string.Empty; string sMsg = DecryptMsg(sMsgSignature, pTimeStamp, pNonce, postStr); // 解析之后的明文 try { XmlDocument doc = new XmlDocument(); doc.LoadXml(sMsg); XmlNode root = doc.FirstChild; sMsgType = root["MsgType"].InnerText; Assembly assembly = Assembly.GetExecutingAssembly(); Type type; if ("event".Equals(sMsgType)) { sEventType = root["Event"].InnerText; type = assembly.GetType("WeChat.PubLib.Model.PubRecEvent" + sEventType.Substring(0, 1).ToUpper() + sEventType.Substring(1).ToLower()); } else { type = assembly.GetType("WeChat.PubLib.Model.PubRecMsg" + sMsgType.Substring(0, 1).ToUpper() + sMsgType.Substring(1).ToLower()); } log.Debug("PubCore ReflectClassName:" + type.Name); object instance = Activator.CreateInstance(type, new object[] { sMsg }); if (instance != null) { log.Debug("PubCore ProcessMsg instance:" + instance.ToString()); PubRecAbstract temp = (PubRecAbstract)instance; sResult = temp.DoProcess(); if (string.IsNullOrEmpty(sResult)) { sResult = "success"; } } } catch (Exception e) { log.Error("PubCore ProcessMsg:", e); } return(EncryptMsg(pTimeStamp, pNonce, sResult)); }