/// <summary> /// 插入一条记录到表MemWeChatMsg,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="memWeChatMsg">待插入的实体对象</param> public int AddMemWeChatMsg(MemWeChatMsgEntity entity) { string sql = @"insert into MemWeChatMsg( [UnionId],[OpenId],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadimgUrl],[AppId],[Status])VALUES ( @UnionId,@OpenId,@NickName,@Sex,@Language,@City,@Province,@Country,@HeadimgUrl,@AppId,@Status); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@UnionId", DbType.String, entity.UnionId); db.AddInParameter(cmd, "@OpenId", DbType.String, entity.OpenId); db.AddInParameter(cmd, "@NickName", DbType.String, entity.NickName); db.AddInParameter(cmd, "@Sex", DbType.Int32, entity.Sex); db.AddInParameter(cmd, "@Language", DbType.String, entity.Language); db.AddInParameter(cmd, "@City", DbType.String, entity.City); db.AddInParameter(cmd, "@Province", DbType.String, entity.Province); db.AddInParameter(cmd, "@Country", DbType.String, entity.Country); db.AddInParameter(cmd, "@HeadimgUrl", DbType.String, entity.HeadimgUrl); db.AddInParameter(cmd, "@AppId", DbType.String, entity.AppId); db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <MemWeChatMsgEntity> GetMemWeChatMsgAll() { string sql = @"SELECT [Id],[UnionId],[OpenId],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadimgUrl],[AppId],[Status] from dbo.[MemWeChatMsg] WITH(NOLOCK) "; IList <MemWeChatMsgEntity> entityList = new List <MemWeChatMsgEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { MemWeChatMsgEntity entity = new MemWeChatMsgEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.UnionId = StringUtils.GetDbString(reader["UnionId"]); entity.OpenId = StringUtils.GetDbString(reader["OpenId"]); entity.NickName = StringUtils.GetDbString(reader["NickName"]); entity.Sex = StringUtils.GetDbInt(reader["Sex"]); entity.Language = StringUtils.GetDbString(reader["Language"]); entity.City = StringUtils.GetDbString(reader["City"]); entity.Province = StringUtils.GetDbString(reader["Province"]); entity.Country = StringUtils.GetDbString(reader["Country"]); entity.HeadimgUrl = StringUtils.GetDbString(reader["HeadimgUrl"]); entity.AppId = StringUtils.GetDbString(reader["AppId"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(MemWeChatMsgEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[MemWeChatMsg] WITH(NOLOCK) "; string where = "where "; if (entity.Id == 0) { where = where + " (NickName=@NickName) "; } else { where = where + " id<>@Id and (NickName=@NickName) "; } sql = sql + where; DbCommand cmd = db.GetSqlStringCommand(sql); if (entity.Id > 0) { db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); } db.AddInParameter(cmd, "@NickName", DbType.String, entity.NickName); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 跟微信同 /// </summary> /// <returns></returns> public ActionResult WeChatCode() { string code = QueryString.SafeQ("wechatcode"); VWMemberEntity mem = new VWMemberEntity(); mem = MemberBLL.Instance.GetVWMember(memid); if (!string.IsNullOrEmpty(code) && string.IsNullOrEmpty(mem.WeChat)) { MemWeChatMsgEntity shortmsg = WeiXinJsSdk.Instance.GetWeChatShortInfo(code); if (!string.IsNullOrEmpty(shortmsg.OpenId) && !string.IsNullOrEmpty(shortmsg.UnionId)) { MemWeChatMsgEntity entity = new MemWeChatMsgEntity(); entity.AppId = WeiXinConfig.GetAppId(); entity.Status = (int)WeChatStatus.ShortInfo; entity.UnionId = shortmsg.UnionId; entity.OpenId = shortmsg.OpenId; MemWeChatMsgBLL.Instance.WeChatLogin(entity); MemberBLL.Instance.BindMemWeChat(memid, shortmsg.UnionId, mem.TimeStampTab); mem = MemberBLL.Instance.GetVWMember(memid); } } ViewBag.VWMember = mem; return(View()); }
public MemWeChatMsgEntity GetMsgByAppUnionId(string appid, string unionid) { string sql = @"SELECT [Id],[UnionId],[OpenId],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadimgUrl],[AppId],[Status] FROM dbo.[MemWeChatMsg] WITH(NOLOCK) WHERE [UnionId]=@UnionId and AppId=@AppId" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@AppId", DbType.String, appid); db.AddInParameter(cmd, "@UnionId", DbType.String, unionid); MemWeChatMsgEntity entity = new MemWeChatMsgEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.UnionId = StringUtils.GetDbString(reader["UnionId"]); entity.OpenId = StringUtils.GetDbString(reader["OpenId"]); entity.NickName = StringUtils.GetDbString(reader["NickName"]); entity.Sex = StringUtils.GetDbInt(reader["Sex"]); entity.Language = StringUtils.GetDbString(reader["Language"]); entity.City = StringUtils.GetDbString(reader["City"]); entity.Province = StringUtils.GetDbString(reader["Province"]); entity.Country = StringUtils.GetDbString(reader["Country"]); entity.HeadimgUrl = StringUtils.GetDbString(reader["HeadimgUrl"]); entity.AppId = StringUtils.GetDbString(reader["AppId"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); } } return(entity); }
/// <summary> /// 获取用户基本信息 /// </summary> /// <param name="code"></param> /// <returns></returns> public MemWeChatMsgEntity GetWeChatShortInfo(string code) { MemWeChatMsgEntity entity = new MemWeChatMsgEntity(); string simpleurl = WeiXinConfig.GetSimpleInfoUrl(code); string result = WebServiceClient.QueryGetWebService(simpleurl, "", null); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> jsonObj = serializer.Deserialize <dynamic>(result); if (jsonObj.ContainsKey("unionid")) { entity.UnionId = jsonObj["unionid"].ToString(); } if (jsonObj.ContainsKey("openid")) { entity.OpenId = jsonObj["openid"].ToString(); } if (jsonObj.ContainsKey("access_token")) { entity.Access_Token = jsonObj["access_token"].ToString(); } if (jsonObj.ContainsKey("refresh_token")) { entity.Refresh_Token = jsonObj["refresh_token"].ToString(); } return(entity); }
public ActionResult WeiXin() { if (Globals.IsWeiXinDevice()) { //是微信客户端走这边 string wechatcode = QueryString.SafeQ("wechatcode"); if (string.IsNullOrEmpty(wechatcode)) { string url = Request.Url.ToString(); string redirecturl = string.Format(WeiXinConfig.URL_WeiXin_Redirect, WeiXinConfig.GetAppId(), System.Web.HttpContext.Current.Server.UrlEncode(url), "0"); return(Redirect(redirecturl)); } else { MemWeChatMsgEntity msg = WeiXinJsSdk.Instance.GetWeChatShortInfo(wechatcode); string _paycode = QueryString.SafeQ("paycode"); VWPayOrderEntity _payen = PayOrderBLL.Instance.GetVWPayOrderByPayCode(_paycode); string redirecturl = string.Format(WeiXinConfig.URL_Pay_InWeiXin, msg.OpenId, _payen.NeedPayPrice); Response.Redirect(redirecturl); } } else { //网站类调出微信端支付通道 string _paycode = QueryString.SafeQ("paycode"); VWPayOrderEntity _payen = PayOrderBLL.Instance.GetVWPayOrderByPayCode(_paycode); DateTime dtnow = DateTime.Now; NativePay nativePay = new NativePay(); WxPayData data = nativePay.GetPayUrl(_payen, "MWEB");//得到调用微信接口的路径 string url = data.GetValue("mweb_url").ToString(); return(Redirect(url)); } return(View()); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <MemWeChatMsgEntity> GetMemWeChatMsgList(int pagesize, int pageindex, ref int recordCount) { string sql = @"SELECT [Id],[UnionId],[OpenId],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadimgUrl],[AppId],[Status] FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id],[UnionId],[OpenId],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadimgUrl],[AppId],[Status] from dbo.[MemWeChatMsg] WITH(NOLOCK) WHERE 1=1 ) as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[MemWeChatMsg] with (nolock) "; IList <MemWeChatMsgEntity> entityList = new List <MemWeChatMsgEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex); db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { MemWeChatMsgEntity entity = new MemWeChatMsgEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.UnionId = StringUtils.GetDbString(reader["UnionId"]); entity.OpenId = StringUtils.GetDbString(reader["OpenId"]); entity.NickName = StringUtils.GetDbString(reader["NickName"]); entity.Sex = StringUtils.GetDbInt(reader["Sex"]); entity.Language = StringUtils.GetDbString(reader["Language"]); entity.City = StringUtils.GetDbString(reader["City"]); entity.Province = StringUtils.GetDbString(reader["Province"]); entity.Country = StringUtils.GetDbString(reader["Country"]); entity.HeadimgUrl = StringUtils.GetDbString(reader["HeadimgUrl"]); entity.AppId = StringUtils.GetDbString(reader["AppId"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entityList.Add(entity); } } cmd = db.GetSqlStringCommand(sql2); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { recordCount = StringUtils.GetDbInt(reader[0]); } else { recordCount = 0; } } return(entityList); }
public string RegSubmit() { ResultObj _obj = new ResultObj(); string password = FormString.SafeQ("password"); string mobile = FormString.SafeQ("mobile"); string mobilecode = FormString.SafeQ("mobilecode"); if (System.Web.HttpContext.Current.Session[CommonKey.MobileNoRegister] == null || System.Web.HttpContext.Current.Session[CommonKey.MobileYZCode] == null) { _obj.Status = (int)CommonStatus.RegisterVerCodeHasExDay; } else if (System.Web.HttpContext.Current.Session[CommonKey.MobileNoRegister] == null || System.Web.HttpContext.Current.Session[CommonKey.MobileYZCode] == null || System.Web.HttpContext.Current.Session[CommonKey.MobileNoRegister].ToString() != mobile || System.Web.HttpContext.Current.Session[CommonKey.MobileYZCode].ToString() != mobilecode) { _obj.Status = (int)CommonStatus.RegisterErrorVerCode; } else { MemberEntity _mem = new MemberEntity(); _mem.MobilePhone = mobile; _mem.PassWord = password; //_mem.IsSupplier = issupplier; //_mem.IsStore = isstore; string code = CookieBLL.GetWeiXinWebCode(); if (!string.IsNullOrEmpty(code)) { MemWeChatMsgEntity shortmsg = WeiXinJsSdk.Instance.GetWeChatShortInfo(code); if (!string.IsNullOrEmpty(shortmsg.OpenId) && !string.IsNullOrEmpty(shortmsg.UnionId)) { _mem.WeChat = shortmsg.UnionId; } } _mem.CreateClientType = Globals.IsMobileDevice()? (int)ClientTypeEnum.Mobile:(int)ClientTypeEnum.PC; _mem.CreateIp = IPAddress.IP; _mem.Status = (int)MemberStatus.Active; _mem.LoginNum = 0; ResultObj _loginentity = MemberLoginBLL.Instance.Register1(_mem); if (_loginentity.Status == (int)CommonStatus.Success) { MemberEntity member = (MemberEntity)_loginentity.Obj; CookieBLL.SetRegisterCookie(StringUtils.GetDbInt(member.Id)); } _obj = _loginentity; } return(JsonJC.ObjectToJson(_obj)); }
public bool SendCGUrlToManager(string oldurl, int memid) { bool returnresult = false; string _redirecturl = oldurl; VWMemberEntity _memen = MemberBLL.Instance.GetVWMember(memid); WeChatNavigationEntity _entity = WeChatNavigationBLL.Instance.GetNavigationByUrl(_redirecturl); if (_entity == null || _entity.Id == 0) { _entity.RedirectUrl = _redirecturl; //_entity.Id = WeChatNavigationBLL.Instance.AddWeChatNavigation(_entity); } _entity.WeChatUrlType = (int)WeChatUrTypeEnum.Temp; _entity.Remark = "供应商临时登录报价"; //_entity.WeChatUrl = string.Format(WeiXinConfig.URL_FORMAT_KHRedirect, WeiXinConfig.GetAppId(), System.Web.HttpContext.Current.Server.UrlEncode(SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.WeChatWebUrl), _entity.Id); _entity.WeChatUrl = string.Format(WeiXinConfig.URL_WeiXin_Redirect, WeiXinConfig.GetAppId(), System.Web.HttpContext.Current.Server.UrlEncode(_redirecturl), _entity.Id); int _result = WeChatNavigationBLL.Instance.UpdateWeChatNavigation(_entity); IList <VWMemberEntity> memlist = MemberBLL.Instance.GetMemByAuthCode(MemberAuthEnum.InquiryOrderQuote); if (memlist != null && memlist.Count > 0) { foreach (VWMemberEntity mem in memlist) { if (!string.IsNullOrEmpty(mem.WeChat)) { MemWeChatMsgEntity wecharmsg = MemWeChatMsgBLL.Instance.GetMsgByAppUnionId(WeiXinConfig.GetAppId(), mem.WeChat); if (wecharmsg != null && !string.IsNullOrEmpty(wecharmsg.OpenId)) { WeiXinCustomerEntity customer = new WeiXinCustomerEntity(); customer.touser = wecharmsg.OpenId; customer.msgtype = WeiXinCustomerMsgtypeEnum.text; WeiXinCustomerTextEntity text = new WeiXinCustomerTextEntity(); text.content = "亲爱的" + _memen.CompanyName + "\n易店心来新的询价单,赶紧点击网址抢单额\n抢单网址:" + _entity.WeChatUrl; customer.text = text; returnresult = WeiXinJsSdk.Instance.SendWeiXinCustomerNote(customer); } } } } return(returnresult); }
/// <summary> /// 微信登录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int WeChatLogin(MemWeChatMsgEntity entity) { string sql = @" if EXISTS( SELECT 1 FROM MemWeChatMsg WHERE UnionId=@UnionId AND AppId=@AppId) BEGIN --如果没有获取过基本信息,此次获取的是基本信息,则完善信息 if(@Status=2 and EXISTS(SELECT 1 FROM MemWeChatMsg WHERE UnionId=@UnionId AND AppId=@AppId and Status=1)) begin UPDATE MemWeChatMsg SET [NickName]=@NickName,[Sex]=@Sex,[Language]=@Language,[City]=@City,[Province]=@Province, [Country]=@Country,[HeadimgUrl]=@HeadimgUrl, [Status]=@Status,loginNum=loginNum+1 WHERE UnionId=@UnionId AND AppId=@AppId end else begin UPDATE MemWeChatMsg SET loginNum=loginNum+1 WHERE UnionId=@UnionId AND AppId=@AppId end end ELSE BEGIN insert into MemWeChatMsg( [UnionId],[OpenId],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadimgUrl],[AppId],[Status])VALUES ( @UnionId,@OpenId,@NickName,@Sex,@Language,@City,@Province,@Country,@HeadimgUrl,@AppId,@Status) end"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@UnionId", DbType.String, entity.UnionId); db.AddInParameter(cmd, "@OpenId", DbType.String, entity.OpenId); db.AddInParameter(cmd, "@NickName", DbType.String, entity.NickName); db.AddInParameter(cmd, "@Sex", DbType.Int32, entity.Sex); db.AddInParameter(cmd, "@Language", DbType.String, entity.Language); db.AddInParameter(cmd, "@City", DbType.String, entity.City); db.AddInParameter(cmd, "@Province", DbType.String, entity.Province); db.AddInParameter(cmd, "@Country", DbType.String, entity.Country); db.AddInParameter(cmd, "@HeadimgUrl", DbType.String, entity.HeadimgUrl); db.AddInParameter(cmd, "@AppId", DbType.String, entity.AppId); db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 插入一条记录到表MemWeChatMsg,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="memWeChatMsg">要添加的MemWeChatMsg数据实体对象</param> public int AddMemWeChatMsg(MemWeChatMsgEntity memWeChatMsg) { if (memWeChatMsg.Id > 0) { return(UpdateMemWeChatMsg(memWeChatMsg)); } else if (string.IsNullOrEmpty(memWeChatMsg.NickName)) { return((int)CommonStatus.ADD_Fail_Empty); } else if (MemWeChatMsgBLL.Instance.IsExist(memWeChatMsg)) { return((int)CommonStatus.ADD_Fail_Exist); } else { return(MemWeChatMsgDA.Instance.AddMemWeChatMsg(memWeChatMsg)); } }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="memWeChatMsg">待更新的实体对象</param> public int UpdateMemWeChatMsg(MemWeChatMsgEntity entity) { string sql = @" UPDATE dbo.[MemWeChatMsg] SET [UnionId]=@UnionId,[OpenId]=@OpenId,[NickName]=@NickName,[Sex]=@Sex,[Language]=@Language,[City]=@City,[Province]=@Province,[Country]=@Country,[HeadimgUrl]=@HeadimgUrl,[AppId]=@AppId,[Status]=@Status WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@UnionId", DbType.String, entity.UnionId); db.AddInParameter(cmd, "@OpenId", DbType.String, entity.OpenId); db.AddInParameter(cmd, "@NickName", DbType.String, entity.NickName); db.AddInParameter(cmd, "@Sex", DbType.Int32, entity.Sex); db.AddInParameter(cmd, "@Language", DbType.String, entity.Language); db.AddInParameter(cmd, "@City", DbType.String, entity.City); db.AddInParameter(cmd, "@Province", DbType.String, entity.Province); db.AddInParameter(cmd, "@Country", DbType.String, entity.Country); db.AddInParameter(cmd, "@HeadimgUrl", DbType.String, entity.HeadimgUrl); db.AddInParameter(cmd, "@AppId", DbType.String, entity.AppId); db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status); return(db.ExecuteNonQuery(cmd)); }
/// <summary> /// 发送微信通知 /// </summary> /// <param name="WeChatUnionId"></param> /// <param name="redirecturl"></param> /// <param name="templetid"></param> /// <param name="hashen"></param> /// <returns></returns> public bool SendWeiXinMsgNote(string WeChatUnionId, string redirecturl, string templetid, Hashtable hashen) { bool success = false; //获取链接导航Id //int navid = WeChatNavigationBLL.Instance.GetIdByUrl(redirecturl); MemWeChatMsgEntity wecharmsg = MemWeChatMsgBLL.Instance.GetMsgByAppUnionId(WeiXinConfig.GetAppId(), WeChatUnionId); if (wecharmsg != null && !string.IsNullOrEmpty(wecharmsg.OpenId)) { WeiXinSendMsgEntity send = new WeiXinSendMsgEntity(); send.touser = wecharmsg.OpenId; send.template_id = templetid; string resulturl = string.Format(WeiXinConfig.URL_WeiXin_Redirect, WeiXinConfig.GetAppId(), System.Web.HttpContext.Current.Server.UrlEncode(redirecturl), "0"); send.url = resulturl; send.data = hashen; string json = JsonJC.ObjectToJson(send); string url = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken(false)); ///发送微信备案 WeChatMsgEntity msg = new WeChatMsgEntity(); msg.ParamStr = json; msg.WeChatOpenId = wecharmsg.OpenId; msg.RedirectUrl = redirecturl; msg.WeChatUrl = url; msg.TemplateIid = templetid; msg.Id = WeChatMsgBLL.Instance.AddWeChatMsg(msg); string result = WebServiceClient.QueryPostWebServiceJson(url, json); WeiXinFailEntity resulten = JsonJC.JsonToObject <WeiXinFailEntity>(result); msg.Result = result; WeChatMsgBLL.Instance.UpdateWeChatMsg(msg); if (resulten.errmsg.ToLower() == "ok") { success = true; } else if (resulten.errcode == "40001" && resulten.errmsg.Contains("access_token is invalid or not latest hint")) { ///发现accesstoken过期后再次发送 WeiXinJsSdk.Instance.RemoveAccessToken(); url = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken(false)); ///发送微信备案 msg.WeChatUrl = url; msg.Result = ""; msg.Id = 0; msg.Id = WeChatMsgBLL.Instance.AddWeChatMsg(msg); result = WebServiceClient.QueryPostWebServiceJson(url, json); resulten = JsonJC.JsonToObject <WeiXinFailEntity>(result); msg.Result = result; WeChatMsgBLL.Instance.UpdateWeChatMsg(msg); if (resulten.errmsg.ToLower() == "ok") { success = true; } else { //需发邮件提醒 EmailSendBLL.Instance.WeiXinSendFail(WeChatUnionId, redirecturl); } } else { //需发邮件提醒 EmailSendBLL.Instance.WeiXinSendFail(WeChatUnionId, redirecturl); } } return(success); }
/// <summary> /// 更新一条MemWeChatMsg记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="memWeChatMsg">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateMemWeChatMsg(MemWeChatMsgEntity memWeChatMsg) { return(MemWeChatMsgDA.Instance.UpdateMemWeChatMsg(memWeChatMsg)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(MemWeChatMsgEntity memWeChatMsg) { return(MemWeChatMsgDA.Instance.ExistNum(memWeChatMsg) > 0); }
public int WeChatLogin(MemWeChatMsgEntity entity) { return(MemWeChatMsgDA.Instance.WeChatLogin(entity)); }
/// <summary> /// 通知供应商 /// </summary> /// <param name="code"></param> /// <returns></returns> public bool NoteToCGMemForQuote(string code) { bool result = false; string emailnote = "供应商发送微信情况<br/>"; emailnote += "订单号:" + code + "<br/>"; InquiryOrderEntity order = InquiryOrderBLL.Instance.GetInquiryOrderByCode(code); string memidsold = CGMemQuotedBLL.Instance.GetQuotedCGMemByCode(order.Code); string memidsnew = MemCGScopeBLL.Instance.GetCGMemIdsByCarBrand(order.ScopeType, order.CarBrandName, memidsold); //获取虚拟报价员 IList <VWMemberEntity> memlist = MemberBLL.Instance.GetMemByAuthCode(MemberAuthEnum.InquiryOrderQuote); string[] memidsoldattr = memidsold.Split(','); string[] memidnewattr = memidsnew.Split(','); bool hascg = false; if (!string.IsNullOrEmpty(memidsnew)) { hascg = true; } if (memlist != null && memlist.Count > 0) { foreach (VWMemberEntity cgmemsup in memlist) { bool oldhas = false; if (memidsoldattr != null && memidsoldattr.Length > 0) { foreach (string memidoleen in memidsoldattr) { if (cgmemsup.MemId.ToString() == memidoleen) { oldhas = true; break; } } if (!oldhas) { foreach (string memidnewen in memidnewattr) { if (cgmemsup.MemId.ToString() == memidnewen) { oldhas = true; break; } } } } if (!oldhas) { memidsnew += "," + cgmemsup.MemId.ToString(); } } } int resultrowi = CGMemQuotedBLL.Instance.AddInquiryToCGMemQuoted(order.Code, memidsnew); //获取要发送的供应商,并发送通知 //InquiryOrderBLL.Instance.UpdateQuoteStatus(order.Code, (int)QuoteStatusEnum.HasSend); IList <CGMemQuotedEntity> _sendlist = CGMemQuotedBLL.Instance.GetCGMemQuotedNeedSend(order.Code); string redirecturl = ConfigCore.Instance.ConfigCommonEntity.InquiryWebUrl + string.Format(WebUrlEnum.InquiryCGMemNote, code); //int navid = WeChatNavigationBLL.Instance.GetIdByUrl(redirecturl); //string url = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken(false)); if (!hascg) { emailnote += "没有找到供应商<br/>"; } if (_sendlist != null && _sendlist.Count > 0) { foreach (CGMemQuotedEntity entity in _sendlist) { if (!hascg) { string title = "您的询价单没有找到供应商额,订单编号:" + order.Code; string ordercode = entity.InquiryOrderCode; try { //获取链接导航Id int memid = entity.CGMemId; VWMemberEntity memen = MemberBLL.Instance.GetVWMember(memid); emailnote += memen.CompanyName + memen.MobilePhone + memen.CompanyAddress + " "; if (!string.IsNullOrEmpty(memen.WeChat)) { Hashtable hashentity = new Hashtable(); hashentity.Add("first", new WeiXinUnitEntity() { value = title }); hashentity.Add("keyword1", new WeiXinUnitEntity() { value = "无" }); hashentity.Add("keyword2", new WeiXinUnitEntity() { value = order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }); hashentity.Add("keyword3", new WeiXinUnitEntity() { value = order.CarBrandName }); hashentity.Add("keyword4", new WeiXinUnitEntity() { value = "备注" + order.Remark }); hashentity.Add("remark", new WeiXinUnitEntity() { value = "" }); bool sendsuccess = WeiXinJsSdk.Instance.SendWeiXinMsgNote(memen.WeChat, redirecturl, WeiXinTemplet.InquiryNeedNote, hashentity); if (sendsuccess) { result = sendsuccess; //发送微信成功备份 CGMemQuotedBLL.Instance.CGQuotedSend(memid, ordercode); emailnote += "发送成功<br/>"; } } else { emailnote += "没有绑定微信<br/>"; ////需发邮件提醒 //EmailSendEntity email = new EmailSendEntity(); //email.CreateTime = DateTime.Now; //email.Body = "询价单编号:" + order.Code + "<br/> 供应商:" + memen.MemCode + "(" + memen.MobilePhone + ")" + memen.MemGradeName + ",<br/>网址:" + redirecturl; //var emailsendstr = SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.SendMailManager; //if (emailsendstr == null || string.IsNullOrEmpty(emailsendstr.ToString())) //{ // email.Email = "*****@*****.**"; //} //else //{ // email.Email = emailsendstr.ToString(); //} //email.Title = "询价单发送微信错误供应商未登记微信"; //email.Status = 0; //EmailSendBLL.Instance.AddEmailSend(email); } } catch (Exception ex) { emailnote += "发送错误" + ex.Message + "<br/>"; LogUtil.Log("微信发送询价出错:订单号:" + ordercode, ex.Message); } } else { string title = "您有订单需要报价啦,赶紧抢单,订单编号:" + order.Code; if (entity.HasSend == 1) { title = "客户修改了询价单信息,请完善报价,订单编号:" + order.Code; } string ordercode = entity.InquiryOrderCode; try { //获取链接导航Id int memid = entity.CGMemId; VWMemberEntity memen = MemberBLL.Instance.GetVWMember(memid); emailnote += memen.CompanyName + memen.MobilePhone + memen.CompanyAddress + " "; if (!string.IsNullOrEmpty(memen.WeChat)) { Hashtable hashentity = new Hashtable(); hashentity.Add("first", new WeiXinUnitEntity() { value = title }); hashentity.Add("tradeDateTime", new WeiXinUnitEntity() { value = order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }); hashentity.Add("orderType", new WeiXinUnitEntity() { value = "询价订单" }); hashentity.Add("customerInfo", new WeiXinUnitEntity() { value = "易店心" }); hashentity.Add("orderItemName", new WeiXinUnitEntity() { value = "备注" }); hashentity.Add("orderItemData", new WeiXinUnitEntity() { value = order.Remark }); hashentity.Add("remark", new WeiXinUnitEntity() { value = "" }); bool sendsuccess = WeiXinJsSdk.Instance.SendWeiXinMsgNote(memen.WeChat, redirecturl, WeiXinTemplet.InquiryQuoteSend, hashentity); if (sendsuccess) { result = sendsuccess; //发送微信成功备份 CGMemQuotedBLL.Instance.CGQuotedSend(memid, ordercode); emailnote += "发送成功<br/>"; } else { emailnote += "发送失败<br/>"; } //else //{ // //需发邮件提醒 // EmailSendEntity email = new EmailSendEntity(); // email.CreateTime = DateTime.Now; // email.Body = "询价单编号:" + order.Code + "<br/> 供应商:" + memen.MemCode + "(" + memen.MobilePhone + ")" + memen.MemGradeName + ",<br/>网址:" + redirecturl; // var emailsendstr = SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.SendMailManager; // if (emailsendstr == null || string.IsNullOrEmpty(emailsendstr.ToString())) // { // email.Email = "*****@*****.**"; // } // else // { // email.Email = emailsendstr.ToString(); // } // email.Title = "询价单发送微信通知失败"; // email.Status = 0; // EmailSendBLL.Instance.AddEmailSend(email); //} } else { emailnote += "没有绑定微信<br/>"; ////需发邮件提醒 //EmailSendEntity email = new EmailSendEntity(); //email.CreateTime = DateTime.Now; //email.Body = "询价单编号:" + order.Code + "<br/> 供应商:" + memen.MemCode + "(" + memen.MobilePhone + ")" + memen.MemGradeName + ",<br/>网址:" + redirecturl; //var emailsendstr = SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.SendMailManager; //if (emailsendstr == null || string.IsNullOrEmpty(emailsendstr.ToString())) //{ // email.Email = "*****@*****.**"; //} //else //{ // email.Email = emailsendstr.ToString(); //} //email.Title = "询价单发送微信错误供应商未登记微信"; //email.Status = 0; //EmailSendBLL.Instance.AddEmailSend(email); } } catch (Exception ex) { emailnote += "发送错误" + ex.Message + "<br/>"; LogUtil.Log("微信发送询价出错:订单号:" + ordercode, ex.Message); } } } } else { InquiryOrderBLL.Instance.UpdateQuoteStatus(order.Code, (int)QuoteStatusEnum.SendFail); } string notemsg = emailnote + "报价网址" + redirecturl + "<br/>"; notemsg += "转移到线下网址:" + SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.InquiryMobileWebUrl + "/Check/copyinquiry?code=" + order.Code + "<br/>"; //notemsg+="订单信息:订单号:" + order.Code+"<br/>"; //notemsg+="备注" + order.Remark+ "<br/>"; //notemsg+="图片信息" + "<br/>"; //if(!string.IsNullOrEmpty(order.VinPic)) //{ // notemsg += "<img src='" + SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.ImagesServerUrl + order.VinPic + "' />"; //} //if (!string.IsNullOrEmpty(order.EngineModelPic)) //{ // notemsg += "<img src='" + SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.ImagesServerUrl + order.EngineModelPic + "' />"; //} //if (order.OrderPics!=null&& order.OrderPics.Count>0) //{ // foreach(InquiryOrderPicsEntity pic in order.OrderPics) // { // notemsg += "<img src='" + SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.ImagesServerUrl + pic.PicUrl + "' />"; // } //} //notemsg +="<br/>"; //notemsg += "产品信息" + "<br/>"; //if (order.OrderProducts != null && order.OrderProducts.Count > 0 && order.OrderProductSubs!=null && order.OrderProductSubs.Count>0) //{ // Dictionary<int, IList<InquiryProductSubEntity>> prosubdic = new Dictionary<int, IList<InquiryProductSubEntity>>(); // foreach (InquiryProductSubEntity prosub in order.OrderProductSubs) // { // if(!prosubdic.ContainsKey(prosub.InquiryProductId)) // { // prosubdic.Add(prosub.InquiryProductId, new List<InquiryProductSubEntity>()); // } // prosubdic[prosub.InquiryProductId].Add(prosub); // } // foreach(InquiryProductEntity pro in order.OrderProducts) // { // if(prosubdic.ContainsKey(pro.Id)) // { // IList <InquiryProductSubEntity> prosublist = prosubdic[pro.Id]; // if(prosublist!=null&& prosublist.Count>0) // { // foreach(InquiryProductSubEntity prosub in prosublist) // { // notemsg += pro.ProductName + " " + prosub.InquiryProductTypeName + "<br/>"; // } // } // } // } //} if (memlist != null && memlist.Count > 0) { foreach (VWMemberEntity cgmemsup in memlist) { MemWeChatMsgEntity wecharmsg = MemWeChatMsgBLL.Instance.GetMsgByAppUnionId(WeiXinConfig.GetAppId(), cgmemsup.WeChat); WeiXinCustomerEntity customer = new WeiXinCustomerEntity(); customer.touser = wecharmsg.OpenId; customer.msgtype = WeiXinCustomerMsgtypeEnum.text; WeiXinCustomerTextEntity text = new WeiXinCustomerTextEntity(); text.content = notemsg.Replace("<br/>", "\n"); customer.text = text; WeiXinJsSdk.Instance.SendWeiXinCustomerNote(customer); } } //需发邮件提醒 EmailSendEntity email = new EmailSendEntity(); email.CreateTime = DateTime.Now; email.Body = notemsg; var emailsendstr = SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.SendMailManager; if (emailsendstr == null || string.IsNullOrEmpty(emailsendstr.ToString())) { email.Email = "*****@*****.**"; } else { email.Email = emailsendstr.ToString(); } email.Title = "询价单没有找到供应商进行报价"; email.Status = 0; EmailSendBLL.Instance.AddEmailSend(email); return(result); }
/// <summary> /// 用户登录 /// </summary> /// <returns></returns> public ActionResult Login() { if (Globals.IsMobileDevice() && Request.Url.AbsoluteUri.Contains(ConfigCore.Instance.ConfigCommonEntity.LoginWebUrl)) { return(Redirect(Request.Url.AbsoluteUri.Replace(ConfigCore.Instance.ConfigCommonEntity.LoginWebUrl, ConfigCore.Instance.ConfigCommonEntity.LoginMobileWebUrl))); } string returnurl = StringUtils.GetDbString(Request.QueryString["returnurl"]); string unionid = ""; string code = QueryString.SafeQ("wechatcode"); //微信自动登录 if (!string.IsNullOrEmpty(code)) { MemWeChatMsgEntity shortmsg = WeiXinJsSdk.Instance.GetWeChatShortInfo(code); if (!string.IsNullOrEmpty(shortmsg.OpenId) && !string.IsNullOrEmpty(shortmsg.UnionId)) { unionid = shortmsg.UnionId; System.Web.HttpContext.Current.Session[CommonKey.WeChatUnionId] = unionid; MemWeChatMsgEntity entity = new MemWeChatMsgEntity(); entity.AppId = WeiXinConfig.GetAppId(); entity.Status = (int)WeChatStatus.ShortInfo; entity.UnionId = shortmsg.UnionId; entity.OpenId = shortmsg.OpenId; MemWeChatMsgBLL.Instance.WeChatLogin(entity); ResultObj _result = MemberLoginBLL.Instance.Login(unionid, "", "", (int)ClientTypeEnum.PC, IPAddress.IP); if (_result != null && _result.Obj != null) { if (_result.Status == (int)CommonStatus.Success) { MemberLoginEntity _loginmodel = (MemberLoginEntity)_result.Obj; if (_loginmodel.Status == (int)MemberStatus.Active) { CookieBLL.SetLoginCookie(_loginmodel, false); CookieBLL.ComBineCart(1); CookieBLL.ComBineCartXuQiu(1); if (string.IsNullOrEmpty(returnurl)) { returnurl = SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.MainWebUrl; } return(Redirect(returnurl)); } } } } } string tempcode = StringUtils.SafeCodeSmall(QueryString.SafeQNo("tempcode"));//临时自动登录 if (!string.IsNullOrEmpty(tempcode)) { ResultObj _resulttemp = MemberLoginBLL.Instance.LoginByTempCode(tempcode, unionid, (int)ClientTypeEnum.PC, IPAddress.IP); if (_resulttemp != null && _resulttemp.Obj != null) { if (_resulttemp.Status == (int)CommonStatus.Success) { MemberLoginEntity _loginmodel = (MemberLoginEntity)_resulttemp.Obj; if (_loginmodel.Status == (int)MemberStatus.Active) { CookieBLL.SetLoginCookie(_loginmodel, false); CookieBLL.ComBineCart(1); CookieBLL.ComBineCartXuQiu(1); if (string.IsNullOrEmpty(returnurl)) { returnurl = SuperMarket.Core.ConfigCore.Instance.ConfigCommonEntity.MainWebUrl; } return(Redirect(returnurl)); } } } } ViewBag.ReturnUrl = returnurl; return(View()); }
/// <summary> /// 询价订单供应商发送微信提醒 /// </summary> /// <returns></returns> public string WeChatInquiryOrderSend() { ResultObj result = new ResultObj(); string ordercode = FormString.SafeQ("ordercode"); string memids = FormString.SafeQ("memids"); memids = memids.Trim(','); string[] memidattr = memids.Split(','); InquiryOrderEntity orderentity = InquiryOrderBLL.Instance.GetInquiryOrderByCode(ordercode); if (orderentity != null && orderentity.Status == (int)OrderInquiryStatusEnum.Quoting) { string url = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken()); string resulturl = SuperMarketWebUrl.InquiryOrderSendWeChat(ordercode); string redirecturl = SuperMarketWebUrl.InquiryOrderUrl(ordercode); result.Obj = resulturl; ////获取链接导航Id //int navid = WeChatNavigationBLL.Instance.GetIdByUrl(redirecturl); foreach (string memidstr in memidattr) { int memid = StringUtils.GetDbInt(memidstr); MemberEntity memen = MemberBLL.Instance.GetMember(memid); if (!string.IsNullOrEmpty(memen.WeChat)) { MemWeChatMsgEntity wecharmsg = MemWeChatMsgBLL.Instance.GetMsgByAppUnionId(WeiXinConfig.GetAppId(), memen.WeChat); if (wecharmsg != null && !string.IsNullOrEmpty(wecharmsg.OpenId)) { WeiXinSendMsgEntity send = new WeiXinSendMsgEntity(); send.touser = wecharmsg.OpenId; send.template_id = WeiXinTemplet.InquiryQuoteSend; send.url = resulturl; WeiXinInquiryEntity inq = new WeiXinInquiryEntity(); inq.first = new WeiXinUnitEntity() { value = "您有订单需要报价啦,赶紧抢单,订单编号:" + orderentity.Code }; inq.tradeDateTime = new WeiXinUnitEntity() { value = orderentity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }; inq.orderType = new WeiXinUnitEntity() { value = "询价订单" }; inq.customerInfo = new WeiXinUnitEntity() { value = "易店心" }; //inq.orderItemName = new WeiXinUnitEntity() { value = "随机名称" }; //inq.orderItemData = new WeiXinUnitEntity() { value = "随机数据" }; inq.remark = new WeiXinUnitEntity() { value = orderentity.Remark }; send.data = inq; string json = JsonJC.ObjectToJson(send); WeChatMsgEntity msg = new WeChatMsgEntity(); msg.ParamStr = json; msg.WeChatOpenId = wecharmsg.OpenId; msg.RedirectUrl = redirecturl; msg.WeChatUrl = url; msg.TemplateIid = WeiXinTemplet.InquiryQuoteSend; msg.Id = WeChatMsgBLL.Instance.AddWeChatMsg(msg); string resultrowi = WebServiceClient.QueryPostWebServiceJson(url, json); WeiXinFailEntity resulten = JsonJC.JsonToObject <WeiXinFailEntity>(resultrowi); if (resulten.errmsg.ToLower() == "ok") { CGMemQuotedBLL.Instance.CGQuotedSend(memid, ordercode); } msg.Result = resultrowi; WeChatMsgBLL.Instance.UpdateWeChatMsg(msg); } } } } else { CGMemQuotedBLL.Instance.QuotedCloseByCode(ordercode); } result.Status = (int)CommonStatus.Success; return(JsonJC.ObjectToJson(result)); }