/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(WeChatMsgEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[WeChatMsg] WITH(NOLOCK) "; string where = "where "; if (entity.Id == 0) { } else { } sql = sql + where; DbCommand cmd = db.GetSqlStringCommand(sql); if (entity.Id > 0) { db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); } object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 根据主键值读取记录。如果数据库不存在这条数据将返回null /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public WeChatMsgEntity GetWeChatMsg(int id) { string sql = @"SELECT [Id],[WeChatOpenId],[TemplateIid],[WeChatUrl],[ParamStr],[Result],[Remark] FROM dbo.[WeChatMsg] WITH(NOLOCK) WHERE [Id]=@id" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, id); WeChatMsgEntity entity = new WeChatMsgEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.WeChatOpenId = StringUtils.GetDbString(reader["WeChatOpenId"]); entity.TemplateIid = StringUtils.GetDbString(reader["TemplateIid"]); entity.WeChatUrl = StringUtils.GetDbString(reader["WeChatUrl"]); entity.ParamStr = StringUtils.GetDbString(reader["ParamStr"]); entity.Result = StringUtils.GetDbString(reader["Result"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); } } return(entity); }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="weChatMsg">待更新的实体对象</param> public int UpdateWeChatMsg(WeChatMsgEntity entity) { string sql = @" UPDATE dbo.[WeChatMsg] SET [WeChatOpenId]=@WeChatOpenId,[TemplateIid]=@TemplateIid,[WeChatUrl]=@WeChatUrl,[ParamStr]=@ParamStr,[Result]=@Result,[Remark]=@Remark WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@WeChatOpenId", DbType.String, entity.WeChatOpenId); db.AddInParameter(cmd, "@TemplateIid", DbType.String, entity.TemplateIid); db.AddInParameter(cmd, "@WeChatUrl", DbType.String, entity.WeChatUrl); db.AddInParameter(cmd, "@ParamStr", DbType.String, entity.ParamStr); db.AddInParameter(cmd, "@Result", DbType.String, entity.Result); db.AddInParameter(cmd, "@Remark", DbType.String, entity.Remark); return(db.ExecuteNonQuery(cmd)); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <WeChatMsgEntity> GetWeChatMsgList(int pagesize, int pageindex, ref int recordCount) { string sql = @"SELECT [Id],[WeChatOpenId],[TemplateIid],[WeChatUrl],[ParamStr],[Result],[Remark] FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id],[WeChatOpenId],[TemplateIid],[WeChatUrl],[ParamStr],[Result],[Remark] from dbo.[WeChatMsg] WITH(NOLOCK) WHERE 1=1 ) as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[WeChatMsg] with (nolock) "; IList <WeChatMsgEntity> entityList = new List <WeChatMsgEntity>(); 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()) { WeChatMsgEntity entity = new WeChatMsgEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.WeChatOpenId = StringUtils.GetDbString(reader["WeChatOpenId"]); entity.TemplateIid = StringUtils.GetDbString(reader["TemplateIid"]); entity.WeChatUrl = StringUtils.GetDbString(reader["WeChatUrl"]); entity.ParamStr = StringUtils.GetDbString(reader["ParamStr"]); entity.Result = StringUtils.GetDbString(reader["Result"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); 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); }
/// <summary> /// 插入一条记录到表WeChatMsg,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="weChatMsg">待插入的实体对象</param> public int AddWeChatMsg(WeChatMsgEntity entity) { string sql = @"insert into WeChatMsg( [WeChatOpenId],[TemplateIid],[WeChatUrl],[ParamStr],[Result],[Remark])VALUES ( @WeChatOpenId,@TemplateIid,@WeChatUrl,@ParamStr,@Result,@Remark); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@WeChatOpenId", DbType.String, entity.WeChatOpenId); db.AddInParameter(cmd, "@TemplateIid", DbType.String, entity.TemplateIid); db.AddInParameter(cmd, "@WeChatUrl", DbType.String, entity.WeChatUrl); db.AddInParameter(cmd, "@ParamStr", DbType.String, entity.ParamStr); db.AddInParameter(cmd, "@Result", DbType.String, entity.Result); db.AddInParameter(cmd, "@Remark", DbType.String, entity.Remark); 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 <WeChatMsgEntity> GetWeChatMsgAll() { string sql = @"SELECT [Id],[WeChatOpenId],[TemplateIid],[WeChatUrl],[ParamStr],[Result],[Remark] from dbo.[WeChatMsg] WITH(NOLOCK) "; IList <WeChatMsgEntity> entityList = new List <WeChatMsgEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { WeChatMsgEntity entity = new WeChatMsgEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.WeChatOpenId = StringUtils.GetDbString(reader["WeChatOpenId"]); entity.TemplateIid = StringUtils.GetDbString(reader["TemplateIid"]); entity.WeChatUrl = StringUtils.GetDbString(reader["WeChatUrl"]); entity.ParamStr = StringUtils.GetDbString(reader["ParamStr"]); entity.Result = StringUtils.GetDbString(reader["Result"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); entityList.Add(entity); } } return(entityList); }
public bool SendWeiXinCustomerNote(WeiXinCustomerEntity customer) { bool success = false; string url = string.Format(WeiXinConfig.Customer_Format_Send, WeiXinJsSdk.Instance.GetAccessToken(false)); string json = JsonJC.ObjectToJson(customer); string result = WebServiceClient.QueryPostWebServiceJson(url, json); WeiXinFailEntity resulten = JsonJC.JsonToObject <WeiXinFailEntity>(result); ///发送微信备案 WeChatMsgEntity msg = new WeChatMsgEntity(); msg.ParamStr = json; msg.WeChatOpenId = ""; msg.RedirectUrl = ""; msg.WeChatUrl = url; msg.TemplateIid = ""; msg.Result = result; msg.Id = WeChatMsgBLL.Instance.AddWeChatMsg(msg); if (resulten.errmsg.ToLower() == "ok") { success = true; } return(success); }
/// <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> /// 更新一条WeChatMsg记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="weChatMsg">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateWeChatMsg(WeChatMsgEntity weChatMsg) { return(WeChatMsgDA.Instance.UpdateWeChatMsg(weChatMsg)); }
/// <summary> /// 插入一条记录到表WeChatMsg,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="weChatMsg">要添加的WeChatMsg数据实体对象</param> public int AddWeChatMsg(WeChatMsgEntity weChatMsg) { return(WeChatMsgDA.Instance.AddWeChatMsg(weChatMsg)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(WeChatMsgEntity weChatMsg) { return(WeChatMsgDA.Instance.ExistNum(weChatMsg) > 0); }
/// <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)); }