public string UpdateFeedback(string feedbackId, LoggingSessionInfo loggiongSessionInfo) { var wxRightOrdersBll = new WXRightOrdersBLL(loggiongSessionInfo); var feedbackEntity = wxRightOrdersBll.QueryByEntity(new WXRightOrdersEntity() { FeedBackId = feedbackId }, null).FirstOrDefault(); if (feedbackEntity == null) { throw new APIException("无效的维权单号") { ErrorCode = 122 }; } var serder = new WApplicationInterfaceBLL(loggiongSessionInfo); //获取微信公众号的信息 var appEntity = serder.QueryByEntity(new WApplicationInterfaceEntity() { CustomerId = loggiongSessionInfo.ClientID }, null).FirstOrDefault(); if (appEntity == null) { throw new APIException("微信公众号信息为空") { ErrorCode = 121 }; } var common = new CommonBLL(); //获取微信的AccessToken var accessToken = common.GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, loggiongSessionInfo).access_token; //{"errcode":0,"errmsg":"ok"} var result = common.UpdatePayFeedBack(accessToken, loggiongSessionInfo, feedbackEntity.OpenId, feedbackId); var data = result.DeserializeJSONTo <WxErrMessage>(); return(data.errmsg); }
private void SendWeixinMessage(TimingPushMessageRuleEntity timingPushMessageRuleEntity) { //得到可以发送的人员列表 WUserMessageBLL wUserMessageBll = new WUserMessageBLL(loggingSessionInfo); WUserMessageEntity[] wUserMessageEntities = wUserMessageBll.GetActiveUserMessageList(); if (wUserMessageEntities.Length == 0) { return; } WApplicationInterfaceEntity applicationInterfaceEntity = null; foreach (var vipEntity in wUserMessageEntities) { //TODO:默认为一个客户一个微信,为了性能增加如下代码。如果多个用多个微信,则要将null判断取消 if (applicationInterfaceEntity == null) { applicationInterfaceEntity = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity { WeiXinID = vipEntity.WeiXinId }, null)[0]; } string appID = applicationInterfaceEntity.AppID; string appSecret = applicationInterfaceEntity.AppSecret; CommonBLL commonService = new CommonBLL(); //获取对应模型列表 TimingPushMessageRuleModelMappingBLL ruleModelMappingBll = new TimingPushMessageRuleModelMappingBLL(loggingSessionInfo); TimingPushMessageRuleModelMappingEntity[] ruleModelMappingEntities = ruleModelMappingBll.QueryByEntity(new TimingPushMessageRuleModelMappingEntity { TimingPushMessageRuleID = timingPushMessageRuleEntity.TimingPushMessageRuleID }, null); foreach (var timingPushMessageRuleModelMappingEntity in ruleModelMappingEntities) { WModelEntity modelEntity = new WModelBLL(loggingSessionInfo).GetByID(timingPushMessageRuleModelMappingEntity.ModelID); //得到当前用户当前模型已经发送的最后文章ID TimingPushMessageVipLastRecordBLL lastRecordBll = new TimingPushMessageVipLastRecordBLL(loggingSessionInfo); TimingPushMessageVipLastRecordEntity[] lastRecordEntities = lastRecordBll.QueryByEntity(new TimingPushMessageVipLastRecordEntity { VipID = vipEntity.VipId, LastModelID = modelEntity.ModelId }, null); TimingPushMessageVipLastRecordEntity lastRecordEntity = new TimingPushMessageVipLastRecordEntity(); if (lastRecordEntities.Length > 0) { lastRecordEntity = lastRecordEntities[0]; } switch (modelEntity.MaterialTypeId) { case 1: var dsMaterialWriting = new WMaterialWritingDAO(loggingSessionInfo).GetWMaterialWritingByID(modelEntity.MaterialId); if (dsMaterialWriting != null && dsMaterialWriting.Tables.Count > 0 && dsMaterialWriting.Tables[0].Rows.Count > 0) { DataRow[] content = GetCurrentArticle(dsMaterialWriting, lastRecordEntity, 1); if (content == null) { return; } //推送消息 if (content.Length > 0) { SendMessageEntity sendInfo = new SendMessageEntity(); sendInfo.msgtype = "text"; sendInfo.touser = vipEntity.OpenId; sendInfo.content = content[0]["Content"].ToString(); ResultEntity msgResultObj = commonService.SendMessage(sendInfo, appID, appSecret, loggingSessionInfo); //保存发送记录 TimingPushMessageBLL timingPushMessageBll = new TimingPushMessageBLL(loggingSessionInfo); TimingPushMessageEntity timingPushMessageEntity = new TimingPushMessageEntity(); timingPushMessageEntity.ClientID = loggingSessionInfo.ClientID; timingPushMessageEntity.IsDelete = 0; timingPushMessageEntity.CreateBy = "System"; timingPushMessageEntity.CreateTime = DateTime.Now; timingPushMessageEntity.TimingPushMessageID = Guid.NewGuid(); timingPushMessageEntity.MemberID = vipEntity.VipId; timingPushMessageEntity.ObjectID = content[0]["WritingId"].ToString(); timingPushMessageEntity.Status = 1; timingPushMessageBll.Create(timingPushMessageEntity); //保存最后一条记录 if (lastRecordEntity != null && lastRecordEntity.LastContentID != null) { lastRecordBll.Update(new TimingPushMessageVipLastRecordEntity { TimingPushMessageVipLastRecordID = lastRecordEntity.TimingPushMessageVipLastRecordID, ClientID = loggingSessionInfo.ClientID, CreateBy = "System", CreateTime = DateTime.Now, CSPipelineID = timingPushMessageRuleEntity.CSPipelineID, TimingPushMessageRuleID = timingPushMessageRuleEntity.TimingPushMessageRuleID, VipID = vipEntity.VipId, IsDelete = 0, LastContentID = content[0]["WritingId"].ToString(), LastContentIndex = lastRecordEntity.LastContentIndex + 1, LastModelID = modelEntity.ModelId }); } else { lastRecordBll.Create(new TimingPushMessageVipLastRecordEntity { TimingPushMessageVipLastRecordID = Guid.NewGuid(), ClientID = loggingSessionInfo.ClientID, CreateBy = "System", CreateTime = DateTime.Now, TimingPushMessageRuleID = timingPushMessageRuleEntity.TimingPushMessageRuleID, CSPipelineID = timingPushMessageRuleEntity.CSPipelineID, VipID = vipEntity.VipId, IsDelete = 0, LastContentID = content[0]["WritingId"].ToString(), LastContentIndex = 1, LastModelID = modelEntity.ModelId }); } } } break; case 2: break; case 3: var dsMaterialText = new WMaterialTextDAO(loggingSessionInfo).GetMaterialTextByID(modelEntity.MaterialId); if (dsMaterialText != null && dsMaterialText.Tables.Count > 0 && dsMaterialText.Tables[0].Rows.Count > 0) { DataRow[] content = GetCurrentArticle(dsMaterialText, lastRecordEntity, 3); if (content == null) { return; } var newsList = new List <NewsEntity>(); foreach (DataRow dr in content) { var url = dr["OriginalUrl"].ToString(); newsList.Add(new NewsEntity() { title = dr["Title"].ToString(), description = "", picurl = dr["CoverImageUrl"].ToString(), url = url }); } //推送消息 SendMessageEntity sendInfo = new SendMessageEntity(); sendInfo.msgtype = "news"; sendInfo.touser = vipEntity.OpenId; sendInfo.articles = newsList; ResultEntity msgResultObj = commonService.SendMessage(sendInfo, appID, appSecret, loggingSessionInfo); //保存发送记录 TimingPushMessageBLL timingPushMessageBll = new TimingPushMessageBLL(loggingSessionInfo); TimingPushMessageEntity timingPushMessageEntity = new TimingPushMessageEntity(); timingPushMessageEntity.ClientID = loggingSessionInfo.ClientID; timingPushMessageEntity.IsDelete = 0; timingPushMessageEntity.CreateBy = "System"; timingPushMessageEntity.CreateTime = DateTime.Now; timingPushMessageEntity.TimingPushMessageID = Guid.NewGuid(); timingPushMessageEntity.MemberID = vipEntity.VipId; timingPushMessageEntity.ObjectID = content[0]["TextId"].ToString(); timingPushMessageEntity.Status = 1; timingPushMessageBll.Create(timingPushMessageEntity); //保存最后一条记录 if (lastRecordEntity != null && lastRecordEntity.LastContentID != null) { lastRecordBll.Update(new TimingPushMessageVipLastRecordEntity { TimingPushMessageVipLastRecordID = lastRecordEntity.TimingPushMessageVipLastRecordID, ClientID = loggingSessionInfo.ClientID, CreateBy = "System", CreateTime = DateTime.Now, TimingPushMessageRuleID = timingPushMessageRuleEntity.TimingPushMessageRuleID, CSPipelineID = timingPushMessageRuleEntity.CSPipelineID, IsDelete = 0, VipID = vipEntity.VipId, LastContentID = content[0]["TextId"].ToString(), LastContentIndex = lastRecordEntity.LastContentIndex + 1, LastModelID = modelEntity.ModelId }); } else { lastRecordBll.Create(new TimingPushMessageVipLastRecordEntity { TimingPushMessageVipLastRecordID = Guid.NewGuid(), ClientID = loggingSessionInfo.ClientID, CreateBy = "System", CreateTime = DateTime.Now, TimingPushMessageRuleID = timingPushMessageRuleEntity.TimingPushMessageRuleID, CSPipelineID = timingPushMessageRuleEntity.CSPipelineID, VipID = vipEntity.VipId, IsDelete = 0, LastContentID = content[0]["TextId"].ToString(), LastContentIndex = 1, LastModelID = modelEntity.ModelId }); } } break; } } } }
/// <summary> /// 根据订单获取发货通知参数 /// </summary> /// <param name="orderId"></param> /// <param name="loggiongSessionInfo"></param> /// <returns>result = 'ok' 为成功</returns> public string GetDeliverInfoByOrderId(string orderId, LoggingSessionInfo loggiongSessionInfo) { var wxDeliverInfo = new WxDeliverInfo(); //获取交易中心的订单号 var tranCenterOrderId = this._currentDAO.GetTranCenterOrderId(orderId, loggiongSessionInfo.ClientID); var serder = new WApplicationInterfaceBLL(loggiongSessionInfo); //获取微信公众号的信息 var appEntity = serder.QueryByEntity(new WApplicationInterfaceEntity() { CustomerId = loggiongSessionInfo.ClientID }, null).FirstOrDefault(); if (appEntity != null) { var appSecret = appEntity.AppSecret; wxDeliverInfo.appid = appEntity.AppID; } else { throw new APIException("微信公众号信息为空") { ErrorCode = 121 }; } var wXPayNoticeBll = new WXPayNoticeBLL(loggiongSessionInfo); var transEntity = wXPayNoticeBll.QueryByEntity(new WXPayNoticeEntity() { OutTradeNo = tranCenterOrderId }, null).FirstOrDefault(); if (transEntity != null) { wxDeliverInfo.openid = transEntity.OpenId; wxDeliverInfo.out_trade_no = transEntity.OutTradeNo; wxDeliverInfo.transid = transEntity.TransactionId; wxDeliverInfo.deliver_status = "1"; wxDeliverInfo.deliver_msg = "ok"; } else { throw new APIException("支付通知信息为空") { ErrorCode = 122 }; } //时间戳,验签 wxDeliverInfo.deliver_timestamp = Convert.ToString((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); wxDeliverInfo.sign_method = "sha1"; //获取微信支付的专用签名 var appkey = this._currentDAO.GetAppKeyByAppId(wxDeliverInfo.appid); var tempDic = new Dictionary <string, object> { { "appid", wxDeliverInfo.appid }, { "appkey", appkey }, { "openid", wxDeliverInfo.openid }, { "transid", wxDeliverInfo.transid }, { "out_trade_no", wxDeliverInfo.out_trade_no }, { "deliver_timestamp", wxDeliverInfo.deliver_timestamp }, { "deliver_status", wxDeliverInfo.deliver_status }, { "deliver_msg", wxDeliverInfo.deliver_msg } }; //生成签名 wxDeliverInfo.app_signature = Sha1(GetParametersStr(tempDic)); var common = new CommonBLL(); //获取微信的AccessToken var accessToken = common.GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, loggiongSessionInfo).access_token; //{"errcode":0,"errmsg":"ok"} var result = common.DeliverNotify(accessToken, loggiongSessionInfo, wxDeliverInfo.ToJSON()); var data = result.DeserializeJSONTo <WxErrMessage>(); Loggers.Debug(new DebugLogInfo() { Message = "微信发货通知返回结果:" + data.ToJSON() }); return(data.errmsg); }
public bool SetEventWXPush(LEventsEntity eventInfo, string WeiXin, string OpenId, string VipId, string msgUrl, out string strError, string AuthUrl, int iRad) { try { MarketSendLogBLL logServer = new MarketSendLogBLL(this.CurrentUserInfo); Random rad = new Random(); if (eventInfo == null || eventInfo.ModelId == null || eventInfo.ModelId.Equals("")) { strError = "获取信息不全,缺少模板。"; return(false); } #region WEventUserMappingBLL eventUserMapping = new WEventUserMappingBLL(CurrentUserInfo); int eventPersonCount = 0; eventPersonCount = eventUserMapping.GetEventSignInCount(eventInfo.EventID); #endregion WApplicationInterfaceBLL wAServer = new WApplicationInterfaceBLL(this.CurrentUserInfo); var wxArray = wAServer.QueryByEntity(new WApplicationInterfaceEntity { WeiXinID = WeiXin , IsDelete = 0 , CustomerId = this.CurrentUserInfo.CurrentUser.customer_id }, null); if (wxArray == null || wxArray.Length == 0 || wxArray[0].AppID == null || wxArray[0].AppID.Equals("")) { strError = "不存在对应的微信帐号"; return(false); } else { WApplicationInterfaceEntity wxInfo = wxArray[0]; WX.CommonBLL server = new WX.CommonBLL(); JIT.CPOS.BS.Entity.WX.SendMessageEntity sendMessageInfo = new Entity.WX.SendMessageEntity(); WMaterialTextBLL wTextServer = new WMaterialTextBLL(this.CurrentUserInfo); IList <WMaterialTextEntity> textlist = new List <WMaterialTextEntity>(); textlist = wTextServer.GetMaterialTextListByModelId(eventInfo.ModelId); if (textlist != null && textlist.Count > 0 && textlist[0].TextId != null) { #region VipBLL vipServer = new VipBLL(CurrentUserInfo); VipEntity vipInfo = vipServer.GetByID(VipId); sendMessageInfo.msgtype = "news"; sendMessageInfo.touser = OpenId; List <JIT.CPOS.BS.Entity.WX.NewsEntity> newsList = new List <JIT.CPOS.BS.Entity.WX.NewsEntity>(); foreach (var info in textlist) { JIT.CPOS.BS.Entity.WX.NewsEntity newsInfo = new Entity.WX.NewsEntity(); newsInfo.title = info.Title; if (vipInfo != null && !vipInfo.VIPID.Equals("")) { newsInfo.description = info.Author.Replace("#VIPNAME#", vipInfo.VipName); } else { newsInfo.description = info.Author; } newsInfo.description = newsInfo.description.Replace("#PERSONCOUNT#", Convert.ToString(eventPersonCount)); //string url = info.OriginalUrl; //JIT.Utility.Log.Loggers.Debug(new DebugLogInfo() //{ // Message = string.Format("处理原文链接出错:{0},url:{1};Status:{2};",) //}); if (info.OriginalUrl != null && !info.OriginalUrl.Equals("") && vipInfo.Status != null && !vipInfo.Status.ToString().Equals("")) { if (vipInfo.Status.Equals(1) && info.OriginalUrl.IndexOf("Fuxing") > 0) { newsInfo.description = info.Text; } else { } } if (info.OriginalUrl.IndexOf("?") > 0) { newsInfo.url = info.OriginalUrl + "&rnd=" + rad.Next(1000, 100000) + ""; } else { string goUrl = info.OriginalUrl + "?1=1&applicationId=" + wxInfo.ApplicationId + "&eventId=" + eventInfo.EventID + "&openId=" + OpenId + "&userId=" + VipId + ""; goUrl = HttpUtility.UrlEncode(goUrl); newsInfo.url = AuthUrl + "OnlineClothing/go.htm?customerId=" + this.CurrentUserInfo.CurrentUser.customer_id + "&applicationId=" + wxInfo.ApplicationId + "&openId=" + OpenId + "&userId=" + VipId + "&backUrl=" + goUrl + ""; } //OnlineClothing/go.htm?customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "&backUrl=" + HttpUtility.UrlEncode(goUrl) + ""; newsInfo.picurl = info.CoverImageUrl; newsList.Add(newsInfo); } sendMessageInfo.articles = newsList; #endregion #region 发送日志 MarketSendLogEntity logInfo1 = new MarketSendLogEntity(); logInfo1.LogId = BaseService.NewGuidPub(); logInfo1.IsSuccess = 1; logInfo1.MarketEventId = eventInfo.EventID; logInfo1.SendTypeId = "2"; logInfo1.Phone = iRad.ToString(); if (sendMessageInfo.ToJSON().ToString().Length > 2000) { logInfo1.TemplateContent = sendMessageInfo.ToJSON().ToString().Substring(1, 1999); } else { logInfo1.TemplateContent = sendMessageInfo.ToJSON().ToString(); } logInfo1.VipId = VipId; logInfo1.WeiXinUserId = OpenId; logInfo1.CreateTime = System.DateTime.Now; logServer.Create(logInfo1); #endregion } var ResultEntity = server.SendMessage(sendMessageInfo, wxInfo.AppID, wxInfo.AppSecret, this.CurrentUserInfo, true); #region Jermyn20140110 处理复星年会的座位信息,是临时的 //FStaffBLL staffServer = new FStaffBLL(this.CurrentUserInfo); //bool bReturn = staffServer.SetStaffSeatsPush(VipId, eventInfo.EventID, out strError); //MarketSendLogEntity logInfo2 = new MarketSendLogEntity(); //logInfo2.LogId = BaseService.NewGuidPub(); //logInfo2.IsSuccess = 1; //logInfo2.MarketEventId = eventInfo.EventID; //logInfo2.SendTypeId = "2"; //logInfo2.TemplateContent = strError; //logInfo2.Phone = iRad.ToString(); //logInfo2.VipId = VipId; //logInfo2.WeiXinUserId = OpenId; //logInfo2.CreateTime = System.DateTime.Now; //logServer.Create(logInfo2); #endregion strError = "ok"; return(true); } } catch (Exception ex) { strError = ex.ToString(); return(false); } }
/// <summary> /// 创建潜在分经销商 /// </summary> /// <param name="loggingSessionInfo">loggingSessionInfo</param> /// <param name="vip_no">vip_no</param> public void CreatePrepRetailTrader(LoggingSessionInfo loggingSessionInfo, string vip_no) { VipEntity vipEntity = new VipBLL(loggingSessionInfo).GetVipDetailByVipID(vip_no); RetailTraderDAO retailTraderDao = new RetailTraderDAO(loggingSessionInfo); if (vipEntity == null || string.IsNullOrWhiteSpace(vipEntity.Col20)) { return; } /// 判断当前vip会员手机号是否存在经销记录 var entiryList = this.QueryByEntity(new RetailTraderEntity() { RetailTraderLogin = vipEntity.Phone }, null); if (entiryList != null && entiryList.Length > 0) { return; } t_unitEntity unitEntity = new t_unitBLL(loggingSessionInfo).GetMainUnit(loggingSessionInfo.ClientID); int RetailTraderCode = getMaxRetailTraderCode(loggingSessionInfo.ClientID); RetailTraderEntity pEntity = new RetailTraderEntity(); pEntity.RetailTraderID = Guid.NewGuid().ToString(); pEntity.RetailTraderType = "MultiLevelSaler"; pEntity.RetailTraderCode = RetailTraderCode + 1; pEntity.RetailTraderName = vipEntity.VipName; pEntity.RetailTraderLogin = vipEntity.Phone; pEntity.RetailTraderPass = MD5Helper.Encryption("888888"); pEntity.SalesType = ""; pEntity.RetailTraderMan = ""; pEntity.RetailTraderPhone = vipEntity.Phone; pEntity.RetailTraderAddress = ""; pEntity.CooperateType = ""; pEntity.SellUserID = ""; pEntity.UnitID = unitEntity.unit_id; pEntity.MultiLevelSalerFromVipId = vip_no; if (!string.IsNullOrEmpty(vipEntity.Col20)) { pEntity.HigheRetailTraderID = vipEntity.Col20; } pEntity.CreateTime = DateTime.Now;; pEntity.CreateBy = "sys"; pEntity.LastUpdateBy = "sys"; pEntity.LastUpdateTime = DateTime.Now; pEntity.IsDelete = 0; pEntity.CustomerId = loggingSessionInfo.ClientID; pEntity.Status = "2"; retailTraderDao.Create(pEntity); this.Create2Ap(pEntity);//ap库里的RetailTraderID和商户里的RetailTraderID是一样的 new ObjectImagesBLL(loggingSessionInfo).SaveRetailTraderHeadImg(vipEntity, pEntity); // todo CommonBLL commonBll = new CommonBLL(); string content = "您的帐号:" + pEntity.RetailTraderLogin + ",密码:888888,已经在连锁掌柜注册成功,请在地址http://app.chainclouds.com/download/chengguo/下载一起发码APP,早下载早成为经销商赚钱"; JIT.CPOS.BS.Entity.WX.SendMessageEntity messageEntity = new JIT.CPOS.BS.Entity.WX.SendMessageEntity(); messageEntity.content = content; messageEntity.touser = vipEntity.WeiXinUserId; messageEntity.msgtype = "text"; WApplicationInterfaceEntity[] wApplicationInterfaceEntities = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity { CustomerId = loggingSessionInfo.ClientID }, null); commonBll.SendMessage(messageEntity, wApplicationInterfaceEntities[0].AppID, wApplicationInterfaceEntities[0].AppSecret, loggingSessionInfo); }