//重置密码 private void ResetPassWord(RequestXML requestXML) { if (requestXML == null) { return; } string EventKey = requestXML.EventKey; if (string.IsNullOrEmpty(EventKey)) { return; } EventKey = EventKey.Replace("qrscene_", ""); Dictionary <string, string> dic = RedisUtil.Get <Dictionary <string, string> >("resetpassword:"******"OpenId"]; if (openId != requestXML.FromUserName) { return; } RedisUtil.Set <object>("resetpassword:" + EventKey, new { OpenId = requestXML.FromUserName, IsScan = 1 }, TimeSpan.FromHours(3)); }
private void SendEventMsg(RequestXML requestXML) //发送事件消息 { String keyStr = requestXML.EventKey.ToString(); string responseContent = String.Empty; string text = String.Empty; //string textLend=SendLendMsg(); //借阅资料 //string textOrder=SendOrderMsg(); //预约资料 string username = HttpContext.Current.Session["UserName"].ToString(); string userid = HttpContext.Current.Session["UserNumber"].ToString(); if (keyStr == "lendsearch") { text = username; } else if (keyStr == "ordersearch") { text = userid; } else { text = "Emmmmm...出现了一些些问题,抱歉..."; } responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, text); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); }
public void ReturnMessage(string postStr) //返回消息 { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(postStr); XmlElement rootElement = xmldoc.DocumentElement;//获取文档根 XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); RequestXML requestXML = new RequestXML(); //声明实例,获取各个属性并赋值 requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText; //公众号 requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText; //用户 requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText; //创建时间 requestXML.MsgType = MsgType.InnerText.Trim().ToString(); //消息类型 if (MsgType.InnerText.Trim().ToLower() == "event") { requestXML.EventName = rootElement.SelectSingleNode("Event").InnerText; requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText; } else if (MsgType.InnerText.Trim().ToLower() == "text") { requestXML.Content = rootElement.SelectSingleNode("Content").InnerText; } ResponseMsg(requestXML); }
private void ResponseMsg(RequestXML requestXML) //回应消息 { string MsgType = requestXML.MsgType; try { //根据消息类型判断发送何种类型消息 switch (MsgType) { case "text": SendTextCase(requestXML); //发送文本消息 break; case "event": //发送事件消息 if (!string.IsNullOrWhiteSpace(requestXML.EventName) && requestXML.EventName.ToString().Trim().Equals("subscribe")) { SendWelComeMsg(requestXML); //关注时返回的消息 } else if (!string.IsNullOrWhiteSpace(requestXML.EventName) && requestXML.EventName.ToString().Trim().Equals("CLICK")) { SendEventMsg(requestXML); //发送菜单点击事件消息 } break; default: break; } } catch (Exception ex) { HttpContext.Current.Response.Write(ex.ToString()); } }
/// <summary> /// 取消关注 /// </summary> /// <param name="xml"></param> private void CancleSubscribe(RequestXML xml) { if (!string.IsNullOrEmpty(xml.FromUserName)) { new wxuserinfoBLL().Delete(string.Format("serverid='{0}' and openid='{1}'", xml.ToUserName, xml.FromUserName)); } }
/// <summary> /// 回复消息(微信信息返回) /// </summary> /// <param name="weixinXML"></param> private void ResponseMsg(RequestXML requestXML, HttpContext context) { ResponseMsgService responseMsg = new ResponseMsgService(); try { string resxml = ""; if (requestXML.MsgType.Equals("text")) { resxml = responseMsg.resText(requestXML); } if (requestXML.MsgType.Equals("event")) { resxml = responseMsg.resEvent(requestXML); } else if (requestXML.MsgType.Equals("location")) { resxml = responseMsg.resLocation(requestXML); } else if (requestXML.MsgType == "image") { responseMsg.resImage(requestXML); } else if (requestXML.MsgType == "voice") { responseMsg.resVoice(requestXML); } context.Response.Write(resxml); } catch (Exception ex) { Util.WriteTxt("异常:" + ex.Message + "Struck:" + ex.StackTrace.ToString()); } }
//绑定微信 private void BindWeiXin(RequestXML xml) { try { if (xml == null) { return; } if (string.IsNullOrEmpty(xml.FromUserName)) { return; } if (string.IsNullOrEmpty(xml.EventKey)) { return; } string key = xml.EventKey.Replace("qrscene_", ""); Entity.MiniApp.LoginQrCode lcode = RedisUtil.Get <Entity.MiniApp.LoginQrCode>("bindwxid:" + key); if (lcode == null) { return; } lcode.OpenId = xml.FromUserName; RedisUtil.Set <Entity.MiniApp.LoginQrCode>("bindwxid:" + key, lcode, TimeSpan.FromMinutes(3)); } catch (Exception ex) { log4net.LogHelper.WriteError(this.GetType(), ex); } }
public string MyMemberQuickCard(RequestXML MsgXml) { StringBuilder w = new StringBuilder(); StringBuilder s = new StringBuilder(); s.Append(" select MemberCode,MemberName from CORE.dbo.MemberView where YuanShiId='" + MsgXml.ToUserName + "' and WxOpenId='" + MsgXml.FromUserName + "' "); DataSet ds = DAL.DalComm.BackData(s.ToString()); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { w.Append("您的会员编号是:" + dr["MemberCode"] + " \n "); w.Append("您的会员名是:" + dr["MemberName"] + ""); } } else { w.Append("您还没有开通会员卡! 请点击微会员--我的会员卡进行开通!"); } return(QueakSend(MsgXml, w.ToString())); }
/// <summary> /// 发送响应语音识别结果 /// </summary> /// <param name="requestXML"></param> private void SendVoiceMsg(RequestXML requestXML) { string responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, "您刚才说的语音消息识别结果为:" + requestXML.Recognition.ToString()); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); }
/// <summary> /// 发送文本 /// </summary> /// <param name="requestXML"></param> private void SendTextCase(RequestXML requestXML) { string responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, requestXML.Content); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); }
internal List <RequestXML> GetWxrequestxmlByopenid(int pageindex, int pagesize, out int totalcount, string openid, string sysweixin) { var Table = "WxRequestXml"; var Column = "*"; var OrderColumn = "id desc"; var GroupColumn = ""; var PageSize = pagesize; var CurrentPage = pageindex; var Group = ""; var Condition = " (fromusername='******' or tousername='******') and msgtype in ('voice','text') and fromusername not like 'gh_%' and tousername not like 'gh_%' and createtimeformat between CONCAT(Convert(varchar(10), dateadd(dd,-4,getdate()),121),' 00:00:00') and CONCAT(Convert(varchar(10),getdate(),121),' 23:59:59') "; var cmd = this.sqlHelper.PrepareStoredSqlCommand("proc_ListPage"); cmd.PagingCommand1(Table, Column, OrderColumn, GroupColumn, PageSize, CurrentPage, Group, Condition); List <RequestXML> list = new List <RequestXML>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { RequestXML model = new RequestXML(); model.Id = reader.GetValue <int>("Id"); model.ToUserName = reader.GetValue <string>("ToUserName"); model.FromUserName = reader.GetValue <string>("FromUserName"); model.CreateTime = reader.GetValue <string>("CreateTime"); model.MsgType = reader.GetValue <string>("MsgType"); model.Content = reader.GetValue <string>("Content"); model.Location_X = reader.GetValue <string>("Location_X"); model.Location_Y = reader.GetValue <string>("Location_Y"); model.Scale = reader.GetValue <string>("Scale"); model.Label = reader.GetValue <string>("Label"); model.PicUrl = reader.GetValue <string>("PicUrl"); model.PostStr = reader.GetValue <string>("PostStr"); model.CreateTimeFormat = reader.GetValue <DateTime>("CreateTimeFormat").ToString().ConvertTo <DateTime>(DateTime.Now); model.MediaId = reader.GetValue <string>("MediaId"); model.Format = reader.GetValue <string>("Format"); model.Recognition = reader.GetValue <string>("Recognition"); model.ThumbMediaId = reader.GetValue <string>("ThumbMediaId"); model.Title = reader.GetValue <string>("Title"); model.Description = reader.GetValue <string>("Description"); model.Url = reader.GetValue <string>("Url"); model.MsgId = reader.GetValue <string>("MsgId"); model.ContentType = reader.GetValue <bool>("ContentType"); model.Comid = reader.GetValue <int>("Comid"); list.Add(model); } } totalcount = int.Parse(cmd.Parameters[0].Value.ToString()); return(list); }
public void Handle(string postStr) { //封装请求类 XmlDocument doc = new XmlDocument(); doc.LoadXml(postStr); XmlElement rootElement = doc.DocumentElement; //MsgType XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); //接收的值--->接收消息类(也称为消息推送) RequestXML requestXML = new RequestXML(); requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText; requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText; requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText; requestXML.MsgType = MsgType.InnerText; //根据不同的类型进行不同的处理 switch (requestXML.MsgType) { case "text": //文本消息 requestXML.Content = rootElement.SelectSingleNode("Content").InnerText; break; case "image": //图片 requestXML.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText; break; case "location": //位置 requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText; requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText; requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText; requestXML.Label = rootElement.SelectSingleNode("Label").InnerText; break; case "link": //链接 break; case "event": //事件推送 支持V4.5+ requestXML.Event = rootElement.SelectSingleNode("Event").InnerText; requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText; break; case "voice": //语音识别 requestXML.Recognition = rootElement.SelectSingleNode("Recognition").InnerText; break; case "click": //点击事件 requestXML.click = rootElement.SelectSingleNode("Click").InnerText; break; } //消息回复 ResponseMsg(requestXML); }
public string resEvent(RequestXML requestXML) { string resxml = ""; //关注 if (requestXML.Event.Equals("subscribe")) { new SubscribeService().subscribe(requestXML.FromUserName); resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + Util.ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[欢迎加入蓝谷养老]]></Content><FuncFlag>0</FuncFlag></xml>"; } //取消关注 if (requestXML.Event.Equals("unsubscribe")) { new SubscribeService().unsubscribe(requestXML.FromUserName); } //服务项目查询 if (requestXML.EventKey.Equals("WX101")) { //resxml = new GovernmentService().GovernmentItem(requestXML); } if (requestXML.EventKey.Equals("WX201")) { //resxml = new GovernmentService().OldManItem(requestXML); } //政府 服务记录查询 if (requestXML.EventKey.Equals("WX102")) { resxml = new GovernmentService().isAuthOrBound(requestXML); } //政府 服务记录查询 if (requestXML.EventKey.Equals("WX202")) { resxml = new OldManService().isAuthOrBound(requestXML); } //自定义菜单 click事件 if (requestXML.EventKey.Equals("V1001_HELLO_WORLD")) { resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + Util.ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[news]]></MsgType><Content><![CDATA[]]></Content><ArticleCount>" + 10 + "</ArticleCount><Articles>"; List <string> list = new List <string>(); //图文消息 最多返回10条数据 for (int i = 0; i < 10; i++) { list.Add("1"); } for (int i = 0; i < list.Count; i++) { resxml += "<item><Title><![CDATA[浙江-杭州]]></Title><Description><![CDATA[元旦特价:¥300 市场价:¥400]]></Description><Url><![CDATA[http://www.hougelou.com]]></Url></item>"; } resxml += "</Articles><FuncFlag>1</FuncFlag></xml>"; } return(resxml); }
private void SendTextCase(RequestXML requestXML) //发送文本消息 { string text = "欢迎使用本系统,本系统由shihang完成,仅供学习与交流。建议在登录后使用相关功能。有问题与想法欢迎交流!"; string responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, text); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); }
private void SendWelComeMsg(RequestXML requestXML) //关注发送消息 { string welstr = "欢迎使用LibraryDemo!该模型仅供学习交流。"; string responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, welstr); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); }
/// <summary> /// 封装请求类 /// </summary> /// <param name="postStr"></param> /// <returns></returns> public static RequestXML BackRequestXML(string postStr) { XmlDocument doc = new XmlDocument(); doc.LoadXml(postStr); XmlElement rootElement = doc.DocumentElement; XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); RequestXML requestXML = new RequestXML(); requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText; requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText; requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText; requestXML.MsgType = MsgType.InnerText; if (requestXML.MsgType == "text") { requestXML.Content = rootElement.SelectSingleNode("Content").InnerText; } else if (requestXML.MsgType == "voice") { requestXML.Content = rootElement.SelectSingleNode("Recognition").InnerText; } else if (requestXML.MsgType == "location") { requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText; requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText; requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText; requestXML.Label = rootElement.SelectSingleNode("Label").InnerText; } else if (requestXML.MsgType == "image") { requestXML.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText; } else if (requestXML.MsgType == "event") { requestXML.Event = rootElement.SelectSingleNode("Event").InnerText; if (requestXML.Event == "scancode_waitmsg") { requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText; requestXML.ScanResult = rootElement.SelectSingleNode("ScanCodeInfo").SelectSingleNode("ScanResult").InnerText; } //if (requestXML.Event != "subscribe") //{ // requestXML.ScanResult = rootElement.SelectSingleNode("ScanCodeInfo").SelectSingleNode("ScanResult").InnerText; // requestXML.ScanType = rootElement.SelectSingleNode("ScanCodeInfo").SelectSingleNode("ScanType").InnerText; //} } return(requestXML); }
public HttpResponseMessage msg([FromBody] RequestXML msg) { //string ToUserName, string FromUserName, string CreateTime, string MsgType,string Content, string MsgId //string xmlstr = FormatTextXML(msg.FromUserName,msg.ToUserName, msg.Content); string xmlstr = "haha!"; var result = new StringContent(xmlstr, UTF8Encoding.UTF8, "application/xml charset=\"utf-8\""); var response = new HttpResponseMessage { Content = result }; return(response); }
/// <summary> /// 将本次交互信息保存至数据库中 /// </summary> /// <param name="requestXML"></param> /// <param name="_xml"></param> /// <param name="_pid"></param> private void WriteToDB(RequestXML requestXML) { try { if (requestXML.MsgType == "voice") { requestXML.Content = requestXML.Recognition; } string sqlstr = "insert into tb_U_weixin (FormUserName,ToUserName,MsgType,Msg,Location_X,Location_Y)values('" + requestXML.FromUserName + "','" + requestXML.ToUserName + "','" + requestXML.MsgType + "','" + requestXML.Content + "','" + requestXML.Location_X + "','" + requestXML.Location_Y + "')"; HXD.DBUtility.SQLHelper.ExecuteNonQuery(sqlstr); } catch { } }
public string QueakSend(RequestXML MsgXml, string SendStr) { StringBuilder w = new StringBuilder(); w.Append("<xml>"); w.Append("<ToUserName><![CDATA[" + MsgXml.FromUserName + "]]></ToUserName>"); w.Append("<FromUserName><![CDATA[" + MsgXml.ToUserName + "]]></FromUserName>"); w.Append("<CreateTime>" + MsgXml.CreateTime + "</CreateTime>"); w.Append("<MsgType><![CDATA[text]]></MsgType>"); w.Append("<Content><![CDATA[" + SendStr + "]]></Content>"); w.Append("</xml>"); return(w.ToString()); }
public void processRequest(string postStr, int id, string types = "") { try { Hashtable requestHT = ParseXml(postStr); RequestXML requestXML = new RequestXML(); requestXML.ToUserName = (string)requestHT["ToUserName"]; //开发者微信号 requestXML.FromUserName = (string)requestHT["FromUserName"]; //发送方帐号(一个OpenID) requestXML.CreateTime = (string)requestHT["CreateTime"]; requestXML.MsgType = (string)requestHT["MsgType"]; requestXML.EventKey = (string)requestHT["EventKey"]; requestXML.Content = (string)requestHT["Content"]; HttpContext.Current.Response.Output.Write(""); if (string.IsNullOrEmpty(requestXML.ToUserName)) { return; } switch (requestXML.MsgType.ToLower()) { case "text": this.GetWXContent(requestXML, id); break; case "image": break; case "link": break; case "event": string eventType = (string)requestHT["Event"]; if (!string.IsNullOrEmpty(eventType)) { this.ResponseMsg(requestHT, eventType, requestXML); } break; case "voice": break; } } catch (Exception ex) { log4net.LogHelper.WriteError(this.GetType(), ex); } }
public void Handle(string postStr, WeiXinBasic basic) { try { //封装请求类 XmlDocument doc = new XmlDocument(); doc.LoadXml(postStr); XmlElement rootElement = doc.DocumentElement; XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); RequestXML requestXML = new RequestXML(); requestXML.PostStr = postStr; requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText; requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText; requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText; requestXML.MsgType = MsgType.InnerText; if (requestXML.MsgType == "event" || requestXML.MsgType == "text") { if (requestXML.MsgType == "event") { requestXML.Eevent = rootElement.SelectSingleNode("Event").InnerText; requestXML.EventKey = rootElement.SelectSingleNode("EventKey") == null ? "" : rootElement.SelectSingleNode("EventKey").InnerText; } ResponseMsg(requestXML, basic); } } catch (Exception ex) { string emptystr = ""; System.Web.HttpContext.Current.Response.Write(emptystr); //加txt文档记录 TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\weixinerrLog.txt", ex.Message); } }
/// <summary> /// 添加新用户到基础表 /// </summary> /// <param name="xml"></param> public void RegisterOAuthUser(RequestXML xml) { try { if (xml == null) { return; } if (string.IsNullOrEmpty(xml.FromUserName)) { return; } //log4net.LogHelper.WriteInfo(this.GetType(), $"扫码事件推送:{JsonConvert.SerializeObject(xml)}"); UserBaseInfo umodel = UserBaseInfoBLL.SingleModel.GetModelByOpenId(xml.FromUserName, xml.ToUserName); if (umodel == null) { WeiXinUser wx = WxHelper.GetWxUserInfo(WxHelper.GetToken(), xml.FromUserName); if (wx != null && !string.IsNullOrEmpty(wx.openid)) { umodel = new UserBaseInfo(); umodel.headimgurl = wx.headimgurl; umodel.nickname = wx.nickname; umodel.openid = wx.openid; umodel.unionid = wx.unionid; umodel.country = wx.country; umodel.sex = wx.sex; umodel.city = wx.city; umodel.province = wx.province; umodel.serverid = xml.ToUserName; UserBaseInfoBLL.SingleModel.Add(umodel); } } else { WeiXinUser wx = WxHelper.GetWxUserInfo(WxHelper.GetToken(), xml.FromUserName); if (wx != null && !string.IsNullOrEmpty(wx.openid) && umodel.headimgurl != wx.headimgurl) { umodel.headimgurl = wx.headimgurl; UserBaseInfoBLL.SingleModel.Update(umodel, "headimgurl"); } } } catch (Exception ex) { log4net.LogHelper.WriteInfo(this.GetType(), $"报错扫码事件推送:{JsonConvert.SerializeObject(ex)}"); log4net.LogHelper.WriteError(this.GetType(), ex); } }
internal int InsertOrUpdate(RequestXML model) { var cmd = sqlHelper.PrepareStoredSqlCommand(SQLInsertOrUpdate); cmd.AddParam("@id", model.Id); cmd.AddParam("@ToUserName", model.ToUserName); cmd.AddParam("@FromUserName", model.FromUserName); cmd.AddParam("@CreateTime", model.CreateTime); cmd.AddParam("@MsgType", model.MsgType); cmd.AddParam("@Content", model.Content); cmd.AddParam("@Location_X", model.Location_X); cmd.AddParam("@Location_Y", model.Location_Y); cmd.AddParam("@Scale", model.Scale); cmd.AddParam("@Label", model.Label); cmd.AddParam("@PicUrl", model.PicUrl); cmd.AddParam("@PostStr", model.PostStr); cmd.AddParam("@CreateTimeFormat", model.CreateTimeFormat); cmd.AddParam("@Sendstate", model.Sendstate); //新增加的参数 cmd.AddParam("@MediaId", model.MediaId); cmd.AddParam("@Format", model.Format); cmd.AddParam("@Recognition", model.Recognition); cmd.AddParam("@ThumbMediaId", model.ThumbMediaId); cmd.AddParam("@Title", model.Title); cmd.AddParam("@Description", model.Description); cmd.AddParam("@Url", model.Url); cmd.AddParam("@MsgId", model.MsgId); cmd.AddParam("@ContentType", model.ContentType); cmd.AddParam("@Comid", model.Comid); if (model.Manageuserid == null) { model.Manageuserid = 0; } if (model.Manageusername == null) { model.Manageusername = ""; } cmd.AddParam("@ManageUserId", model.Manageuserid); cmd.AddParam("@ManageUserName", model.Manageusername); var parm = cmd.AddReturnValueParameter("ReturnValue"); cmd.ExecuteNonQuery(); return((int)parm.Value); }
/// <summary> /// 编辑微信访问记录日志 /// </summary> /// <param name="requestXML"></param> /// <returns></returns> public int EditWxRequestXmlLog(RequestXML requestXML) { using (var sql = new SqlHelper()) { try { var internalData = new InternalWxRequestXml(sql); int result = internalData.InsertOrUpdate(requestXML); return(result); } catch { throw; } } }
public string PutXML1(string postString) { //使用XMLDocument加载信息结构 XmlDocument xmlDoc1 = new XmlDocument(); xmlDoc1.LoadXml(postString); XmlElement rootElement1 = xmlDoc1.DocumentElement; //获取文档的根 RequestXML requestXML1 = new RequestXML(); //声明实例,获取各个属性并赋值 requestXML1.EventKey = rootElement1.SelectSingleNode("Ticket").InnerText; //scene_id string s1 = requestXML1.EventKey; return(s1); }
public string resLocation(RequestXML requestXML) { //string city = GetMapInfo(requestXML.Location_X, requestXML.Location_Y); string resxml = ""; string city = ""; if (city == "0") { resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + Util.ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[Sorry,没有找到" + city + " 的相关产品信息]]></Content><FuncFlag>0</FuncFlag></xml>"; } else { resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + Util.ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[Sorry,这是 " + city + " 的产品信息]]></Content><FuncFlag>0</FuncFlag></xml>"; } return(resxml); }
private void ResponseXML(string postString) { //使用XMLDocument加载信息结构 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(postString); XmlElement rootElement = xmlDoc.DocumentElement; //获取文档的根 XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); //获取消息的文本类型 RequestXML requestXML = new RequestXML(); //声明实例,获取各个属性并赋值 requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText; //公众号 requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText; //用户 requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText; //创建时间 requestXML.MsgType = MsgType.InnerText; //消息类型 ///对消息的不同类型进行赋值 if (requestXML.MsgType == "text") { //赋值文本信息内容 requestXML.Content = rootElement.SelectSingleNode("Content").InnerText; } if (requestXML.MsgType.Trim() == "location") { ///赋值地理位置纬度,经度,地图缩放比例,地理位置说明 requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText; requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText; requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText; requestXML.Label = rootElement.SelectSingleNode("Label").InnerText; } if (requestXML.MsgType.Trim().ToLower() == "event") { ///赋值事件名称和事件key值 requestXML.EventName = rootElement.SelectSingleNode("Event").InnerText; requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText; } if (requestXML.MsgType.Trim().ToLower() == "voice") { ///赋值语音识别结果,赋值之前一定要记得在开发者模式下,把语音识别功能开启,否则获取不到 requestXML.Recognition = rootElement.SelectSingleNode("Recognition").InnerText; } ResponseMsg(requestXML); }
/// <summary> /// 发送关注时的图文消息 /// </summary> /// <param name="requestXML"></param> private void SendWelComeMsg(RequestXML requestXML) { String responseContent = String.Empty; string newdate = DateTime.Now.Subtract(new DateTime(1970, 1, 1, 8, 0, 0)).TotalSeconds.ToString(); string PUrlfileName = ""; //"http://www.deqiaohr.com.cn/weixin/welcome.jpg"; responseContent = string.Format(Message_News_Main, requestXML.FromUserName, requestXML.ToUserName, newdate, "1", string.Format(Message_News_Item, "欢迎关注", "犇这来", PUrlfileName, ""));//"http://www.deqiaohr.com.cn/weixin/WxGsjianjie.aspx")); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); }
/// <summary> /// 发送响应事件消息 /// </summary> /// <param name="requestXML"></param> private void SendEventMsg(RequestXML requestXML) { string keyStr = requestXML.EventKey.ToString(); switch (keyStr) { //case "mypay": // SendPayDetails(requestXML);//发送薪资账单 // break; //case "tianqiyubao": // SendWeaterMessage(requestXML);//发送天气预报 // break; //case "kaixinyixiao": // SendKaiXinMessage(requestXML);//发送开心一笑结果集 // break; //case "updateMessage": // SendUpdateMessage(requestXML);//发送修改信息链接 // break; //case "yuangonghuodong": // SendYuanGongHuoDong(requestXML);//发送学生活动 // break; //case "yuangongtongzhi": // SendYuanGongTongZhi(requestXML);//发送员工通知 // break; //case "youwenbida": // SendWenti(requestXML);//发送员工提交问题链接 // break; //case "mywen": // SendWentiList(requestXML);//发送问题列表链接 // break; //case "PhoneSerices": // SendKeFuMessage(requestXML);//接入客服 // break; default: String responseContent = String.Empty; responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, "此功能暂未开放!敬请期待!"); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); HttpContext.Current.Response.End(); break; } }
internal List <RequestXML> GetWxErrSendMsgList(int comid, string FromUserName, out int totalcount) { int count = 0; DateTime CreateTimeFormat = DateTime.Now.AddDays(-7);//一周以内的 条数 //最多20条 string sql = @"select top 20 * from WxRequestXml where sendstate=0 and createtimeformat >@CreateTimeFormat and comid=@comid and tousername=@fromusername order by id desc"; var cmd = sqlHelper.PrepareTextSqlCommand(sql); cmd.AddParam("@CreateTimeFormat", CreateTimeFormat); cmd.AddParam("@comid", comid); cmd.AddParam("@fromusername", FromUserName); List <RequestXML> list = new List <RequestXML>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { RequestXML model = new RequestXML(); model.Id = reader.GetValue <int>("Id"); model.ToUserName = reader.GetValue <string>("ToUserName"); model.FromUserName = reader.GetValue <string>("FromUserName"); model.CreateTime = reader.GetValue <string>("CreateTime"); model.MsgType = reader.GetValue <string>("MsgType"); model.Content = reader.GetValue <string>("Content"); model.Location_X = reader.GetValue <string>("Location_X"); model.Location_Y = reader.GetValue <string>("Location_Y"); model.Scale = reader.GetValue <string>("Scale"); model.Label = reader.GetValue <string>("Label"); model.PicUrl = reader.GetValue <string>("PicUrl"); model.PostStr = reader.GetValue <string>("PostStr"); model.CreateTimeFormat = reader.GetValue <DateTime>("CreateTimeFormat").ToString().ConvertTo <DateTime>(DateTime.Parse("1900-01-01 00:00:00")); list.Add(model); count++; } } totalcount = count; return(list); }