public void SendNews(string device_id, string openId, string type, string content, string content2) { //string openId = QrChildManager.GetOpenId(device_id); if (openId == "" || openId == null) { HttpContext.Current.Response.Write("设备未被绑定!"); //return "设备未被绑定!"; } string data = ""; switch (type) { case "text": data = "{\"touser\":\"" + openId + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + content + "\"}}"; break; case "image": data = "{\"touser\":\"" + openId + "\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"" + content + "\"}}"; break; case "voice": data = "{\"touser\":\"" + openId + "\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"" + content + "\"}}"; break; case "video": data = "{\"touser\":\"" + openId + "\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"" + content + "\", \"thumb_media_id\":\"" + content2 + "\"}}"; break; default: break; } du.SendNews(data); HttpContext.Current.Response.Write("消息发送成功!"); //return "消息发送成功!"; }
public void DelUsers(string openId) { if (Context.Session["OpenId"] != null) { string OpenId = Context.Session["OpenId"].ToString(); string device = QrChildManager.GetChildDeviceId(OpenId); DataTable dt = QrChildManager.GetOpenId(device); if (OpenId == dt.Rows[0]["OpenId"].ToString()) { Device_user du = new Device_user(); List <string> list = new List <string>(); foreach (DataRow row in dt.Rows) { list.Add(row["OpenId"].ToString()); } Dictionary <string, List <Dictionary <string, string> > > dic2 = new Dictionary <string, List <Dictionary <string, string> > >(); List <Dictionary <string, string> > list2 = new List <Dictionary <string, string> >(); foreach (var item in list) { Dictionary <string, string> dic3 = new Dictionary <string, string>(); dic3.Add("openid", item); dic3.Add("lang", "zh_CN"); list2.Add(dic3); } dic2.Add("user_list", list2); string data2 = du.GetUserInformation(JsonConvert.SerializeObject(dic2)); Dictionary <string, List <Dictionary <string, object> > > list3 = JsonConvert.DeserializeObject <Dictionary <string, List <Dictionary <string, object> > > >(data2); string admin = ""; string user = ""; foreach (var item in list3["user_info_list"]) { if (item["openid"].ToString() == OpenId) { admin = item["nickname"].ToString(); } if (item["openid"].ToString() == openId) { user = item["nickname"].ToString(); } } foreach (var item in list3["user_info_list"]) { if (user == admin) { return; } else { string content = string.Format("成员{0}已被管理员{1}删除绑定!", user, admin); if (item["openid"].ToString() == openId) { content = string.Format("你已被管理员{0}删除绑定!", admin); } string data = "{\"touser\":\"" + item["openid"] + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + content + "\"}}"; du.SendNews(data); } } string xingeToken = QrChildManager.GetXingeToken(openId); QrChildManager.DeleteOpenId(openId, device); string js = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + openId + "\",\"Content\":\"\"}"; Message ms = new Message("e家亲幼儿伴侣", js); XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms)); Write("true"); } else { Write("你不是管理员,没有权限删除成员!"); } } }