//批量删除 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("weixin_account_manage", PLEnums.ActionEnum.Delete.ToString()); //检查权限 int sucCount = 0; int errorCount = 0; BLL.weixin_account bll = new BLL.weixin_account(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { if (bll.Delete(id)) { sucCount += 1; } else { errorCount += 1; } } } AddAdminLog(PLEnums.ActionEnum.Delete.ToString(), "删除微信公众平台成功" + sucCount + "条,失败" + errorCount + "条"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("account_list.aspx", "keywords={0}", this.keywords)); }
//批量删除 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("weixin_account_manage", DTEnums.ActionEnum.Delete.ToString()); //检查权限 int sucCount = 0; int errorCount = 0; BLL.weixin_account bll = new BLL.weixin_account(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { if (bll.Delete(id)) { sucCount += 1; } else { errorCount += 1; } } } AddAdminLog(DTEnums.ActionEnum.Delete.ToString(), "删除微信公众平台成功" + sucCount + "条,失败" + errorCount + "条"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("account_list.aspx", "keywords={0}", this.keywords)); }
private bool DoAdd() { bool result = false; Model.weixin_account model = new Model.weixin_account(); BLL.weixin_account bll = new BLL.weixin_account(); model.name = txtName.Text.Trim(); model.originalid = txtOriginalId.Text.Trim(); model.wxcode = txtWxCode.Text.Trim(); model.token = txtToKen.Text.Trim(); model.appid = txtAppId.Text.Trim(); model.appsecret = txtAppSecret.Text.Trim(); if (cbIsPush.Checked == true) { model.is_push = 1; } else { model.is_push = 0; } model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); if (bll.Add(model) > 0) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "增加公众账户:" + model.name); //记录日志 result = true; } return result; }
private bool DoAdd() { bool result = false; Model.weixin_account model = new Model.weixin_account(); BLL.weixin_account bll = new BLL.weixin_account(); model.name = txtName.Text.Trim(); model.originalid = txtOriginalId.Text.Trim(); model.wxcode = txtWxCode.Text.Trim(); model.token = txtToKen.Text.Trim(); model.appid = txtAppId.Text.Trim(); model.appsecret = txtAppSecret.Text.Trim(); if (cbIsPush.Checked == true) { model.is_push = 1; } else { model.is_push = 0; } model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); if (bll.Add(model) > 0) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "增加公众账户:" + model.name); //记录日志 result = true; } return(result); }
private void WeiXinBind() { Model.weixin_account model = new BLL.weixin_account().GetModel(); if (model == null || model.is_push == 0) { this.btnWxPost.Visible = false; } }
/// <summary> /// 返回第一个微信公众号信息 /// </summary> /// <returns></returns> protected Model.weixin_account GetWxAccountModel() { string requestDomain = HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号 string requestPath = HttpContext.Current.Request.RawUrl.ToLower(); //当前的URL地址 string sitePath = GetSitePath(requestPath, requestDomain); BLL.weixin_account wxBll = new BLL.weixin_account(); Model.weixin_account modelt = wxBll.GetModel(1); return(modelt); }
private void TreeBind() { BLL.weixin_account bll = new BLL.weixin_account(); DataTable dt = bll.GetList(0, "", "sort_id asc,id desc").Tables[0]; this.ddlAccountId.Items.Clear(); this.ddlAccountId.Items.Add(new ListItem("请选择公众账户", "")); foreach (DataRow dr in dt.Rows) { this.ddlAccountId.Items.Add(new ListItem(dr["name"].ToString(), dr["id"].ToString())); } }
private void RptBind(string _strWhere, string _orderby) { this.page = DTRequest.GetQueryInt("page", 1); this.txtKeywords.Text = this.keywords; BLL.weixin_account bll = new BLL.weixin_account(); this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount); this.rptList.DataBind(); //绑定页码 txtPageNum.Text = this.pageSize.ToString(); string pageUrl = Utils.CombUrlTxt("account_list.aspx", "keywords={0}&page={1}", this.keywords, "__id__"); PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8); }
/// <summary> /// 重写虚方法,此方法将在Init事件前执行 /// </summary> protected override void ShowPage() { int weixinId = DTRequest.GetQueryInt("wxid"); string url = "http://" + DTRequest.GetHost() + HttpContext.Current.Request.RawUrl; BLL.weixin_account wxBll = new BLL.weixin_account(); Model.weixin_account modelt = wxBll.GetModel(weixinId); if (modelt != null) { string ticket = JsApiTicketContainer.TryGetJsApiTicket(modelt.appid, modelt.appsecret); jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(modelt.appid, modelt.appsecret, url); } this.Init += new EventHandler(article_show_Init); }
private void WeiXinBind() { DataTable dt = new BLL.weixin_account().GetList(0, "is_push=1", "sort_id asc,id desc").Tables[0]; if (dt.Rows.Count == 0) { this.ddlWXPost.Visible = false; return; } this.ddlWXPost.Items.Clear(); this.ddlWXPost.Items.Add(new ListItem("微信推送", "")); foreach (DataRow dr in dt.Rows) { this.ddlWXPost.Items.Add(new ListItem("├ " + dr["name"].ToString(), dr["id"].ToString())); } }
//保存排序 protected void btnSave_Click(object sender, EventArgs e) { ChkAdminLevel("weixin_account_manage", DTEnums.ActionEnum.Edit.ToString()); //检查权限 BLL.weixin_account bll = new BLL.weixin_account(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); int sortId; if (!int.TryParse(((TextBox)rptList.Items[i].FindControl("txtSortId")).Text.Trim(), out sortId)) { sortId = 99; } bll.UpdateField(id, "sort_id=" + sortId); } AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "保存公众账户排序"); //记录日志 JscriptMsg("保存排序成功!", Utils.CombUrlTxt("account_list.aspx", "keywords={0}", this.keywords)); }
//批量清空菜单 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("weixin_custom_menu", DTEnums.ActionEnum.Delete.ToString()); //检查权限 int sucCount = 0; int errorCount = 0; CRMComm cpp = new CRMComm(); BLL.weixin_account bll = new BLL.weixin_account(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { Model.weixin_account model = new BLL.weixin_account().GetModel(id); if (model != null) { string error = string.Empty; //定义错误 string token = cpp.GetAccessToken(id, out error); //获取最新的AccessToken if (string.IsNullOrEmpty(error)) { var result = Senparc.Weixin.MP.CommonAPIs.CommonApi.DeleteMenu(token); if ((int)result.errcode == 0) { sucCount += 1; } else { errorCount += 1; } } else { errorCount += 1; } } else { errorCount += 1; } } } AddAdminLog(DTEnums.ActionEnum.Delete.ToString(), "清空公众平台自定义菜单成功" + sucCount + "条,失败" + errorCount + "条"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("menu_list.aspx", "keywords={0}", this.keywords)); }
//保存排序 protected void btnSave_Click(object sender, EventArgs e) { ChkAdminLevel("weixin_account_manage", PLEnums.ActionEnum.Edit.ToString()); //检查权限 BLL.weixin_account bll = new BLL.weixin_account(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); int sortId; if (!int.TryParse(((TextBox)rptList.Items[i].FindControl("txtSortId")).Text.Trim(), out sortId)) { sortId = 99; } bll.UpdateField(id, "sort_id=" + sortId); } AddAdminLog(PLEnums.ActionEnum.Edit.ToString(), "保存公众账户排序"); //记录日志 JscriptMsg("保存排序成功!", Utils.CombUrlTxt("account_list.aspx", "keywords={0}", this.keywords)); }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { BLL.weixin_account bll = new BLL.weixin_account(); Model.weixin_account model = bll.GetModel(); if (model == null) { model = new Model.weixin_account(); } model.name = txtName.Text.Trim(); model.originalid = txtOriginalId.Text.Trim(); model.wxcode = txtWxCode.Text.Trim(); model.token = txtToKen.Text.Trim(); model.appid = txtAppId.Text.Trim(); model.appsecret = txtAppSecret.Text.Trim(); if (cbIsPush.Checked == true) { model.is_push = 1; } else { model.is_push = 0; } //保存数据 if (model.id > 0) { if (bll.Update(model)) { AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "编辑公众账户:" + model.name); //记录日志 JscriptMsg("编辑公众账户成功!", "account_edit.aspx"); return; } } else { if (bll.Add(model) > 0) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "增加公众账户:" + model.name); //记录日志 JscriptMsg("编辑公众账户成功!", "account_edit.aspx"); return; } } JscriptMsg("保存过程中发生错误!", string.Empty); return; }
private void ShowInfo(int _id) { BLL.weixin_account bll = new BLL.weixin_account(); Model.weixin_account model = bll.GetModel(_id); txtName.Text = model.name; txtOriginalId.Text = model.originalid; txtWxCode.Text = model.wxcode; txtToKen.Text = model.token; txtAppId.Text = model.appid; txtAppSecret.Text = model.appsecret; if (model.is_push== 1) { cbIsPush.Checked = true; } else { cbIsPush.Checked = false; } txtSortId.Text = model.sort_id.ToString(); }
private void ShowInfo(int _id) { BLL.weixin_account bll = new BLL.weixin_account(); Model.weixin_account model = bll.GetModel(_id); txtName.Text = model.name; txtOriginalId.Text = model.originalid; txtWxCode.Text = model.wxcode; txtToKen.Text = model.token; txtAppId.Text = model.appid; txtAppSecret.Text = model.appsecret; if (model.is_push == 1) { cbIsPush.Checked = true; } else { cbIsPush.Checked = false; } txtSortId.Text = model.sort_id.ToString(); }
private void ShowInfo() { BLL.weixin_account bll = new BLL.weixin_account(); Model.weixin_account model = bll.GetModel(); if (model != null) { txtName.Text = model.name; txtOriginalId.Text = model.originalid; txtWxCode.Text = model.wxcode; txtToKen.Text = model.token; txtAppId.Text = model.appid; txtAppSecret.Text = model.appsecret; if (model.is_push == 1) { cbIsPush.Checked = true; } else { cbIsPush.Checked = false; } } }
protected void Page_Load(object sender, EventArgs e) { string token = string.Empty; //与微信公众账号后台的Token设置保持一致,区分大小写。 int uid = DTRequest.GetQueryInt("uid", 0); if (uid == 0) { WriteContent("参数非法"); return; } token = new BLL.weixin_account().GetToken(uid); //获取公众账户的ToKen if (string.IsNullOrEmpty(token)) { WriteContent("不存在的公众账户!"); return; } //获取微信传送参数 string signature = Request["signature"]; string timestamp = Request["timestamp"]; string nonce = Request["nonce"]; string echostr = Request["echostr"]; if (Request.HttpMethod == "GET") { //GET-仅在微信后台填写URL验证时触发 if (Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, token)) { WriteContent(echostr); //返回随机字符串则表示验证通过 } else { WriteContent("failed:" + signature + ",token:" + token + " " + Senparc.Weixin.MP.CheckSignature.GetSignature(timestamp, nonce, token) + "。" + "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。"); } Response.End(); } else { //POST-当有用户想公众账号发送消息时触发 if (!Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, token)) { WriteContent("参数错误!"); return; } //可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制 var maxRecordCount = 10; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new CustomMessageHandler(Request.InputStream, maxRecordCount); try { //执行微信处理过程 messageHandler.Execute(); WriteContent(messageHandler.ResponseDocument.ToString()); return; } catch (Exception ex) { //写日志 /*using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) * { * tw.WriteLine(ex.Message); * tw.WriteLine(ex.InnerException.Message); * if (messageHandler.ResponseDocument != null) * { * tw.WriteLine(messageHandler.ResponseDocument.ToString()); * } * tw.Flush(); * tw.Close(); * }*/ WriteContent(""); } finally { Response.End(); } } }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { try { string error = string.Empty; string accessToken = cpp.GetAccessToken(this.id, out error); Model.weixin_account accountModel = new BLL.weixin_account().GetModel(this.id); if (!string.IsNullOrEmpty(error)) { JscriptMsg(error, string.Empty); return; } //重新整理按钮信息 ButtonGroup bg = new ButtonGroup(); TextBox txtName = new TextBox(); TextBox txtKey = new TextBox(); TextBox txtUrl = new TextBox(); IList <BaseButton> topList = new List <BaseButton>(); IList <SingleButton> subList = new List <SingleButton>(); //菜单设置 for (int i = 0; i < 3; i++) { txtName = this.FindControl("txtTop" + (i + 1) + "Name") as TextBox; txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox; txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox; if (txtName.Text.Trim() == "") { // 如果名称为空,则忽略该菜单,以及下面的子菜单 continue; } subList = new List <SingleButton>(); TextBox txtSubName = new TextBox(); TextBox txtSubKey = new TextBox(); TextBox txtSubUrl = new TextBox(); for (int j = 0; j < 5; j++) { //子菜单的设置 txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Name") as TextBox; txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox; txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox; if (txtSubName.Text.Trim() == "") { continue; } if (txtSubUrl.Text.Trim() != "") { SingleViewButton sub = new SingleViewButton(); sub.name = txtSubName.Text.Trim(); //2015-6-8 链接跳转加入OAuth授权 //删除OAuth授权 //sub.url = txtSubUrl.Text.Trim().Contains("https://open.weixin.qq.com/") ? txtSubUrl.Text.Trim() : // OAuth.GetAuthorizeUrl(accountModel.appid, txtSubUrl.Text.Trim(), "1", OAuthScope.snsapi_base); sub.url = txtSubUrl.Text.Trim(); subList.Add(sub); } else if (txtSubKey.Text.Trim() != "") { SingleClickButton sub = new SingleClickButton(); sub.name = txtSubName.Text.Trim(); sub.key = txtSubKey.Text.Trim(); subList.Add(sub); } else { //报错 :子菜单必须有key和name JscriptMsg("二级菜单的名称和key或者url必填!", string.Empty); return; } } if (subList != null && subList.Count > 0) { //有子菜单, 该一级菜单是SubButton if (subList.Count < 1) { JscriptMsg("子菜单个数必须为2至5个!", string.Empty); return; } SubButton topButton = new SubButton(Utils.CutString(txtName.Text.Trim(), 16)); topButton.sub_button.AddRange(subList); topList.Add(topButton); } else { // 无子菜单 if (txtKey.Text.Trim() == "" && txtUrl.Text.Trim() == "") { JscriptMsg("如无子菜单,必须填写Key或者URL值!", string.Empty); return; } if (txtUrl.Text.Trim() != "") { //view 页面跳转 SingleViewButton topSingleButton = new SingleViewButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.url = txtUrl.Text.Trim(); topList.Add(topSingleButton); } else if (txtKey.Text.Trim() != "") { SingleClickButton topSingleButton = new SingleClickButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.key = txtKey.Text.Trim(); topList.Add(topSingleButton); } } } bg.button.AddRange(topList); var result = mMrg.CreateMenu(accessToken, bg); JscriptMsg("自定义菜单保存成功!", "menu_list.aspx"); } catch (Exception ex) { JscriptMsg("出错了:" + ex.Message, "menu_list.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { string token = new BLL.weixin_account().GetToken(); //与微信公众账号后台的Token设置保持一致,区分大小写。 if (string.IsNullOrEmpty(token)) { WriteContent("请先添加公众账户!"); return; } //获取微信传送参数 string signature = Request["signature"]; string timestamp = Request["timestamp"]; string nonce = Request["nonce"]; string echostr = Request["echostr"]; if (Request.HttpMethod == "GET") { //GET-仅在微信后台填写URL验证时触发 if (Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, token)) { WriteContent(echostr); //返回随机字符串则表示验证通过 } else { WriteContent("failed:" + signature + ",token:" + token + " " + Senparc.Weixin.MP.CheckSignature.GetSignature(timestamp, nonce, token) + "。" + "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。"); } Response.End(); } else { //POST-当有用户想公众账号发送消息时触发 if (!Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, token)) { WriteContent("参数错误!"); return; } //可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制 var maxRecordCount = 10; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new CustomMessageHandler(Request.InputStream, maxRecordCount); try { //执行微信处理过程 messageHandler.Execute(); WriteContent(messageHandler.ResponseDocument.ToString()); return; } catch (Exception ex) { //写日志 /*using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) { tw.WriteLine(ex.Message); tw.WriteLine(ex.InnerException.Message); if (messageHandler.ResponseDocument != null) { tw.WriteLine(messageHandler.ResponseDocument.ToString()); } tw.Flush(); tw.Close(); }*/ WriteContent(""); } finally { Response.End(); } } }
protected void Page_Load(object sender, EventArgs e) { int uid = DTRequest.GetQueryInt("uid", 0); if (uid == 0) { WriteContent("参数非法"); return; } Model.weixin_account model = new BLL.weixin_account().GetModel(uid); //获取公众账户信息 if (model == null || string.IsNullOrEmpty(model.token)) { WriteContent("不存在的公众账户!"); return; } //获取微信传送参数 string signature = Request["signature"]; string timestamp = Request["timestamp"]; string nonce = Request["nonce"]; string echostr = Request["echostr"]; if (Request.HttpMethod == "GET") { //GET-仅在微信后台填写URL验证时触发 if (Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, model.token)) { WriteContent(echostr); //返回随机字符串则表示验证通过 } else { WriteContent("failed:" + signature + ",token:" + model.token + " " + Senparc.Weixin.MP.CheckSignature.GetSignature(timestamp, nonce, model.token) + "。" + "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。"); } Response.End(); } else { if (!Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, model.token)) { WriteContent("参数错误!"); return; } //post method - 当有用户想公众账号发送消息时触发 var postModel = new Senparc.Weixin.MP.Entities.Request.PostModel() { Signature = Request.QueryString["signature"], Msg_Signature = Request.QueryString["msg_signature"], Timestamp = Request.QueryString["timestamp"], Nonce = Request.QueryString["nonce"], //以下保密信息不会(不应该)在网络上传播,请注意 Token = model.token, //EncodingAESKey = model.aeskey, //根据自己后台的设置保持一致 AppId = model.appid //根据自己后台的设置保持一致 }; //v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制 var maxRecordCount = 10; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new CustomMessageHandler(Request.InputStream, postModel, maxRecordCount); try { //执行微信处理过程 messageHandler.Execute(); WriteContent(messageHandler.ResponseDocument.ToString()); return; } catch { /*using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) * { * tw.WriteLine(ex.Message); * tw.WriteLine(ex.InnerException.Message); * if (messageHandler.ResponseDocument != null) * { * tw.WriteLine(messageHandler.ResponseDocument.ToString()); * } * tw.Flush(); * tw.Close(); * }*/ } finally { Response.End(); } } }
//微信推送 protected void btnWxPost_Click(object sender, EventArgs e) { ChkAdminLevel("channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Edit.ToString()); //检查权限 //检查该微信公众号是否开启消息推送功能 Model.weixin_account wxModel = new BLL.weixin_account().GetModel(); if (wxModel == null || wxModel.is_push == 0) { JscriptMsg("微信账户未开启消息推送!", string.Empty); return; } string errmsg = string.Empty; //错误消息 string linkdomain = GetLinkDomain(); //链接网址 List <Model.article> artls = new List <Model.article>(); //选中文章的实体 API.Weixin.Common.CRMComm wxComm = new API.Weixin.Common.CRMComm(); List <Senparc.Weixin.MP.AdvancedAPIs.GroupMessage.NewsModel> ls = new List <Senparc.Weixin.MP.AdvancedAPIs.GroupMessage.NewsModel>(); BLL.article bll = new BLL.article(); Repeater rptList = new Repeater(); if (this.rptList1.Visible == true) { rptList = this.rptList1; } else { rptList = this.rptList2; } for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { Model.article model = bll.GetWXModel(id); //获取文章实体 if (model == null || string.IsNullOrEmpty(model.img_url.Trim())) { JscriptMsg("错误:所选择信息有些没有图片!", string.Empty); return; } artls.Add(model); } } //判断是否超出推送的数量 if (artls.Count == 0 || artls.Count > 10) { JscriptMsg("错误:推送消息数量应在1-10条范围!", string.Empty); return; } //上传及群发消息 foreach (Model.article modelt in artls) { //上传永久素材获取media_id string mediaId = wxComm.UploadForeverMedia(Utils.GetMapPath(modelt.img_url), out errmsg); if (string.IsNullOrEmpty(mediaId)) { JscriptMsg("错误:" + errmsg, string.Empty); return; } //添加消息实体 Senparc.Weixin.MP.AdvancedAPIs.GroupMessage.NewsModel newsModel = new Senparc.Weixin.MP.AdvancedAPIs.GroupMessage.NewsModel(); newsModel.thumb_media_id = mediaId; //图文消息缩略图的media_id newsModel.title = modelt.title; //图文消息的标题 newsModel.content_source_url = linkdomain; //点击“阅读原文”后的页面 newsModel.content = ReplaceImagesPath(modelt.content); //图文消息页面的内容,替换图片路径 newsModel.digest = modelt.zhaiyao; //图文消息的描述 newsModel.show_cover_pic = "1"; //是否显示封面,1为显示,0为不显示 ls.Add(newsModel); //添加实体到泛型 } //开始群发消息 bool result = wxComm.SendGroupMessageByGroupId(ls, out errmsg); if (!result) { JscriptMsg("错误:" + errmsg, string.Empty); return; } JscriptMsg("微信消息推送成功!", Utils.CombUrlTxt("article_list.aspx", "channel_id={0}&category_id={1}&keywords={2}&property={3}&page={4}", this.channel_id.ToString(), this.category_id.ToString(), this.keywords, this.property, this.page.ToString())); }