private void startwechat(HttpContext context) { try { var config = new SiteConfig(); if (WebUtil.GetContextPath().Contains(config.SITE_URL)) { string VirName = WebUtil.GetVirName(); int SiteNumber = int.Parse(config.Wechat_SiteNumber); string ZipPath = config.Wechat_ZipPath; string SitePath = config.Wechat_SitePath; Utility.Tools.UnZipFile(ZipPath, SitePath, VirName); bool sitestatus = IISManager.CreateWebSite(string.Empty, VirName, SitePath + VirName + @"\weixin", false, 1, SiteNumber, "localhost"); string ConfigPath = SitePath + VirName + @"\weixin\Web.config"; Dictionary <string, object> dic = new Dictionary <string, object>(); string SiteURL = config.SITE_URL; if (SiteURL.EndsWith("/")) { SiteURL = SiteURL.Substring(0, SiteURL.Length - 1); } if (!SiteURL.EndsWith(VirName) && !VirName.Equals("saas")) { SiteURL = SiteURL + "/" + VirName; } dic["apiurl"] = SiteURL + "/handler/api.ashx"; dic["SITE_URL"] = SiteURL; Utility.IISManager.UpdateConfigValue(ConfigPath, dic); } var list = Foresight.DataAccess.SysConfig.GetSysConfigListByType("Wechat"); var data = list.FirstOrDefault(p => p.Name.Equals("WechatEnable")); if (data == null) { data = new Foresight.DataAccess.SysConfig(); data.AddTime = DateTime.Now; data.ConfigType = "Wechat"; } data.Name = "WechatEnable"; data.Value = "1"; data.Save(); WebUtil.WriteJsonResult(context, "生成成功"); } catch (Exception ex) { LogHelper.WriteError("WechatSetup", "startwechat", ex); WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, ex); } }
private void savesite(HttpContext context) { try { var config = new Utility.SiteConfig(); string VirName = context.Request.Params["sitename"]; int CompanyID = int.Parse(context.Request.Params["CompanyID"]); int SiteNumber = int.Parse(config.SiteNumber); string SiteName = config.SiteName; string ZipPath = config.ZipPath; string SitePath = config.SitePath; int ServerLocation = WebUtil.GetIntValue(context, "ServerLocation"); int VersionCode = 1; int.TryParse(config.SysVersionCode, out VersionCode); var company = Foresight.DataAccess.Company.GetCompany(CompanyID); if (company == null) { WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, "公司已删除"); return; } if (string.IsNullOrEmpty(VirName)) { WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, "网址不能为空"); return; } company.ServerLocation = ServerLocation; if (company.ServerLocation == 1) { if (!VirName.ToLower().StartsWith("http://") && !VirName.ToLower().StartsWith("https://")) { WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, "网址输入不正确"); return; } company.BaseURL = VirName; company.IsActive = true; company.IsAdmin = false; company.IsCustomer = true; company.VersionCode = company.VersionCode > 0 ? company.VersionCode : VersionCode; company.Save(); WebUtil.WriteJsonResult(context, "生成成功"); return; } if (!string.IsNullOrEmpty(company.BaseURL)) { WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, "网址已分配"); return; } var URLList = Foresight.DataAccess.Company.GetCompanies().Select(p => p.BaseURL); if (URLList.Any(p => p.Contains(VirName))) { WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, "网站已存在"); return; } string SiteURL = config.SITE_URL + VirName; string DBName = "yy_" + VirName; try { Utility.Tools.UnZipFile(ZipPath, SitePath, VirName); bool sitestatus = IISManager.CreateWebSite(SiteName, VirName, SitePath + VirName, false, 1, SiteNumber, "localhost"); //if (!sitestatus) //{ // WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, "网站已存在"); // return; //} string ConfigPath = SitePath + VirName + @"\Web.config"; if (!System.IO.File.Exists(ConfigPath)) { ConfigPath = SitePath + @"Web.config"; } if (System.IO.File.Exists(ConfigPath)) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic["SITE_URL"] = SiteURL; dic["CompanyName"] = company.CompanyName; dic["CopyRight"] = DateTime.Now.Year.ToString() + " " + company.CompanyName; dic["ConnString"] = config.ConnString + ";database=" + DBName; Utility.IISManager.UpdateConfigValue(ConfigPath, dic); } } catch (Exception) { } #region 生成数据库 try { Utility.SQLHelper.CreateDataBase(DBName, CompanyID); company.BaseURL = SiteURL; company.IsActive = true; company.IsAdmin = false; company.IsCustomer = true; company.VersionCode = VersionCode; company.Save(); string sqltext = @"insert into [" + DBName + "].[dbo].[Company]([CompanyName],[CompanyDesc],[PhoneNumber],[Address],[ChargePerson],[AddTime],[IsActive],[BaseURL],[VersionCode]) select [CompanyName],[CompanyDesc],[PhoneNumber],[Address],[ChargePerson],[AddTime],[IsActive],[BaseURL],[VersionCode] from [prosystem].[dbo].[Company] where CompanyID=" + company.CompanyID + ";"; Utility.SQLHelper.ExecuteSql("master", sqltext); sqltext = @"insert into [" + DBName + "].[dbo].[User]([LoginName],[Password],[PhoneNumber],[Email],[HeadImg],[NickName],[RealName],[Gender],[Type],[CreateTime],[IsLocked],[LockTime]) select [LoginName],[Password],[PhoneNumber],[Email],[HeadImg],[NickName],[RealName],[Gender],[Type],[CreateTime],[IsLocked],[LockTime] from [prosystem].[dbo].[User] where UserID in (select UserID from [prosystem].[dbo].[UserCompany] where [CompanyID]=" + CompanyID + ");"; Utility.SQLHelper.ExecuteSql("master", sqltext); } catch (Exception) { } #endregion WebUtil.WriteJsonResult(context, "生成成功"); } catch (Exception ex) { WebUtil.WriteJsonError(context, ErrorCode.InvalideRequest, ex); } }
private void upgradeweixinsite(HttpContext context) { string IDs = context.Request["IDList"]; List <int> IDList = new List <int>(); if (!string.IsNullOrEmpty(IDs)) { IDList = JsonConvert.DeserializeObject <List <int> >(IDs); } if (IDList.Count == 0) { WebUtil.WriteJson(context, new { status = false, error = "公司为空" }); return; } HttpPostedFile postedFile = context.Request.Files[0]; string fileName = postedFile.FileName; if (fileName == "" || fileName == null) { WebUtil.WriteJson(context, new { status = false, error = "请上传文件" }); return; } string extension = System.IO.Path.GetExtension(fileName).ToLower(); fileName = DateTime.Now.ToFileTime().ToString() + extension; string filepath = "/upload/"; string rootPath = HttpContext.Current.Server.MapPath("~" + filepath); if (!System.IO.Directory.Exists(rootPath)) { System.IO.Directory.CreateDirectory(rootPath); } string ZipPath = rootPath + fileName; postedFile.SaveAs(ZipPath); var companys = Foresight.DataAccess.Company.GetAllActiveCompanyList().Where(p => IDList.Contains(p.CompanyID)).ToArray(); var config = new Utility.SiteConfig(); string SitePath = config.Wechat_SitePath; string SiteName = config.SiteName; foreach (var company in companys) { if (!company.BaseURL.Contains(config.SITE_URL)) { WebUtil.WriteJson(context, new { status = false, error = "功能不支持,请手动配置微信" }); return; } string NewFileName = company.BaseURL.Replace(config.SITE_URL, ""); string VirName = NewFileName; string Sub_VirName = "html"; if (NewFileName.StartsWith("http://")) { NewFileName = "saas"; VirName = "html"; Sub_VirName = ""; } int SiteNumber = int.Parse(config.SiteNumber); Utility.Tools.UnZipFile(ZipPath, SitePath, NewFileName); string my_sitepath = SitePath + NewFileName + @"\html"; bool sitestatus = IISManager.CreateWebSite(SiteName, VirName, my_sitepath, false, 1, SiteNumber, "localhost", Sub_VirName); } WebUtil.WriteJson(context, new { status = true }); }