public Stream CheckNew2(string applicationId) { dynamic apps = win.core.utils.FileAdapter.GetJSONFromFile(HttpContext.Current.Server.MapPath("~/CheckNew2.json")); dynamic app = null; foreach (dynamic theOne in apps) { if (theOne.ApplicationId == applicationId) { app = theOne; break; } } if (app == null) { WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; return(new MemoryStream(Encoding.UTF8.GetBytes("无效的AppId"))); } //检查主程序 string exeFileName = app.ApplicationCode; string exeDir = HttpContext.Current.Server.MapPath("~/" + applicationId); string exeFilePath = exeDir + @"\" + exeFileName; if (FileAdapter.Exists(exeFilePath)) { //Assembly asm = Assembly.LoadFile(exeFilePath);会锁定 Assembly asm = Assembly.Load(System.IO.File.ReadAllBytes(exeFilePath)); string version = asm.GetName().Version.ToString(); Product product = new Product { ApplicationId = applicationId, ApplicationName = app.ApplicationName, Version = version, Description = "更新说明" }; string appRoot = GetAppRootPath(); if (appRoot.EndsWith("/")) { appRoot = appRoot.Substring(0, appRoot.Length - 1); } product.FileList = new UpdateFilesInfo { SourcePath = appRoot + "/" + applicationId + "/" }; string[] files = Directory.GetFiles(exeDir, "*", SearchOption.AllDirectories); product.FileList.FileItems = new List <FileItem>(); foreach (string file in files) { string itemName = file.Replace(exeDir + @"\", "").Replace(@"\", "/"); product.FileList.FileItems.Add(new FileItem { Name = itemName }); } product.FileList.Count = product.FileList.FileItems.Count.ToString(); byte[] resultBytes = Encoding.UTF8.GetBytes(XmlSerializeAdapter.Serialize <Product>(product)); WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; return(new MemoryStream(resultBytes)); } return(null); }
public string ResponseText(WXReceiveTextMessage receiveMessage) { string result = ""; if (receiveMessage.Content.StartsWith("103/002/")) { string[] arrFields = receiveMessage.Content.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (arrFields.Length == 12) { string lat = arrFields[3]; //当前位置纬度 string log = arrFields[2]; //当前位置经度 string mapAPIKey = "00001"; if (!string.IsNullOrEmpty(GlobalManager.TheServiceAccount.MapAPI)) { if (GlobalManager.TheMapAPIOfInverseAdressParse.ContainsKey(GlobalManager.TheServiceAccount.MapAPI)) { mapAPIKey = GlobalManager.TheServiceAccount.MapAPI; } } string antiGeocodingUrl = GlobalManager.TheMapAPIOfInverseAdressParse[mapAPIKey].ReplaceWithKeys(new { lat = lat, log = log }.ToStringObjectDictionary()); HttpAdapter.apiJ(antiGeocodingUrl, (ret, res) => { if (ret.status == 0) { string detailAddress = ret.result.address; if (mapAPIKey == "00002") { detailAddress = string.IsNullOrEmpty(ret.result.street_number) ? ret.result.formatted_address + "附近" : ret.result.formatted_address; } result = XmlSerializeAdapter.Serialize <WXResponseTextMessage>(new WXResponseTextMessage { ToUserName = receiveMessage.FromUserName, FromUserName = receiveMessage.ToUserName, CreateTime = DateTimeAdapter.ConvertDateTimeUnix(DateTime.Now), MsgType = "text", Content = detailAddress }, true); //result = string.Format("<xml><ToUserName>{0}</ToUserName><FromUserName>{1}</FromUserName><CreateTime>{2}</CreateTime><MsgType>text</MsgType><Content>{3}</Content></xml>", requestMessage.FromUserName, requestMessage.ToUserName, DateTimeAdapter.ConvertDateTimeUnix(DateTime.Now), detailAddress); } }); } } //else //{ // result = FormatOutputText(receiveMessage.FromUserName, receiveMessage.ToUserName, "/:coffee"); //} return(result); }
public Stream ReceiveWXMessage(Stream s) { string result = ""; using (StreamReader sr = new StreamReader(s)) { result = sr.ReadToEnd(); } //result = OperationContext.Current.RequestContext.RequestMessage.ToString(); if (result != "") { WXReceiveMessage receiveMessage = XmlSerializeAdapter.Deserialize <WXReceiveMessage>(result); /* * XmlSerializer serializer = new XmlSerializer(typeof(WXReceiveMessage)); * using (StringReader rdr = new StringReader(result)) * { * WXReceiveMessage requestMessage = serializer.Deserialize(rdr) as WXReceiveMessage; * * } */ if (receiveMessage.MsgType.Equals("text")) { WXReceiveTextMessage requestTextMessage = XmlSerializeAdapter.Deserialize <WXReceiveTextMessage>(result); result = GlobalManager.TheWeiXinResponser.ResponseText(requestTextMessage); if (string.IsNullOrEmpty(result)) { result = GlobalManager.TheWeiXinDispatcher.DesideDispatchWho(requestTextMessage); GlobalManager.TheWeiXinDispatcher.DispatchText(requestTextMessage); } } else if (receiveMessage.MsgType.Equals("event")) { WXReceiveEventMessage requestEventMessage = XmlSerializeAdapter.Deserialize <WXReceiveEventMessage>(result); if (requestEventMessage.Event.Equals("subscribe")) { #region 关注 NormalAccount normalAccount = BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).List <NormalAccount>(new NormalAccount { OpenId = requestEventMessage.FromUserName, AccountCode = GlobalManager.TheServiceAccount.AccountCode }).FirstOrDefault(); if (normalAccount == null) { //第一次关注 BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).Create <NormalAccount>(new NormalAccount { AccountCode = GlobalManager.TheServiceAccount.AccountCode, OpenId = requestEventMessage.FromUserName, Gender = "F", SubscribeTime = DateTime.Now }); result = GlobalManager.TheWeiXinResponser.FormatOutputText(requestEventMessage.FromUserName, requestEventMessage.ToUserName, "欢迎加入" + GlobalManager.TheServiceAccount.Name); } else { //曾经关注过 BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).Update <NormalAccount>(new NormalAccount { FollowStatus = 1, SubscribeTime = DateTime.Now, Id = normalAccount.Id }); result = GlobalManager.TheWeiXinResponser.FormatOutputText(normalAccount.OpenId, requestEventMessage.ToUserName, "欢迎重新加入" + GlobalManager.TheServiceAccount.Name); } _RefreshWXUserInfo(requestEventMessage.FromUserName, (ret) => { string gender = "N"; int iGender = int.Parse(ret.sex.ToString()); if (iGender == 1) { gender = "M"; } else if (iGender == 2) { gender = "F"; } BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).ExecuteNativeSqlNoneQuery(new IBatisNetBatchStatement { StatementName = "NormalAccount_UpdateByOpenId", ParameterObject = new NormalAccount { OpenId = ret.openid, NickName = ret.nickname, Gender = gender, Language = ret.language, Country = ret.country, Province = ret.province, City = ret.city, HeadImgUrl = ret.headimgurl }.ToStringObjectDictionary(false), Type = SqlExecuteType.UPDATE }); }, null); #endregion } else if (requestEventMessage.Event.Equals("unsubscribe")) { #region 取消关注 NormalAccount normalAccount = BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).List <NormalAccount>(new NormalAccount { OpenId = requestEventMessage.FromUserName, AccountCode = GlobalManager.TheServiceAccount.AccountCode }).FirstOrDefault(); if (normalAccount != null) { BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).Update <NormalAccount>(new NormalAccount { FollowStatus = 0, SubscribeTime = DateTime.Now, Id = normalAccount.Id }); } #endregion } else if (requestEventMessage.Event.Equals("LOCATION")) { WXReceiveLocationMessage requestLocationMessage = XmlSerializeAdapter.Deserialize <WXReceiveLocationMessage>(result); var spParam = new { SourceTable = new NormalAccount().GetMappingTableName(), SourceId = requestLocationMessage.FromUserName, LocateType = "WX-Location-Report", Longitude = requestLocationMessage.Longitude, Latitude = requestLocationMessage.Latitude }.ToSPParam(); try { BuilderFactory.DefaultBulder().ExecuteSPNoneQuery("SP_Pub_InsertPubLocation", spParam); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { result = GlobalManager.TheWeiXinResponser.ResponseEvent(requestEventMessage); } } else if (receiveMessage.MsgType.Equals("location")) { } else if (receiveMessage.MsgType == "image") { } else if (receiveMessage.MsgType == "voice") { } } else { result = "hello"; } byte[] resultBytes = Encoding.UTF8.GetBytes(result); WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; return(new MemoryStream(resultBytes)); }
public string FormatOutputNews(string toUserName, string fromUserName, List <WXResponseNewsItem> newsItems) { return(XmlSerializeAdapter.Serialize <WXResponseNewsMessage>(new WXResponseNewsMessage { ToUserName = toUserName, FromUserName = fromUserName, CreateTime = DateTimeAdapter.ConvertDateTimeUnix(DateTime.Now), MsgType = "news", ArticleCount = newsItems.Count, Articles = newsItems }, true)); }
public string FormatOutputText(string toUserName, string fromUserName, string content) { return(XmlSerializeAdapter.Serialize <WXResponseTextMessage>(new WXResponseTextMessage { ToUserName = toUserName, FromUserName = fromUserName, CreateTime = DateTimeAdapter.ConvertDateTimeUnix(DateTime.Now), MsgType = "text", Content = content.Replace(@"\\", @"\") }, true)); }