public override void ProcessActivity(WebRequest request, WebResponse response) { var Id = UMC.Data.Utility.Guid(this.AsyncDialog("Id", g => { this.Prompt("请输入参数"); return(this.DialogValue("none")); }), true); var subEntity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>(); subEntity.Where.And().Equal(new Subject { Id = Id }); var sub = subEntity.Single(); var user = UMC.Security.Identity.Current; if (sub.project_id.HasValue) { var project = Utility.CMS.ObjectEntity <Project>().Where.And().Equal(new Project { Id = sub.project_id }).Entities.Single(); if (project != null && project.user_id == user.Id) { } else { var member = Utility.CMS.ObjectEntity <ProjectMember>().Where.And().Equal(new ProjectMember { project_id = sub.project_id, user_id = user.Id }).Entities.Single(); if (member != null) { switch (member.AuthType) { case WebAuthType.Admin: case WebAuthType.User: break; default: if (sub.Status > 0) { this.Context.Send(new UISectionBuilder(request.Model, "UIData", new UMC.Web.WebMeta().Put("Id", Id)) .Builder(), true); } if (sub.user_id == user.Id) { this.Prompt(String.Format("{0}项目收回了您的编辑权限", project.Caption)); } else { this.Prompt("您未有编辑此图文的权限"); } break; } } else { if (sub.Status > 0) { this.Context.Send(new UISectionBuilder(request.Model, "UIData", new UMC.Web.WebMeta().Put("Id", Id)) .Builder(), true); } if (sub.user_id == user.Id) { this.Prompt(String.Format("{0}项目收回了你的编辑权限", project.Caption)); } else { this.Prompt("您未有编辑此图文的权限"); } } } } if (String.IsNullOrEmpty(request.SendValue) == false) { this.Context.Send(new UISectionBuilder(request.Model, request.Command, new UMC.Web.WebMeta().Put("Id", Id)) .RefreshEvent("Subject.Save", "image", "Subject.Content").CloseEvent("Subject.Del") .Builder(), true); } // var appKey = UMC.Security.Principal.Current.AppKey ?? Guid.Empty; var Model = this.AsyncDialog("Model", gKey => { var webr = UMC.Data.WebResource.Instance(); UITitle uITItle = UITitle.Create(); uITItle.Title = "图文发布"; var sestion = UISection.Create(uITItle); var pictureEntity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Picture>(); pictureEntity.Where.And().GreaterEqual(new Data.Entities.Picture { Seq = 0 }); pictureEntity.Order.Asc(new Data.Entities.Picture { Seq = 0 }); var images = new List <String>(); var items = new List <WebMeta>(); pictureEntity.Where .And().In(new Data.Entities.Picture { group_id = sub.Id }) .Entities.Query(dr => { var src = webr.ResolveUrl(dr.group_id.Value, dr.Seq, "0"); var chachKey = "?_ts=" + UMC.Data.Utility.TimeSpan(dr.UploadDate.Value); items.Add(new UMC.Web.WebMeta().Put("src", src + "!200" + chachKey).Put("click", new Web.UIClick(new UMC.Web.WebMeta().Put("Id", dr.group_id.Value).Put("Seq", dr.Seq).Put(gKey, "Picture")) { Model = request.Model, Command = request.Command })); images.Add(src + "?_ts=" + chachKey); }); var uidesc = new UIDesc(sub.Title); uidesc.Style.Bold().Height(50); uidesc.Click(new UIClick("Id", Id.ToString(), gKey, "Title") { Model = request.Model, Command = request.Command }); var nine = new UMC.Web.WebMeta().Put("images", items); sestion.Delete(uidesc, new UIEventText().Click(new UIClick("Id", Id.ToString(), gKey, "Del") { Model = request.Model, Command = request.Command })); var sT = sub.Description ?? sub.Title; if (sT.Length > 48) { sT = sT.Substring(0, 48) + "..."; } var desc = new UIDesc(sT); desc.Style.Height(40).Color(0x999).Size(13);//.Name("border", "none"); desc.Click(new UIClick("Id", Id.ToString(), gKey, "Desc") { Model = request.Model, Command = request.Command }); sestion .Add(UICell.Create("NineImage", nine)).Add(desc) .AddCell("封面方式", sub.IsPicture == true ? "显示大图" : (images.Count > 2 ? "三张图" : "单张图") , new UIClick("Id", Id.ToString(), gKey, "Show") { Model = request.Model, Command = request.Command }); if (images.Count < 3) { nine.Put("click", new UIClick("Id", Id.ToString(), gKey, "Image") { Model = request.Model, Command = request.Command }); } if (request.IsApp) { sestion.NewSection().AddCell('\uf044', "编辑正文", "", new UIClick(Id.ToString()) { Command = "Content", Model = request.Model }); } var status = "审阅中"; if (sub.Status > 0) { status = "已发布"; } else if (sub.Status < 0) { if (sub.Status == -2) { status = "被驳回"; } else { status = "未发布"; } } var cateName = "草稿"; if (sub.project_item_id.HasValue) { //var portfolio = Utility.CMS.ObjectEntity<UMC.Data.Entities.Portfolio>().Where.And().Equal(new Data.Entities.Portfolio //{ // Id = sub.portfolio_id.Value //}).Entities.Single(); var ProjectItem = Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectItem>().Where.And().Equal(new Data.Entities.ProjectItem { Id = sub.project_item_id.Value }).Entities.Single(); var Project = Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>().Where.And().Equal(new Data.Entities.Project { Id = sub.project_id.Value }).Entities.Single(); cateName = String.Format("{0}/{1}", Project.Caption, ProjectItem.Caption); } var ness = sestion .NewSection().AddCell("发布状态", status); ness.AddCell("所属专栏", cateName , new UIClick("Id", sub.Id.ToString(), gKey, "Project") { Model = request.Model, Command = request.Command }); ness.AddCell("评论功能", (sub.IsComment ?? true) ? "开启" : "关闭", new UIClick("Id", Id.ToString(), gKey, "Comment") { Model = request.Model, Command = request.Command }) .NewSection() .AddCell("浏览正文", "", new UIClick(sub.Id.ToString()).Send(request.Model, "View")) .AddCell("管理评论", "", new UIClick(Id.ToString()) { Command = "Comments", Model = request.Model }); if (request.UserAgent.IndexOf("DingTalk") > 0 && sub.project_id.HasValue) { if (Utility.CMS.ObjectEntity <ProjectSetting>() .Where.And().Equal(new ProjectSetting { project_id = sub.project_id, Type = 11 }).Entities.Count() > 0) { var strt = UMC.Security.AccessToken.Current.Data["DingTalk-Sub-Id"] as string;//, Utility.Guid(projectId)).Commit(); var text = ""; if (Utility.Guid(sub.Id.Value) == strt) { text = UMC.Security.AccessToken.Current.Data["DingTalk-Session-Text"] as string; } ness.NewSection().AddCell("发送到群", text, new UIClick("Id", Id.ToString(), gKey, "DingTalk") { Model = request.Model, Command = request.Command }); } } else { if (Utility.CMS.ObjectEntity <ProjectSetting>() .Where.And().Equal(new ProjectSetting { project_id = sub.project_id, Type = 12 }).Entities.Count() > 0) { ness.NewSection().AddCell("发送到群", "", new UIClick("Id", Id.ToString(), gKey, "DingTalk") { Model = request.Model, Command = request.Command }); } } //} sestion.UIFootBar = new UIFootBar().AddText( new UIEventText(sub.Status == 1 ? "下架" : "确认发布").Click(new UIClick("Id", Id.ToString(), "Model", "Status", "Status", sub.Status == 1 ? "-1" : "1") { Model = request.Model, Command = request.Command }).Style(new UIStyle().BgColor()), new UIEventText("摘正文摘要").Click(new UIClick("Id", Id.ToString(), "Model", "AutoDesc") { Model = request.Model, Command = request.Command })); sestion.UIFootBar.IsFixed = true; response.Redirect(sestion); return(this.DialogValue("none")); }); switch (Model) { case "Picture": var seq = this.AsyncDialog("Seq", "1"); this.AsyncDialog("Picture", g => { var sel = new Web.UISheetDialog(); sel.Options.Add(new UIClick(new UMC.Web.WebMeta().Put("id", sub.Id.Value).Put("seq", seq)) { Command = "Picture", Text = "重新上传", Model = "Design" }); sel.Options.Add(new UIClick(new UMC.Web.WebMeta().Put("id", sub.Id.Value).Put("seq", seq).Put("media_id", "none")) { Command = "Picture", Text = "删除图片", Model = "Design" }); return(sel); }); break; case "DingTalk": { if (sub.Status == 1) { switch (this.AsyncDialog("Type", g => { var ds = new UISelectDialog(); ds.Options.Put("用机器人发送", "Robot"); ds.Options.Put("选择到人发送", "Session"); return(ds); })) { case "Robot": if (Utility.CMS.ObjectEntity <ProjectSetting>() .Where.And().Equal(new ProjectSetting { project_id = sub.project_id, Type = 12 }).Entities.Count() > 0) { this.Send(request, sub, String.Empty, true); this.Prompt("机器人发送已经发起"); } else { this.Prompt("此项目未配置钉钉机器人"); } break; } } var DingTalk = Web.UIDialog.AsyncDialog("TalkId", g => { if (request.UserAgent.IndexOf("DingTalk") == -1) { this.Prompt("非钉钉环境,不能获取到钉钉会话参数"); } var ticket = SubjectDingtalkActivity.JsAccessToken(sub.project_id.Value); if (ticket == null) { this.Prompt("未有钉钉配置"); } if (String.IsNullOrEmpty(ticket.AgentId)) { this.Prompt("未有钉钉应用ID"); } var nonceStr = Utility.TimeSpan(); var timeStamp = Utility.TimeSpan(); var url = (request.UrlReferrer ?? request.Url).AbsoluteUri; String plain = "jsapi_ticket=" + ticket.APITicket + "&noncestr=" + nonceStr + "×tamp=" + timeStamp + "&url=" + url; var config = new WebMeta(); config.Put("agentId", ticket.AgentId); config.Put("corpId", ticket.CorpId); config.Put("timeStamp", timeStamp.ToString()); config.Put("nonceStr", nonceStr.ToString()); config.Put("url", url); config.Put("signature", Utility.SHA1(plain).ToLower()); config.Put("jsApiList", new string[] { "biz.map.view", "biz.chat.pickConversation" }); this.Context.Send("Subject.DingTalk", new WebMeta().Put("method", "pickConversation").Put("Sign", config).Put("Params", new WebMeta(request.Arguments).Put("_model", request.Model, "_cmd", request.Command)).Put("Key", g), true); return(this.DialogValue("none")); }); if (sub.Status == 1) { this.Send(request, sub, DingTalk, false); this.Prompt("会话发送已经发起"); } else { UMC.Security.AccessToken.Current.Put("DingTalk-Sub-Id", Utility.Guid(sub.Id.Value)).Put("DingTalk-Session-Text", this.AsyncDialog("TalkId-Text", "Text")).Put("DingTalk-Session-Id", DingTalk).Commit(); } } break; case "Image": Web.UIDialog.AsyncDialog("Image", g => { var dl = new Web.UISheetDialog() { Title = "图片上传" }; dl.Options.Add(new Web.UIClick(sub.Id.ToString()) { Model = request.Model, Command = "Image", Text = "正文图片" }); dl.Options.Add(new Web.UIClick(sub.Id.ToString()) { Model = "Design", Command = "Picture", Text = "本地图片" }); return(dl); }); break; case "Title": var title = Web.UIDialog.AsyncDialog("Title", g => { var dl = new Web.UIFormDialog() { Title = "图文标题" }; dl.AddTextarea("快文标题", "Title", sub.Title); dl.Submit("确认更改", request, "Subject.Save"); return(dl); }); subEntity.Update(new Subject { Title = title }); break; case "Desc": var desc = Web.UIDialog.AsyncDialog("Description", g => { var dl = new Web.UIFormDialog() { Title = "图文摘要" }; dl.AddTextarea("图文摘要", "Description", sub.Description ?? sub.Title).Put("Rows", 10); dl.Submit("确认更改", request, "Subject.Save"); return(dl); }); subEntity.Update(new Subject { Description = desc }); break; case "Score": var Score = Utility.IntParse(Web.UIDialog.AsyncDialog("Score", g => { var dl = new Web.UIFormDialog() { Title = "图文积分" }; dl.AddNumber("图文积分", "Score", sub.Score); dl.Submit("确认更改", request, "Subject.Save"); return(dl); }), 0); if (Score < 0) { this.Prompt("积分必须大于或等于零"); } subEntity.Update(new Subject { Score = Score }); break; case "Project": { var meta = new WebMeta(); if (sub.project_id.HasValue) { var project = Utility.CMS.ObjectEntity <Project>().Where.And().Equal(new Project { Id = sub.project_id.Value }).Entities.Single(); if (project != null) { if (project.Id == user.Id) { } else { meta.Put("Project", sub.project_id); var member = Utility.CMS.ObjectEntity <ProjectMember>().Where.And().Equal(new ProjectMember { project_id = sub.project_id, user_id = user.Id }).Entities.Single(); if (member != null) { switch (member.AuthType) { case WebAuthType.Admin: case WebAuthType.User: break; default: this.Prompt("您未有编辑此图文的权限"); break; } } else { this.Prompt("您未有编辑此图文的权限"); } } } } var sid = UMC.Data.Utility.Guid(this.AsyncDialog("PortfolioId", request.Model, "Portfolio", meta)).Value; var portfolio = Utility.CMS.ObjectEntity <UMC.Data.Entities.Portfolio>() .Where.And().Equal(new Portfolio { Id = sid }).Entities.Single(); var projectItem = Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectItem>() .Where.And().Equal(new ProjectItem { Id = portfolio.project_item_id }).Entities.Single(); if (request.IsCashier == false) { var project = Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>() .Where.And().Equal(new Project { Id = portfolio.project_id }).Entities.Single(); if (project.user_id.Value != user.Id) { var member = Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectMember>() .Where.And().Equal(new ProjectMember { project_id = project.Id }).Entities.Single(); if (member == null) { this.Prompt("你尚未加入此项目的专栏"); } else { switch (member.AuthType) { case WebAuthType.Admin: case WebAuthType.User: break; default: this.Prompt("你尚未加入此项目的专栏"); break; } } } } if (String.IsNullOrEmpty(sub.Code)) { subEntity.Update(new Subject() { Code = Utility.Parse36Encode(sub.Id.Value.GetHashCode()), portfolio_id = portfolio.Id, project_id = projectItem.project_id, project_item_id = projectItem.Id, last_user_id = user.Id }); } else { subEntity.Update(new Subject() { portfolio_id = portfolio.Id, project_id = projectItem.project_id, project_item_id = projectItem.Id, last_user_id = user.Id }); } } break; case "Comment": var s2 = UMC.Data.Utility.IntParse(this.AsyncDialog("Comment", g => { var dl = new Web.UISelectDialog() { Title = "评论功能" }; dl.Options.Add("开启评论", "1"); dl.Options.Add("关闭评论", "-1"); return(dl); }), 0); subEntity.Update(new Subject { IsComment = s2 == 1 }); break; case "Status": var s = UMC.Data.Utility.IntParse(this.AsyncDialog("Status", g => { var dl = new Web.UISelectDialog() { Title = "发布确认" }; dl.Options.Add("不发布", "-1"); dl.Options.Add("发布", "1"); return(dl); }), 0); if (sub.project_id.HasValue == false || sub.project_item_id.HasValue == false || sub.portfolio_id.HasValue == false) { this.Prompt("请选择发布的栏位"); } if ((sub.soure_id ?? Guid.Empty) != Guid.Empty) { this.Prompt("提示", "非原创,公共栏目不接收,只限于公众号群发。"); } if (s == 0) { if (String.IsNullOrEmpty(sub.Url) == false && sub.Status == -1) { s = 1; } } if (s == -1 && sub.Status == -2) { this.Prompt("被驳回状态,不需要此操作"); } String Sdesc = null; if (s > 0) { //if (String.IsNullOrEmpty(sub.Code)) if (String.IsNullOrEmpty(sub.Description)) { // sub.DataJSON var celss = UMC.Data.JSON.Deserialize <WebMeta[]>((String.IsNullOrEmpty(sub.DataJSON) ? "[]" : sub.DataJSON)) ?? new UMC.Web.WebMeta[] { }; var sb = new StringBuilder(); foreach (var pom in celss) { switch (pom["_CellName"]) { case "CMSText": var value = pom.GetMeta("value"); var format = pom.GetMeta("format")["text"]; var fValue = Utility.Format(format, value.GetDictionary(), String.Empty); if (String.Equals(fValue, sub.Title) == false) { sb.Append(fValue); } if (sb.Length > 250) { break; } break; } } Sdesc = sb.Length > 250 ? sb.ToString(0, 250) : sb.ToString(); sub.Description = Sdesc; } var IsDraught = Utility.CMS.ObjectEntity <UMC.Data.Entities.Picture>().Where .And().In(new Data.Entities.Picture { group_id = sub.Id }).Entities.Count() == 0; subEntity.Update(new Subject { Status = s, Description = Sdesc, IsDraught = IsDraught, Code = String.IsNullOrEmpty(sub.Code) ? Utility.Guid(sub.Id.Value) : null, Poster = user.Alias, ReleaseDate = DateTime.Now }); var cid = String.Empty; // var strt = UMC.Security.AccessToken.Current.Data["DingTalk-Sub-Id"] as string; //, Utility.Guid(projectId)).Commit(); if (Utility.Guid(sub.Id.Value) == strt) { cid = UMC.Security.AccessToken.Current.Data["DingTalk-Session-Id"] as string; } Send(request, sub, cid, true); if (String.IsNullOrEmpty(strt) == false) { UMC.Security.AccessToken.Current.Put("DingTalk-Sub-Id", String.Empty).Commit(); } this.Prompt("发布成功", false); } else { subEntity.Update(new Subject { Status = s, Code = String.IsNullOrEmpty(sub.Code) ? Utility.Guid(sub.Id.Value) : null, }); } break; case "AutoDesc": { // sub.DataJSON var celss = UMC.Data.JSON.Deserialize <WebMeta[]>((String.IsNullOrEmpty(sub.DataJSON) ? "[]" : sub.DataJSON)) ?? new UMC.Web.WebMeta[] { }; var sb = new StringBuilder(); foreach (var pom in celss) { switch (pom["_CellName"]) { case "CMSText": var value = pom.GetMeta("value"); var format = pom.GetMeta("format")["text"]; var fValue = Utility.Format(format, value.GetDictionary(), String.Empty); if (String.Equals(fValue, sub.Title) == false) { sb.Append(fValue); } if (sb.Length > 250) { break; } break; } } var Sdesc2 = sb.Length > 250 ? sb.ToString(0, 250) : sb.ToString(); subEntity.Update(new Subject { Description = Sdesc2 }); } break; case "Show": var m = this.AsyncDialog("Show", g => { var dl = new Web.UISelectDialog() { Title = "封面展示方式" }; dl.Options.Put("封面大图形式", "Max").Put("封面小图形式", "Min"); return(dl); }); subEntity.Update(new Subject { IsPicture = String.Equals(m, "Max") }); break; case "Del": subEntity.Update(new Subject { Visible = -1, LastDate = DateTime.Now }); //subEntity.Delete(); this.Context.Send("Subject.Del", new WebMeta().Put("Id", sub.Id), false); break; } this.Context.Send("Subject.Save", true); }
public override void ProcessActivity(WebRequest request, WebResponse response) { var Type = this.AsyncDialog("Type", "Client"); var user = UMC.Security.Identity.Current; switch (Type) { case "Client": if (user.IsAuthenticated == false) { response.Redirect(request.Model, "Login"); } break; case "Cashier": if (request.IsCashier == false) { response.Redirect("Settings", "Login"); } break; } var Model = this.AsyncDialog("Model", gkey => { WebMeta form = request.SendValues ?? new UMC.Web.WebMeta(); if (form.ContainsKey("limit") == false) { this.Context.Send(new UISectionBuilder(request.Model, request.Command, request.Arguments) .RefreshEvent("UI.Setting", "image", "Email", "Mobile") .Builder(), true); } var account = Security.Account.Create(user.Id.Value); var dic = UMC.Web.UISection.Create(); var name = user.Name; switch (Type) { default: dic.Title = new UITitle("账户信息"); var imageTextView = new UMC.Web.UI.UIImageTextValue(Data.WebResource.Instance().ImageResolve(user.Id.Value, "1", 4), "头像", ""); imageTextView.Style.Name("image-width", "100"); imageTextView.Click(new UIClick("id", user.Id.ToString(), "seq", "1") { Model = "Design", Command = "Picture" }); //dic.AddImageTextValue(Data.WebResource.Instance().ImageResolve(user.Id.Value, "1", 4), "头像", 100, new UIClick("id", user.Id.ToString(), "seq", "1") //{ Model = "Design", Command = "Picture" }); dic.Add(imageTextView); dic.AddCell("昵称", user.Alias, new UIClick(new WebMeta(request.Arguments).Put(gkey, "Alias")).Send(request.Model, request.Command)); dic.AddCell('\uf084', "登录账号", name, new UIClick() { Model = "Account", Command = "Password" }); break; case "Small": var Discount = new UIHeader.Portrait(Data.WebResource.Instance().ImageResolve(user.Id.Value, "1", 4)); Discount.Value(user.Alias); var ac2 = account[Security.Account.SIGNATURE_ACCOUNT_KEY]; Discount.Time(ac2 == null ? "未有签名" : ac2.Name); var color = 0xfff; Discount.Gradient(color, color); Discount.Click(new UIClick("id", user.Id.ToString(), "seq", "1") { Model = "Design", Command = "Picture" }); var header = new UIHeader(); var style = new UIStyle(); header.AddPortrait(Discount); header.Put("style", style); style.Name("value").Color(0x111).Size(18).Click(new UIClick(new WebMeta(request.Arguments).Put(gkey, "Alias")).Send(request.Model, request.Command)); style.Name("time").Click(new UIClick(new WebMeta(request.Arguments).Put(gkey, "Signature")).Send(request.Model, request.Command)); dic.UIHeader = header; break; } var ac = account[Security.Account.EMAIL_ACCOUNT_KEY]; if (ac != null && String.IsNullOrEmpty(ac.Name) == false) { name = ac.Name; int c = name.IndexOf('@'); if (c > 0) { var cname = name.Substring(0, c); name = name.Substring(0, 2) + "***" + name.Substring(c); } if ((ac.Flags & Security.UserFlags.UnVerification) == Security.UserFlags.UnVerification) { name = name + "(未验证)"; } } else { name = "点击绑定"; } var cui = Type == "Small" ? dic : dic.NewSection(); cui.AddCell('\uf199', "邮箱", name, new UIClick() { Command = "Email", Model = "Account" }); ac = account[Security.Account.MOBILE_ACCOUNT_KEY]; if (ac != null && String.IsNullOrEmpty(ac.Name) == false) { name = ac.Name; if (name.Length > 3) { name = name.Substring(0, 3) + "****" + name.Substring(name.Length - 3); } if ((ac.Flags & Security.UserFlags.UnVerification) == Security.UserFlags.UnVerification) { name = name + "(未验证)"; } } else { name = "点击绑定"; } cui.AddCell('\ue91a', "手机号码", name, new UIClick() { Command = "Mobile", Model = "Account" }); switch (Type) { case "Small": response.Redirect(dic); break; default: ac = account[Security.Account.SIGNATURE_ACCOUNT_KEY]; dic.NewSection().AddCell("个性签名", ac == null ? "未有签名" : ac.Name, new UIClick(new WebMeta(request.Arguments).Put(gkey, "Signature")).Send(request.Model, request.Command)); break; } if (request.IsApp == false && request.IsWeiXin == false) { UICell cell = UICell.Create("UI", new UMC.Web.WebMeta().Put("text", "退出登录").Put("Icon", "\uf011").Put("click", new UIClick() { Model = "Account", Command = "Close" })); cell.Style.Name("text", new UIStyle().Color(0xf00)); dic.NewSection().NewSection().Add(cell); } response.Redirect(dic); return(this.DialogValue("none")); }); switch (Model) { case "Alias": String Alias = this.AsyncDialog("Alias", a => new UITextDialog() { Title = "修改别名", DefaultValue = user.Alias }); Membership.Instance().ChangeAlias(user.Name, Alias); this.Prompt(String.Format("您的账户的别名已修改成{0}", Alias), false); this.Context.Send("UI.Setting", true); break; case "Signature": var account = Security.Account.Create(user.Id.Value); var ac = account[Security.Account.SIGNATURE_ACCOUNT_KEY]; var reset = Web.UIFormDialog.AsyncDialog("value", g => { var selt = new Web.UIFormDialog(); selt.Title = "个性签名"; selt.AddTextarea("个性签名", "Signature", ac == null ? "" : ac.Name); selt.Submit("确认提交", request, "UI.Setting"); return(selt); }); var Signature = reset["Signature"]; Security.Account.Post(Signature, user.Id.Value, Security.UserFlags.Normal, Security.Account.SIGNATURE_ACCOUNT_KEY); WebMeta print = new UMC.Web.WebMeta(); print["type"] = "UI.Setting"; print["Signature"] = Signature; this.Context.Send(print, true); break; } }
public override void ProcessActivity(WebRequest request, WebResponse response) { var refer_id = UMC.Data.Utility.Guid(this.AsyncDialog("Refer", g => { return(new Web.UITextDialog() { Title = "评论的主题" }); })); var user = UMC.Security.Identity.Current; var Id = UMC.Data.Utility.Guid(this.AsyncDialog("Id", g => { return(this.DialogValue(Guid.NewGuid().ToString())); })).Value; var commentEntity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Comment>() .Where.And().In(new Comment { Id = refer_id }, Id).Entities; var commant = commentEntity.Single(); var ui = this.AsyncDialog("UI", g => this.DialogValue("none")); var section = this.AsyncDialog("section", g => this.DialogValue("1")); var row = this.AsyncDialog("row", g => this.DialogValue("1")); var Content = Web.UIDialog.AsyncDialog("Content", g => { var from = new Web.UIFormDialog(); if (commant != null) { from.Title = "回复评论"; } else { from.Title = "评论"; } if (request.IsApp) { var sn = new WebMeta(request.Arguments); sn.Put("Id", Id).Put("Refer", refer_id); var ms = new WebMeta().Put("submit", new UIClick(sn) { Text = commant != null ? "请回复" : "请评论" }.Send(request.Model, request.Command)); this.Context.Send(commant == null ? "Comment" : "Reply", ms, true); } from.AddTextarea("内容", "Content", String.Empty).Put("MinSize", "6"); if (commant == null) { from.AddFiles("图片上传", "Picture").Put("required", "none") .Command("Design", "Picture", new UMC.Web.WebMeta().Put("id", Id)); } from.Submit(commant != null ? "确认回复" : "确认评论", request, "UI.Event"); return(from); }); var image = this.AsyncDialog("image", "none"); if (image != "none") { var webr = UMC.Data.WebResource.Instance(); var imgs = image.Split(','); var ls = new List <Picture>(); for (var i = 0; i < imgs.Length; i++) { webr.Transfer(new Uri(imgs[i]), Id, i + 1); ls.Add(new Picture { group_id = Id, Seq = i + 1, UploadDate = DateTime.Now, user_id = user.Id }); } if (ls.Count > 0) { var entity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Picture>(); entity.Where.And().Equal(new UMC.Data.Entities.Picture { group_id = Id }).Entities.Delete(); entity.Insert(ls.ToArray()); } } if (commant != null) { if (commant.Id == Id) { return; } var forId = commant.for_id ?? Guid.Empty; if (forId == Guid.Empty) { forId = commant.Id.Value; } var entity = Utility.CMS.ObjectEntity <Subject>() .Where.And().Equal(new Subject { Id = commant.ref_id }).Entities; var sinle = entity.Single(new Subject { Reply = 0, project_id = Guid.Empty }); if (sinle != null) { if (sinle.Reply.HasValue) { entity.Update("{0}+{1}", new Subject { Reply = 1 }); } else { entity.Update(new Subject { Reply = 1 }); } } commentEntity.Insert(new Comment { Id = Id, CommentDate = DateTime.Now, for_id = forId, ref_id = commant.ref_id, Content = Content, Effective = 0, Farworks = 0, Invalid = 0, project_id = sinle != null ? sinle.project_id : null, Reply = 0, Score = 0, Unhealthy = 0, Visible = 0, Poster = user.Alias, user_id = user.Id }); var cm = Utility.CMS.ObjectEntity <UMC.Data.Entities.Comment>() .Where.And().Equal(new Data.Entities.Comment { Id = commant.Id }) .Entities.Single(); var editer = new Web.UISection.Editer(section, row); editer.Put((Utility.Comment(cm, request.Model)), false); editer.Builder(this.Context, ui, true); } else { var entity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>() .Where.And().Equal(new Subject { Id = refer_id }).Entities; var sinle = entity.Single(new Subject { Reply = 0, project_id = Guid.Empty }); commentEntity.Insert(new Comment { Id = Id, CommentDate = DateTime.Now, for_id = Guid.Empty, ref_id = refer_id, project_id = sinle != null ? sinle.project_id : null, Content = Content, Effective = 0, Farworks = 0, Invalid = 0, Reply = 0, Score = 0, Unhealthy = 0, Visible = 0, Poster = user.Alias, user_id = user.Id }); if (sinle != null) { if (sinle.Reply.HasValue) { entity.Update("{0}+{1}", new Subject { Reply = 1 }); } else { entity.Update(new Subject { Reply = 1 }); } var editer = new Web.UISection.Editer(1, 1); var cm = Utility.CMS.ObjectEntity <UMC.Data.Entities.Comment>() .Where.And().Equal(new Data.Entities.Comment { Id = Id, for_id = Guid.Empty }) .Entities.Single(); if (commentEntity.Where.Reset().And().Equal(new Comment { ref_id = refer_id, for_id = Guid.Empty }).And().Greater(new Comment { Visible = -1 }).Entities.Count() == 1) { editer.Put(Utility.Comment(cm, request.Model), false); } else { editer.Insert(Utility.Comment(cm, request.Model)); } editer.Builder(this.Context, ui, true); } } }
public override void ProcessActivity(WebRequest request, WebResponse response) { var Id = UMC.Data.Utility.Guid(this.AsyncDialog("Id", g => { this.Prompt("请输入参数"); return(this.DialogValue("none")); }), true); if (String.IsNullOrEmpty(request.SendValue) == false) { this.Context.Send(new UISectionBuilder(request.Model, request.Command, new UMC.Web.WebMeta().Put("Id", Id)) .RefreshEvent("Subject.Save", "Subject.WeiXin") .Builder(), true); } var subEntity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>(); subEntity.Where.And().Equal(new Subject { Id = Id }); var sub = subEntity.Single(); var webr = UMC.Data.WebResource.Instance(); //var appid = "wx141d18e076be64a1"; var user = UMC.Security.Identity.Current; var appid = user.Id.ToString(); var config = Data.JSON.Deserialize <Hashtable>(sub.ConfigXml) ?? new Hashtable(); var imageKey = config["images"] as Hashtable ?? new Hashtable(); config["images"] = imageKey; Array articleids = config["articles"] as Array; var subsid = new List <Guid>(); if (articleids != null) { foreach (var o in articleids) { subsid.Add(Utility.Guid(o.ToString()).Value); } } var Model = this.AsyncDialog("Model", gKey => { UITitle uITItle = UITitle.Create(); uITItle.Title = "公众号群发"; var sestion = UISection.Create(uITItle); var src = webr.ResolveUrl(sub.Id.Value, 1, "0") + "!cms1"; if (subsid.Count == 0) { var image = UICell.Create("CMSImage", new UMC.Web.WebMeta().Put("src", src)); image.Style.Padding(0, 10); var title = new UIDesc(sub.Title); title.Style.Bold().Height(40).Name("border", "none"); title.Click(new UIClick("Id", Id.ToString(), gKey, "Title") { Model = request.Model, Command = request.Command }); var desc = new UIDesc(sub.Description ?? sub.Title); desc.Style.Height(40).Color(0x999).Name("border", "none"); desc.Click(new UIClick("Id", Id.ToString(), gKey, "Desc") { Model = request.Model, Command = request.Command }); sestion.Add(title) .Add(image) .Add(desc); } else { var image = UICell.Create("CMSImage", new UMC.Web.WebMeta().Put("src", src).Put("title", sub.Title)); image.Style.Padding(10, 10, 0, 10); image.Format.Put("title", "{title}"); sestion.Add(image); Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>() .Where.And().In(new Subject { Id = subsid[0] }, subsid.ToArray()) .Entities.Query(dr => { var cell = new UIImageTextValue(webr.ResolveUrl(sub.Id.Value, 1, "0") + "!200", dr.Title, null); cell.Style.Name("image-width", 60); cell.Click(new UIClick("Id", dr.Id.ToString(), gKey, "Items") { Model = request.Model, Command = request.Command }); var item = new UMC.Web.WebMeta().Put("_CellName", cell.Type).Put("value", cell.Data).Put("format", cell.Format).Put("style", cell.Style) .Put("del", new UMC.Web.WebMeta().Put("click", new UIClick("Id", Id.ToString(), gKey, "Del", "Item", dr.Id.ToString()) { Model = request.Model, Command = request.Command })); sestion.AddCells(item); }); } var ctip = "未同步公众号"; var ModifiedTime = config["ModifiedTime"] as string; if (String.IsNullOrEmpty(ModifiedTime) == false) { ctip = String.Format("已同步公众号", Utility.GetDate(Utility.TimeSpan(Utility.IntParse(ModifiedTime, 0)))); } var ls = sestion.NewSection().AddCell("图文封面", config.ContainsKey("thumb_media_id") ? "已同步公众号" : "未同步公众号", new UIClick("Id", Id.ToString(), gKey, "Thumb") { Model = request.Model, Command = request.Command }).AddCell("图文正文", ctip, new UIClick("Id", Id.ToString(), gKey, "Content") { Model = request.Model, Command = request.Command }); var mstatus = ""; if (config.ContainsKey("ContentLoading")) { mstatus = "正在同步请等候"; } else { mstatus = config.ContainsKey("media_id") ? "已在公众生成" : "未在公众号生成"; } ls.AddCell("群发素材", mstatus, new UIClick("Id", Id.ToString(), gKey, "Material") { Model = request.Model, Command = request.Command }) .NewSection().AddCell("使用帮助", "查看", UIClick.Pager("Message", "UIData", new UMC.Web.WebMeta().Put("Id", "Help.SendWeiXin"))); sestion.UIFootBar = new UIFootBar().AddText(new UIEventText("追加图文") .Click(new UIClick("Id", Id.ToString(), "Model", "Preview") { Model = request.Model, Command = request.Command }), new UIEventText("微信预览") .Click(new UIClick("Id", Id.ToString(), "Model", "Articles") { Model = request.Model, Command = request.Command }).Style(new UIStyle().BgColor()), new UIEventText("确认群发").Click(new UIClick("Id", Id.ToString(), "Model", "SendAll") { Model = request.Model, Command = request.Command })); sestion.UIFootBar.IsFixed = true; response.Redirect(sestion); return(this.DialogValue("none")); }); switch (Model) { case "Articles": { var sudId = Utility.Guid(this.AsyncDialog("Articles", request.Model, "Select")).Value; var config2 = Data.JSON.Deserialize <Hashtable>(sub.ConfigXml) ?? new Hashtable(); Array articles2 = config2["articles"] as Array; var subsid2 = new List <Guid>(); if (articles2 != null) { foreach (var o in articles2) { subsid.Add(Utility.Guid(o.ToString()).Value); } } subsid.Remove(sudId); subsid.Add(sudId); config2["articles"] = subsid; subEntity.Update(new Subject { ConfigXml = Data.JSON.Serialize(config2) }); } break; case "Title": var title = Web.UIDialog.AsyncDialog("Title", g => { var dl = new Web.UIFormDialog() { Title = "图文标题" }; dl.AddTextarea("图文标题", "Title", sub.Title); dl.Submit("确认更改", request, "Subject.Save"); return(dl); }); subEntity.Update(new Subject { Title = title }); this.Context.Send("Subject.Save", true); break; case "Desc": var desc = Web.UIDialog.AsyncDialog("Description", g => { var dl = new Web.UIFormDialog() { Title = "图文摘要" }; dl.AddTextarea("图文摘要", "Description", sub.Description); dl.Submit("确认更改", request, "Subject.WeiXin"); return(dl); }); subEntity.Update(new Subject { Description = desc }); break; case "Thumb": if (webr.SubmitCheck(appid) == false) { response.Redirect("Message", "Auth"); } if (config.ContainsKey("thumb_media_id")) { var thumb_media_id = config["thumb_media_id"] as string; webr.Submit("cgi-bin/material/del_material", Data.JSON.Serialize(new UMC.Web.WebMeta().Put("media_id", thumb_media_id)), appid); } var src = webr.ResolveUrl(sub.Id.Value, 1, "0") + "!cms1"; var data = webr.Submit("cgi-bin/material/add_material&type=image", src, appid); if (data.ContainsKey("media_id") == false) { this.Prompt("同步封面图片失败"); } else { config["thumb_media_id"] = data["media_id"]; subEntity.Update(new Subject { ConfigXml = Data.JSON.Serialize(config) }); this.Prompt("最新封面成功同步到公众号。", false); } break; case "Content": if (webr.SubmitCheck(appid) == false) { response.Redirect("Message", "Auth"); } if (config.ContainsKey("thumb_media_id") == false) { this.Prompt("请先同步封面,再来同步正文"); } var ModifiedTime = Utility.IntParse(config["ModifiedTime"] as string ?? "", 0); if (Utility.TimeSpan() - ModifiedTime < 10) { this.Prompt("提示", "正在同步,请过一会再更新"); } var res = this.AsyncDialog("Content", g => { if (request.SendValues != null) { var url = request.SendValues["Url"]; if (String.IsNullOrEmpty(url) == false) { return(this.DialogValue(System.Text.UTF8Encoding.UTF8.GetString(new UMC.Net.HttpClient().DownloadData(url)))); } } var domUrl = new Uri(request.UrlReferrer ?? request.Url, String.Format("{0}Show/{1}/UIMin/Id/{2}", webr.WebDomain(), request.Model, sub.Id)).AbsoluteUri; this.Context.Send(new UMC.Web.WebMeta().Put("type", "OpenUrl").Put("selector", "#body section", "value", domUrl).Put("title", "正文同步到公众号素材") .Put("submit", new Web.UIClick("Id", sub.Id.ToString(), "Model", "Content", "Url", "Value") { Command = request.Command, Model = request.Model }), true); return(this.DialogValue("none")); }); config["ContentLoading"] = "YES"; subEntity.Update(new Subject { ConfigXml = Data.JSON.Serialize(config) }); UMC.Data.Reflection.Start(() => { var udata = new Subject(); try { var content = Content(res, appid, imageKey); config["ModifiedTime"] = Utility.TimeSpan(); config.Remove("ContentLoading"); udata.Content = content; } catch (Exception ex) { config.Remove("ContentLoading"); config["result"] = ex.Message; } finally { udata.ConfigXml = Data.JSON.Serialize(config); subEntity.Update(udata); } }); break; case "Material": if (webr.SubmitCheck(appid) == false) { response.Redirect("Message", "Auth"); } if (config.ContainsKey("ModifiedTime") == false) { this.Prompt("提示", String.Format("“{0}”正文未同步到公众号", sub.Title)); } if (config.ContainsKey("thumb_media_id") == false) { this.Prompt("提示", String.Format("“{0}”封面未同步到公众号", sub.Title)); } if (config.ContainsKey("media_id")) { webr.Submit("cgi-bin/material/del_material", Data.JSON.Serialize(new UMC.Web.WebMeta().Put("media_id", config["media_id"])), appid); } var content_source_url = new Uri(request.Url, String.Format("{0}Page/{1}/UIData/Id/{2}", webr.WebDomain(), request.Model, sub.Id)).AbsoluteUri; var articles = new List <WebMeta>(); articles.Add(new UMC.Web.WebMeta().Put("title", sub.Title) .Put("author", user.Alias) .Put("digest", sub.Description ?? sub.Title) .Put("thumb_media_id", config["thumb_media_id"]) .Put("content", sub.Content) .Put("show_cover_pic", 0) .Put("content_source_url", content_source_url) .Put("need_open_comment", (sub.IsComment ?? true) ? 1 : 0)); var subs = new List <Subject>(); if (subsid.Count > 0) { Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>().Where.And().In(new Subject { Id = subsid[0] }, subsid.ToArray()) .Entities.Query(dr => subs.Add(dr)); foreach (var key in subsid) { var csub = subs.Find(g => g.Id == key); var sconfig = Data.JSON.Deserialize <Hashtable>(csub.ConfigXml) ?? new Hashtable(); if (sconfig.ContainsKey("ModifiedTime") == false) { this.Prompt("提示", String.Format("“{0}”正文未同步到公众号", csub.Title)); } if (sconfig.ContainsKey("thumb_media_id") == false) { this.Prompt("提示", String.Format("“{0}”封面未同步到公众号", csub.Title)); } content_source_url = new Uri(request.Url, String.Format("{0}Page/{1}/UIData/Id/{2}", webr.WebDomain(), request.Model, csub.Id)).AbsoluteUri; articles.Add(new UMC.Web.WebMeta().Put("title", csub.Title) .Put("author", user.Alias) .Put("digest", csub.Description ?? csub.Title) .Put("thumb_media_id", sconfig["thumb_media_id"]) .Put("content", csub.Content) .Put("show_cover_pic", 0) .Put("content_source_url", content_source_url) .Put("need_open_comment", (sub.IsComment ?? true) ? 1 : 0)); } } var sData = webr.Submit("cgi-bin/material/add_news", Data.JSON.Serialize(new UMC.Web.WebMeta().Put("articles", articles)), appid); if (sData.ContainsKey("media_id") == false) { this.Prompt("提示", "上传图文素材失败"); } else { config["media_id"] = sData["media_id"]; config["MediaTime"] = Utility.TimeSpan(); config["result"] = "ok"; subEntity.Update(new Subject { ConfigXml = Data.JSON.Serialize(config) }); this.Prompt("提示", "最新图文素材成功更新到公众号。", false); } break; case "SendAll": if (webr.SubmitCheck(appid) == false) { response.Redirect("Message", "Auth"); } if (config.ContainsKey("media_id") == false) { this.Prompt("提示", "请先生成群发素材"); } if (config.ContainsKey("msg_id")) { var msgData = webr.Submit("cgi-bin/message/mass/get", Data.JSON.Serialize(new UMC.Web.WebMeta().Put("msg_id", config["msg_id"])), appid); switch (msgData["msg_status"] as string) { case "SEND_SUCCESS": this.Prompt("提示", "群发发送成功"); break; case "SENDING": this.Prompt("提示", "群发正在发送中"); break; case "SEND_FAIL": this.Prompt("提示", "群发发送失败,请在公众号后台查看"); break; case "DELETE": this.Prompt("提示", "信息已经删除"); break; } } var tag = this.AsyncDialog("tag", t => { var appKey = UMC.Security.Principal.Current.AppKey ?? Guid.Empty; if (appKey == Guid.Empty) { return(this.DialogValue("-1")); } var tags = webr.Submit("cgi-bin/tags/get", String.Empty, appid); if (String.Equals(tags["errcode"], "48001")) { return(this.DialogValue("-1")); } var header = new Web.UIGridDialog.Header("id", 0); header.AddField("name", "粉丝标签"); header.AddField("count", "粉丝数"); var ls = new ArrayList(); ls.Add(new UMC.Web.WebMeta().Put("id", "-1", "name", "所有粉丝", "count", "all")); ls.AddRange(tags["tags"] as Array); var di = Web.UIGridDialog.Create(header, ls.ToArray()); di.Title = "群发的粉丝"; return(di); }); var filter = new UMC.Web.WebMeta().Put("is_to_all", tag == "-1"); if (tag != "-1") { filter.Put("tag_id", tag); } var sendall = new UMC.Web.WebMeta().Put("msgtype", "mpnews").Put("send_ignore_reprint", 0).Put("clientmsgid", Utility.Guid(sub.Id.Value)) .Put("filter", filter).Put("mpnews", new UMC.Web.WebMeta().Put("media_id", config["media_id"])); var sendData = webr.Submit("cgi-bin/message/mass/sendall", Data.JSON.Serialize(sendall), appid); if (sendData.ContainsKey("msg_data_id")) { config["msg_id"] = sendData["msg_id"]; config["msg_data_id"] = sendData["msg_data_id"]; config["clientmsgid"] = sub.Id; subEntity.Update(new Subject { ConfigXml = Data.JSON.Serialize(config) }); this.Prompt("提示", "群发指令已经成功提交"); } else { var errcode = (sendData["errcode"] ?? "").ToString(); switch (errcode) { case "0": this.Prompt("发送成功"); break; case "48001": this.Prompt("群发失败", "此公众号未认证"); break; default: this.Prompt("群发失败", "请确认此微信号已经关注公众号"); break; } } break; case "Preview": if (webr.SubmitCheck(appid) == false) { this.Context.Send(new UISectionBuilder("Message", "UIData", new UMC.Web.WebMeta().Put("Id", "Help.Auth")) .Builder(), true); } if (config.ContainsKey("media_id") == false) { this.Prompt("提示", "请先生成群发素材"); } else { var touser = Web.UIDialog.AsyncDialog("Touser", g => { var dl = new Web.UIFormDialog() { Title = "微信号" }; dl.AddText("微信号", "Touser", String.Empty); dl.Submit("确认", request, "Subject.WeiXin"); return(dl); }); //touser = "******"; var preview = new UMC.Web.WebMeta().Put("msgtype", "mpnews") .Put("touser", touser).Put("mpnews", new UMC.Web.WebMeta().Put("media_id", config["media_id"])); var rdata = webr.Submit("cgi-bin/message/mass/preview", Data.JSON.Serialize(preview), appid); var errcode = (rdata["errcode"] ?? "").ToString(); switch (errcode) { case "0": this.Prompt("发送成功"); break; case "48001": this.Prompt("发送失败", "此公众号未认证"); break; default: this.Prompt("发送失败", "请确认此微信号已经关注公众号"); break; } } break; case "Items": this.AsyncDialog("Items", g => { var dl = new Web.UISheetDialog() { Title = "公众号同步" }; dl.Options.Add(new UIClick("Id", Id.ToString(), "Model", "Thumb") { Text = "封面同步到公众号", Model = request.Model, Command = request.Command }); dl.Options.Add(new UIClick("Id", Id.ToString(), "Model", "Content") { Text = "正文同步到公众号", Model = request.Model, Command = request.Command }); return(dl); }); break; case "Del": var itemid = Utility.Guid(this.AsyncDialog("Item", "aut")); if (itemid.HasValue) { subsid.Remove(itemid.Value); config["articles"] = subsid; subEntity.Update(new Subject { ConfigXml = Data.JSON.Serialize(config) }); } break; } this.Context.Send("Subject.WeiXin", true); }