Esempio n. 1
0
        /// <summary>
        /// 推送图文消息
        /// </summary>
        /// <param name="materialId"></param>
        public void GetImageText(string materialId, string WeiXin, string OpenId)
        {
            Loggers.Debug(new DebugLogInfo()
            {
                Message = string.Format("中欧扫描--关注materialId 进入 materialId:{0},WeiXin:{1},OpenId:{2}", materialId, WeiXin, OpenId)
            });
            try
            {
                var dsMaterialText = new WMaterialTextDAO(loggingSessionInfo).GetMaterialTextByID(materialId);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("中欧扫描--关注loggingSessionInfo 进入 loggingSessionInfo:{0}", loggingSessionInfo.CurrentUser.customer_id)
                });
                if (dsMaterialText != null && dsMaterialText.Tables.Count > 0 && dsMaterialText.Tables[0].Rows.Count > 0)
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("中欧扫描--关注materialId 进入 dsMaterialText:")
                    });
                    var newsList = new List <NewsEntity>();

                    foreach (DataRow dr in dsMaterialText.Tables[0].Rows)
                    {
                        newsList.Add(new NewsEntity()
                        {
                            title       = dr["Title"].ToString(),
                            description = dr["Author"].ToString(),
                            picurl      = dr["CoverImageUrl"].ToString(),
                            url         = dr["OriginalUrl"].ToString()
                        });
                    }
                    JIT.CPOS.BS.BLL.WX.CommonBLL commonService = new WX.CommonBLL();
                    SendMessageEntity            sendInfo      = new SendMessageEntity();
                    sendInfo.msgtype  = "news";
                    sendInfo.touser   = OpenId;
                    sendInfo.articles = newsList;
                    WApplicationInterfaceBLL waServer = new WApplicationInterfaceBLL(loggingSessionInfo);
                    var waObj = waServer.QueryByEntity(new WApplicationInterfaceEntity
                    {
                        WeiXinID = WeiXin
                    }, null);
                    if (waObj == null || waObj.Length == 0 || waObj[0] == null)
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("中欧扫描--关注materialId 进入 waObj为空:}")
                        });
                    }
                    else
                    {
                        string appID     = string.Empty;
                        string appSecret = string.Empty;
                        appID     = waObj[0].AppID;
                        appSecret = waObj[0].AppSecret;
                        JIT.CPOS.BS.Entity.WX.ResultEntity resultInfo = new JIT.CPOS.BS.Entity.WX.ResultEntity();
                        resultInfo = commonService.SendMessage(sendInfo, appID, appSecret, loggingSessionInfo);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("中欧扫描--关注materialId 进入 waObj:appID:{0},appSecret {1}", appID, appSecret)
                        });
                    }
                }
            }
            catch (Exception ex) {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("中欧扫描--关注GetImageText 进入 错误:{0}", ex.ToString())
                });
            }
        }
Esempio n. 2
0
        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);
            }
        }