/// <summary> /// 判断用户是否已经绑定微信 /// </summary> public static Boolean SureUserWinxin(string as_UserWeixinID) { GyShop_Page.SetSession(); String ls_Sql = "SELECT cus_code,cus_name,WeixinID FROM customer where WeixinID=@WeixinID"; GysoftParameter[] Pa = { new GysoftParameter("@WeixinID", as_UserWeixinID) }; DataTable ldt = SqlHelper.ExecuteDataTable(ls_Sql, Pa); if (String.IsNullOrEmpty(SqlHelper.ErrStr) && ldt.Rows.Count > 0) { SysVisitor.Current.UserCode = ldt.Rows[0]["cus_code"].ToString().Trim(); SysVisitor.Current.UserName = ldt.Rows[0]["cus_name"].ToString().Trim(); SysVisitor.Current.UserWeixinID = ldt.Rows[0]["WeixinID"].ToString().Trim(); return(true); } return(false); }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="as_Cus_code">用户编号</param> /// <param name="as_Cus_Name">用户名</param> public static void GetUserInfo(out string as_Cus_code, out string as_Cus_Name) { as_Cus_code = as_Cus_Name = ""; //if (String.IsNullOrEmpty(SysVisitor.Current.UserName) || String.IsNullOrEmpty(SysVisitor.Current.UserCode)) //{ // HttpContext.Current.Response.Redirect("Error.aspx?获取用户名称或用户编号为空"); // return; //} //string strSql = "select top 1 Cus_code,cus_name from Customer where cus_code=@cus_code and Iscustomer='Y'"; //GysoftParameter[] Pa = { new GysoftParameter("@cus_code", SysVisitor.Current.UserCode) }; //DataTable ldt_UserInfo = SqlHelper.ExecuteDataTable(strSql, Pa); //if (ldt_UserInfo.Rows.Count != 1) //{ // HttpContext.Current.Response.Redirect("Error.aspx?用户名称获取失败"); // return; //} //as_Cus_code = SysVisitor.Current.UserCode = ldt_UserInfo.Rows[0]["cus_code"].ToString().Trim();//cus_code,cus_name字段为char类型 //as_Cus_Name = SysVisitor.Current.UserName = ldt_UserInfo.Rows[0]["cus_name"].ToString().Trim(); //return; try { if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["userweixinid"])) { string ls_userweixinid = Core.SysVisitor.Current.UserWeixinID; string ls_sql = "SELECT cus_code,cus_name,WeixinID FROM customer where WeixinID=@WeixinID"; GysoftParameter[] Pa = { new GysoftParameter("@WeixinID", ls_userweixinid) }; DataTable ldt_UserInfo = SqlHelper.ExecuteDataTable(ls_sql, Pa); if (ldt_UserInfo.Rows.Count != 1) { HttpContext.Current.Response.Redirect("Error.aspx?用户名称获取失败"); return; } as_Cus_code = SysVisitor.Current.UserCode = ldt_UserInfo.Rows[0]["cus_code"].ToString().Trim();; as_Cus_Name = SysVisitor.Current.UserName = ldt_UserInfo.Rows[0]["cus_name"].ToString().Trim(); return; } else { GyShop_Page.SetSession(); string ls_userweixinid = HttpContext.Current.Request.QueryString["userweixinid"]; string strSql = "select top 1 Cus_code,cus_name from Customer where WeixinID=@WeixinID and Iscustomer='Y'"; GysoftParameter[] Pa = { new GysoftParameter("@WeixinID", ls_userweixinid) }; DataTable ldt_UserInfo = SqlHelper.ExecuteDataTable(strSql, Pa); if (ldt_UserInfo.Rows.Count != 1) { HttpContext.Current.Response.Redirect("Error.aspx?用户名称获取失败"); return; } as_Cus_code = SysVisitor.Current.UserCode = ldt_UserInfo.Rows[0]["cus_code"].ToString().Trim();//cus_code,cus_name字段为char类型 as_Cus_Name = SysVisitor.Current.UserName = ldt_UserInfo.Rows[0]["cus_name"].ToString().Trim(); return; } } catch { HttpContext.Current.Response.Redirect("Error.aspx?url上的参数不包含userweixinid"); return; } }
public static String MainReply(String as_RequestXML) { try { GyShop_Page.SetSession(); XmlDocument doc = new XmlDocument(); doc.LoadXml(as_RequestXML); XmlNodeList list = doc.GetElementsByTagName("xml"); XmlNode xn = list[0]; Core.SysVisitor.Current.WeixinID = xn.SelectSingleNode("//ToUserName").InnerText.Trim(); Core.SysVisitor.Current.UserWeixinID = xn.SelectSingleNode("//FromUserName").InnerText.Trim(); string ls_MsgType = xn.SelectSingleNode("//MsgType").InnerText; //接到信息类型 switch (ls_MsgType.ToLower()) { case "event": //点击 #region event事件 String ls_Event = xn.SelectSingleNode("//Event").InnerText; #region 关注与取消关注 if (ls_Event.ToLower() == "subscribe") //订阅 { try { string ls_name = SysVisitor.Current.Get_User(Core.SysVisitor.Current.UserWeixinID); if (!string.IsNullOrEmpty(ls_name)) { string ls_wingroup_wx = "", ls_customer = ""; ls_wingroup_wx = SqlHelper.ExecuteScalar("select isnull(openid,'') from wingroup_wx where openid=@openid", "@openid=" + Core.SysVisitor.Current.UserWeixinID); ls_customer = SqlHelper.ExecuteScalar("select isnull(weixinid,'') from customer where weixinid=@openid", "@openid=" + Core.SysVisitor.Current.UserWeixinID); string ls_haveerp = "Y"; if (ls_customer == "") { ls_haveerp = "N"; } if (ls_name.Length > 30) { ls_name = ls_name.Substring(0, 30); } n_create_sql lnv_sql = new n_create_sql(); lnv_sql.of_SetTable("wingroup_wx"); lnv_sql.of_AddCol("wxname", ls_name); lnv_sql.of_AddCol("haveok", "Y"); lnv_sql.of_AddCol("insdate", DateTime.Now.ToString()); lnv_sql.of_AddCol("haveerp", ls_haveerp); if (ls_wingroup_wx == "") { lnv_sql.of_AddCol("openid", Core.SysVisitor.Current.UserWeixinID); lnv_sql.of_execute(); } else { lnv_sql.of_execute("openid=@openid", "@openid=" + Core.SysVisitor.Current.UserWeixinID); } } } catch { } return(SubscribeReply()); } if (ls_Event.ToLower() == "unsubscribe") //取消订阅 { string ls_wingroup_wx = "", ls_customer = "";; ls_wingroup_wx = SqlHelper.ExecuteScalar("select isnull(openid,'') from wingroup_wx where openid=@openid", "@openid=" + Core.SysVisitor.Current.UserWeixinID); ls_customer = SqlHelper.ExecuteScalar("select isnull(weixinid,'') from customer where weixinid=@openid", "@openid=" + Core.SysVisitor.Current.UserWeixinID); string ls_haveerp = "Y"; if (ls_customer == "") { ls_haveerp = "N"; } n_create_sql lnv_sql = new n_create_sql(); lnv_sql.of_SetTable("wingroup_wx"); lnv_sql.of_AddCol("haveok", "N"); lnv_sql.of_AddCol("deldate", DateTime.Now.ToString()); lnv_sql.of_AddCol("haveerp", ls_haveerp); if (ls_wingroup_wx == "") { lnv_sql.of_AddCol("openid", Core.SysVisitor.Current.UserWeixinID); lnv_sql.of_execute(); } else { lnv_sql.of_execute("openid=@openid", "@openid=" + Core.SysVisitor.Current.UserWeixinID); } return(""); } #endregion else if (ls_Event.ToLower() == "click") //菜单点击 { string ls_EventKey = xn.SelectSingleNode("//EventKey").InnerText; switch (ls_EventKey.ToLower()) { case "subcom": return(SubcomReply()); //命令列表 case "ordercar": return(OrderCarReply()); //在线订货 case "getmain": return(GetMainReply()); //订单查看 case "outone": return(OutOneReply()); //发货单查看 case "backmoney": return(BackMoneyReply()); //汇款单查看 case "accbook": return(AccBookReply()); //对账单查看 case "default": return(ShowDefault()); //显示首页 } } else if (ls_Event.ToLower() == "view") //菜单点击(url类型) { if (!UserInfo.SureUserWinxin(SysVisitor.Current.UserWeixinID)) { return(NeedBindWeixin()); } string ls_EventKey = xn.SelectSingleNode("//EventKey").InnerText; switch (ls_EventKey.ToLower()) { case "": return(""); } } else if (ls_Event.ToUpper() == "TEMPLATESENDJOBFINISH") //模板消息发送 { string ls_EventKey = xn.SelectSingleNode("//Status").InnerText; string ls_openID = xn.SelectSingleNode("//FromUserName").InnerText; switch (ls_EventKey.ToLower()) { case "success": Tools.WriteLog("Log", "模板消息推送", "成功!" + ls_openID); break; //成功送达 case "failed:user block": Tools.WriteLog("Log", "模板消息推送", "用户拒收!" + ls_openID); break; //用户设置了拒收 case "failed: system failed": Tools.WriteLog("Log", "模板消息推送", "用户拒收!" + ls_openID); break; //其他原因失败 } } return(ErrXML()); #endregion case "text": //文字 return(TextReply(xn.SelectSingleNode("//Content").InnerText)); case "image": //图片 return(ErrXML()); case "voice": //语音 return(ErrXML()); case "video": //视频 return(ErrXML()); case "location": //地理位置 return(ErrXML()); case "link": //链接 return(ErrXML()); default: return(ErrXML()); } } catch (Exception Ex) { Core.Tools.WriteLog("Err", "MainReply", Ex.Message); return(ErrXML()); } }