public void GetKeyByApp() { WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(loggingSessionInfo); WApplicationInterfaceEntity info = server.GetByID(applicationId); if (info == null) { Response.Write("不存在对应的微信标识"); } else { strAppId = info.AppID; strAppSecret = info.AppSecret; if (info.AuthUrl == null || info.AuthUrl.Equals("")) { } else { //qianzhi 2014-03-17 if (!info.AuthUrl.EndsWith("/")) { info.AuthUrl = info.AuthUrl.Insert(info.AuthUrl.Length, "/"); } strRedirectUri = info.AuthUrl + "WXOAuth/AuthCodeReques.aspx"; } } }
/// <summary> /// 获取jsapi_ticket /// </summary> /// <returns></returns> public string getJsApiConfig(string pRequest) { var rp = pRequest.DeserializeJSONTo <APIRequest <WeiXinConfigRq> >(); if (string.IsNullOrEmpty(rp.OpenID))//OpenID为空立刻返回空数据,让前端跳转高级auth认证 { return(new SuccessResponse <IAPIResponseData>(new XeiXinJsApiConfig()).ToJSON()); } var loggingSessionInfo = Default.GetBSLoggingSession(rp.CustomerID, "1"); var appService = new WApplicationInterfaceBLL(loggingSessionInfo); var wxUserInfoBLL = new WXUserInfoBLL(loggingSessionInfo); var vipService = new VipBLL(loggingSessionInfo); var appEntity = new WApplicationInterfaceEntity(); var vipEntitys = vipService.QueryByEntity(new VipEntity { WeiXinUserId = rp.OpenID, ClientID = loggingSessionInfo.ClientID }, null); if (vipEntitys != null && vipEntitys.Length > 0) { appEntity = appService.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = vipEntitys[0].WeiXin, CustomerId = rp.CustomerID }, null).FirstOrDefault(); } else { //优先从支持多号运营的表中取 var wxUserInfo = wxUserInfoBLL.QueryByEntity(new WXUserInfoEntity() { CustomerID = loggingSessionInfo.ClientID, WeiXinUserID = rp.OpenID }, null).FirstOrDefault(); if (wxUserInfo != null) { appEntity = appService.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = wxUserInfo.WeiXin, CustomerId = rp.CustomerID }, null).FirstOrDefault(); } } //返回空数据,让前端跳转高级auth认证 if (string.IsNullOrEmpty(appEntity.AppID)) { return(new SuccessResponse <IAPIResponseData>(new XeiXinJsApiConfig()).ToJSON()); } string timestamp = ((long)((DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds)).ToString(); string nonceStr = Guid.NewGuid().ToString("N").Substring(0, 16); XeiXinJsApiConfig config = new XeiXinJsApiConfig() { debug = rp.Parameters.debug, appId = appEntity.AppID, timestamp = timestamp, nonceStr = nonceStr, signature = this.getJsApiSignature(this.getJsApiTicket(rp.CustomerID, appEntity.AppID, appEntity.AppSecret), nonceStr, timestamp, rp.Parameters.url), jsApiList = new List <string>() }; return(new SuccessResponse <IAPIResponseData>(config).ToJSON()); }
/// <summary> /// 取消授权 /// </summary> /// <param name="appid"></param> /// <param name="clientid"></param> /// <returns></returns> public static bool UnauthWechatApp(string appid) { var clientId = "eb17cc2569c74ab7888b1f403972d37d";//测试用 var loggingSessionInfo = Default.GetBSLoggingSession(clientId, "open"); var waiBll = new WApplicationInterfaceBLL(loggingSessionInfo); var wmenuBll = new WMenuBLL(loggingSessionInfo); var userInfo = loggingSessionInfo; userInfo.CurrentLoggingManager.Connection_String = WebConfigurationManager.AppSettings["APConn"]; var customerWxMappingBll = new TCustomerWeiXinMappingBLL(userInfo); var customerId = customerWxMappingBll.GetCustomerIdByAppId(appid); var waiEntitys = new WApplicationInterfaceEntity[] { }; var waiEntity = new WApplicationInterfaceEntity(); var component_Appid = WebConfigurationManager.AppSettings["Component_Appid"]; waiEntitys = waiBll.QueryByEntity(new WApplicationInterfaceEntity { AppID = appid, OpenOAuthAppid = component_Appid, CustomerId = customerId, IsDelete = 0 }, null); if (waiEntitys != null && waiEntitys.Length > 0) { waiEntity = waiEntitys.FirstOrDefault(); //waiEntity.OpenOAuthAppid = null;//置空 //waiBll.Update(waiEntity); waiBll.Delete(waiEntity); //查询参数 List <IWhereCondition> complexCondition = new List <IWhereCondition> { }; complexCondition.Add(new EqualsCondition() { FieldName = "WeiXinID", Value = waiEntity.WeiXinID }); var tempList = wmenuBll.PagedQuery(complexCondition.ToArray(), null, 10, 1); if (tempList.Entities.Length > 0) { foreach (var item in tempList.Entities) { wmenuBll.Delete(item); } } //var wmenuEntitys = wmenuBll.QueryByEntity(new WMenuEntity { WeiXinID = waiEntity.WeiXinID }, null); //if (wmenuEntitys != null && wmenuEntitys.Length > 0) //{ // foreach (var item in wmenuEntitys) // { // wmenuBll.Delete(item); // } //} } return(true); }
public void GetKeyByApp() { WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(loggingSessionInfo); WApplicationInterfaceEntity info = server.GetByID(applicationId); if (info == null) { Response.Write("不存在对应的微信标识"); } else { strAppId = info.AppID; strAppSecret = info.AppSecret; } }
/// <summary> /// Web列表获取 /// </summary> public IList <WApplicationInterfaceEntity> GetWebWApplicationInterface(WApplicationInterfaceEntity entity, int Page, int PageSize) { if (PageSize <= 0) { PageSize = 15; } IList <WApplicationInterfaceEntity> list = new List <WApplicationInterfaceEntity>(); DataSet ds = new DataSet(); ds = _currentDAO.GetWebWApplicationInterface(entity, Page, PageSize); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { list = DataTableToObject.ConvertToList <WApplicationInterfaceEntity>(ds.Tables[0]); } return(list); }
public void GetKeyByApp() { WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(loggingSessionInfo); WApplicationInterfaceEntity info = server.GetByID(applicationId); if (info == null) { Response.Write("不存在对应的微信标识"); } else { strAppId = info.AppID; strAppSecret = info.AppSecret; Loggers.Debug(new DebugLogInfo() { Message = string.Format("泸州老窖:APPID: {0},AppSecret:{1}", strAppId, strAppSecret) }); } }
public void GetKey() { WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(loggingSessionInfo); WApplicationInterfaceEntity info = null; if (string.IsNullOrEmpty(applicationId)) { info = server.Query( new IWhereCondition[] { new EqualsCondition() { FieldName = "CustomerId", Value = customerId } } , null)[0]; } else { info = server.GetByID(applicationId); } if (info == null) { Response.Write("不存在对应的微信标识"); Response.End(); } else { applicationId = info.ApplicationId; strAppId = info.AppID; strAppSecret = info.AppSecret; if (info.AuthUrl == null || info.AuthUrl.Equals("")) { } else { strRedirectUri = info.AuthUrl + "WXOAuth/AuthCodeReques.aspx"; } } }
public void GetKeyByApp() { WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(loggingSessionInfo); WApplicationInterfaceEntity info = server.GetByID(applicationId); if (info == null) { Response.Write("不存在对应的微信标识,请联系管理员尽快处理."); Response.End(); } else { strAppId = info.AppID; strAppSecret = info.AppSecret; if (info.AuthUrl == null || info.AuthUrl.Equals("")) { } else { strRedirectUri = info.AuthUrl + "OAuthWX.aspx"; } } }
/// <summary> /// 推广分享设置 /// </summary> /// <param name="para"></param> /// <param name="bllSpreadSetting"></param> /// <param name="imageBll"></param> public void SaveSpreadSetting(SetCTWEventRP para, T_CTW_SpreadSettingBLL bllSpreadSetting, ObjectImagesBLL imageBll, WApplicationInterfaceEntity wapentity, out string QRCodeUrl) { QRCodeUrl = string.Empty; string QRCodeId = string.Empty; if (!string.IsNullOrEmpty(para.CTWEventId)) { bllSpreadSetting.DeleteByCTWEventID(para.CTWEventId); } foreach (var sItem in para.SpreadSettingList) { var bgimageEntity = new ObjectImagesEntity(); bgimageEntity.ImageURL = sItem.BGImageUrl; bgimageEntity.ObjectId = ""; bgimageEntity.CreateBy = loggingSessionInfo.UserID; bgimageEntity.IsDelete = 0; bgimageEntity.CustomerId = loggingSessionInfo.ClientID; bgimageEntity.ImageId = Guid.NewGuid().ToString(); imageBll.Create(bgimageEntity); if (sItem.SpreadType == "Focus") { bool IsSuccess = true; CreateFocusQRCode(para, sItem.LogoUrl, wapentity, out QRCodeUrl, out QRCodeId, out IsSuccess); if (!IsSuccess) { throw new APIException(111, "关注二维码生成失败!请重新提交"); } //imageEntity = new ObjectImagesEntity(); //imageEntity.ImageURL = QRCodeUrl; //imageEntity.ObjectId = ""; //imageEntity.CreateBy = loggingSessionInfo.UserID; //imageEntity.IsDelete = 0; //imageEntity.CustomerId = loggingSessionInfo.ClientID; //imageEntity.ImageId = Guid.NewGuid().ToString(); //imageBll.Create(imageEntity); } entitySpreadSetting = new T_CTW_SpreadSettingEntity() { SpreadType = sItem.SpreadType, Title = sItem.Title, ImageId = bgimageEntity.ImageId, Summary = sItem.Summary, PromptText = sItem.PromptText, LeadPageQRCodeImageId = QRCodeId, LeadPageSharePromptText = sItem.LeadPageSharePromptText, LeadPageFocusPromptText = sItem.LeadPageFocusPromptText, LeadPageRegPromptText = sItem.LeadPageRegPromptText, LogoUrl = sItem.LogoUrl, CustomerId = loggingSessionInfo.ClientID, CTWEventId = new Guid(strCTWEventId) }; bllSpreadSetting.Create(entitySpreadSetting); } }
public void Update(WApplicationInterfaceEntity pEntity, bool pIsUpdateNullField, IDbTransaction pTran) { _currentDAO.Update(pEntity, pIsUpdateNullField, pTran); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Update(WApplicationInterfaceEntity pEntity, IDbTransaction pTran) { Update(pEntity, true, pTran); }
/// <summary> /// 在事务内创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Create(WApplicationInterfaceEntity pEntity, IDbTransaction pTran) { _currentDAO.Create(pEntity, pTran); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(WApplicationInterfaceEntity pEntity) { _currentDAO.Create(pEntity); }
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="para"></param> /// <param name="wapentity"></param> /// <param name="strQRCode"></param> /// <param name="QRCodeUrl"></param> public void CreateFocusQRCode(SetCTWEventRP para, string strLogoUrl, WApplicationInterfaceEntity wapentity, out string QRCodeUrl, out string QRCodeId, out bool IsSuccess) { QRCodeUrl = string.Empty; QRCodeId = string.Empty; var wqrCodeManagerEntity = new WQRCodeManagerBLL(loggingSessionInfo).QueryByEntity(new WQRCodeManagerEntity() { ObjectId = strCTWEventId }, null).FirstOrDefault(); //#region 生成二维码 var wqrentity = new WQRCodeTypeBLL(loggingSessionInfo).QueryByEntity( new WQRCodeTypeEntity { TypeCode = "CreativeCode" } , null).FirstOrDefault(); var wxCode = CretaeWxCode(); IsSuccess = true; if (string.IsNullOrEmpty(wxCode.ImageUrl)) { IsSuccess = false; } QRCodeUrl = wxCode.ImageUrl; if (!string.IsNullOrEmpty(QRCodeUrl)) { if (!string.IsNullOrEmpty(strLogoUrl)) //如果有值则生成二维码中间带图 { string targetPath = HttpContext.Current.Server.MapPath("/QRCodeImage/"); ////二维码中奖加图片 string currentDomain = "http://" + HttpContext.Current.Request.Url.Host; //当前项目域名 string strFileNmae = QRCodeUrl.Substring(QRCodeUrl.LastIndexOf("/") + 1); string strQRCodeFilePath = targetPath + strFileNmae; string logoImage = "~" + strLogoUrl.Substring(currentDomain.Length); System.IO.MemoryStream MStream1 = new System.IO.MemoryStream(); Utils.CombinImage(QRCodeUrl, HttpContext.Current.Server.MapPath(logoImage)).Save(MStream1, System.Drawing.Imaging.ImageFormat.Png); Image ii = Image.FromStream(MStream1); ii.Save(strQRCodeFilePath, System.Drawing.Imaging.ImageFormat.Png); MStream1.Dispose(); QRCodeUrl = currentDomain + "/QRCodeImage/" + strFileNmae; } var WQRCodeManagerbll = new WQRCodeManagerBLL(loggingSessionInfo); if (wqrCodeManagerEntity == null) { wqrCodeManagerEntity = new WQRCodeManagerEntity() { QRCodeId = Guid.NewGuid(), QRCode = wxCode.MaxWQRCod.ToString(), QRCodeTypeId = wqrentity.QRCodeTypeId, IsUse = 1, ObjectId = strCTWEventId, Remark = "CTW", CreateBy = loggingSessionInfo.UserID, ApplicationId = wapentity.ApplicationId, IsDelete = 0, ImageUrl = QRCodeUrl, CustomerId = loggingSessionInfo.ClientID }; WQRCodeManagerbll.Create(wqrCodeManagerEntity); } else { wqrCodeManagerEntity.ImageUrl = QRCodeUrl; WQRCodeManagerbll.Update(wqrCodeManagerEntity); } QRCodeId = wqrCodeManagerEntity.QRCodeId.ToString(); } }
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; } } } }
//设置请求参数 private RequestParams SetRequestParams(string postStr, string _TrueEncodingAESKey, HttpContext httpContext, LoggingSessionInfo loggingSessionInfo, WApplicationInterfaceEntity wAppEntity) { XmlDocument doc = new XmlDocument(); doc.LoadXml(postStr); XmlNodeList list = doc.GetElementsByTagName("xml"); XmlNode xn = list[0]; string openID = xn.SelectSingleNode("//FromUserName").InnerText; //发送方帐号(一个OpenID) string weixinID = xn.SelectSingleNode("//ToUserName").InnerText; //开发者微信号 string msgType = xn.SelectSingleNode("//MsgType").InnerText.ToLower(); //消息类型(text, image, location, link, event) BaseService.WriteLogWeixin("微信平台推送的消息: " + postStr); BaseService.WriteLogWeixin("FromUserName(发送方帐号): " + openID); BaseService.WriteLogWeixin("ToUserName(开发者微信号): " + weixinID); BaseService.WriteLogWeixin("MsgType(消息类型): " + msgType); var timestamp = httpContext.Request["timestamp"] == null ? "" : httpContext.Request["timestamp"].ToString(); var nonce = httpContext.Request["nonce"] == null ? "" : httpContext.Request["nonce"].ToString(); var requestParams = new RequestParams() { OpenId = openID, WeixinId = weixinID, MsgType = msgType, XmlNode = xn, LoggingSessionInfo = loggingSessionInfo, //BaseService.GetWeixinLoggingSession(weixinID), TrueEncodingAESKey = _TrueEncodingAESKey, Token = string.IsNullOrEmpty(wAppEntity.OpenOAuthAppid) ? wAppEntity.Token : wAppEntity.OpenToken, //如果授权给公众平台了,就用公众平台的token AppID = string.IsNullOrEmpty(wAppEntity.OpenOAuthAppid) ? wAppEntity.AppID : wAppEntity.OpenAppID, EncryptType = (int)wAppEntity.EncryptType, Timestamp = timestamp, Nonce = nonce }; return(requestParams); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> public void Update(WApplicationInterfaceEntity pEntity) { Update(pEntity, true); }
const int ERROR_LOAD_WRONG = 302; //打开出错 protected override GetSetoffToolDetailRD ProcessRequest(APIRequest <GetSetoffToolDetailRP> pRequest) { string content = string.Empty; string customerId = string.Empty; GetSetoffToolDetailRD setoffToolDetailRD = new GetSetoffToolDetailRD(); var para = pRequest.Parameters; customerId = CurrentUserInfo.CurrentUser.customer_id; try { var imageUrl = string.Empty; Random ro = new Random(); var iUp = 100000000; var iDown = 50000000; var rpVipDCode = 0; //临时二维码 var iResult = ro.Next(iDown, iUp); //随机数 var userQrCodeBll = new WQRCodeManagerBLL(CurrentUserInfo); var imgBll = new ObjectImagesBLL(CurrentUserInfo); var setOffPosterBLL = new SetoffPosterBLL(CurrentUserInfo); var SetoffToolUserViewBLL = new SetoffToolUserViewBLL(CurrentUserInfo); var SetoffToolsBll = new SetoffToolsBLL(CurrentUserInfo); var SetOffPosterInfo = setOffPosterBLL.QueryByEntity(new SetoffPosterEntity() { SetoffPosterID = new Guid(para.ObjectId) }, null); //获取集客海报信息 var setoffEventBLL = new SetoffEventBLL(CurrentUserInfo); var setoffEventInfo = setoffEventBLL.QueryByEntity(new SetoffEventEntity() { Status = "10", SetoffType = 1, CustomerId = customerId }, null); //var SetoffToolsInfo = SetoffToolsBll.QueryByEntity(new SetoffToolsEntity() { ObjectId = para.ObjectId, Status = "10", ToolType = para.ToolType, SetoffEventID = setoffEventInfo[0].SetoffEventID }, null);//获取工具信息 //VipDcode=9生成永久二维码 if (para.VipDCode == 9) { //根据分享人ID和对象ID获取永久二维码信息 var userQrCode = userQrCodeBll.QueryByEntity(new WQRCodeManagerEntity() { ObjectId = para.ObjectId }, null); if (userQrCode != null && userQrCode.Length > 0) { if (para.ToolType == "Coupon")//如果类型为优惠券则返回二维码 { setoffToolDetailRD.ToolType = para.ToolType; } if (para.ToolType == "SetoffPoster")//如果为集客海报则返回背景图和二维码 { if (SetOffPosterInfo != null) { var backImgInfo = imgBll.QueryByEntity(new ObjectImagesEntity() { ObjectId = SetOffPosterInfo[0].ImageId }, null); setoffToolDetailRD.ToolType = para.ToolType; setoffToolDetailRD.imageUrl = userQrCode[0].ImageUrl; setoffToolDetailRD.paraTemp = userQrCode[0].QRCode; setoffToolDetailRD.backImgUrl = backImgInfo[0].ImageURL; } } setoffToolDetailRD.imageUrl = userQrCode[0].ImageUrl; setoffToolDetailRD.paraTemp = userQrCode[0].QRCode; return(setoffToolDetailRD); } //获取当前二维码 最大值 iResult = new WQRCodeManagerBLL(CurrentUserInfo).GetMaxWQRCod() + 1; rpVipDCode = 1; } #region 获取微信帐号 var server = new WApplicationInterfaceBLL(CurrentUserInfo); var wxObj = new WApplicationInterfaceEntity(); wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { CustomerId = customerId }, null).FirstOrDefault(); if (wxObj == null) { throw new APIException("不存在对应的微信帐号.") { ErrorCode = ERROR_NULL_WXOBJ }; } else { var commonServer = new CommonBLL(); //rpVipDCode 二维码类型 0: 临时二维码 1:永久二维码 imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID, wxObj.AppSecret, rpVipDCode.ToString(""), iResult, CurrentUserInfo);//iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000 //供本地测试时使用 "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA=="; } #endregion if (para.VipDCode == 9 && !string.IsNullOrEmpty(imageUrl)) //永久二维码 { #region 创建店员永久二维码匹配表 var userQrTypeBll = new WQRCodeTypeBLL(CurrentUserInfo); string pTypeCode = string.Empty; if (para.ToolType.ToLower() == "coupon") { pTypeCode = "CouponQrCode"; } if (para.ToolType.ToLower() == "setoffposter") { pTypeCode = "SetoffPosterQrCode"; } if (para.ToolType.ToLower() == "superretail") { pTypeCode = "SuperRetailQrCode"; } var userQrType = userQrTypeBll.QueryByEntity(new WQRCodeTypeEntity() { TypeCode = pTypeCode }, null); //"SuperRetailQrCode=超级分销商二维码" if (userQrType != null && userQrType.Length > 0) { var userQrcodeBll = new WQRCodeManagerBLL(CurrentUserInfo); var userQrCode = new WQRCodeManagerEntity(); userQrCode.QRCode = iResult.ToString();//记录传过去的二维码场景值 userQrCode.QRCodeTypeId = userQrType[0].QRCodeTypeId; userQrCode.IsUse = 1; userQrCode.CustomerId = customerId; userQrCode.ImageUrl = imageUrl; userQrCode.ApplicationId = wxObj.ApplicationId; //objectId 为集客海报ID或者优惠券ID userQrCode.ObjectId = para.ObjectId; userQrcodeBll.Create(userQrCode); } #endregion } else { #region 创建临时匹配表 VipDCodeBLL vipDCodeServer = new VipDCodeBLL(CurrentUserInfo); VipDCodeEntity info = new VipDCodeEntity(); info.DCodeId = iResult.ToString();//记录传过去的二维码场景值****(保存到数据库时没加空格) info.CustomerId = customerId; VipBLL vipBll = new VipBLL(CurrentUserInfo); info.UnitId = ""; info.Status = "0"; info.IsReturn = 0; info.DCodeType = para.VipDCode; info.CreateBy = CurrentUserInfo.UserID; info.ImageUrl = imageUrl; info.VipId = ""; info.ObjectId = para.ObjectId; //工具对象ID(优惠券或集客海报对象ID) info.OwnerUserId = para.ShareVipId; //分享人ID vipDCodeServer.Create(info); #endregion } int flag = 0;//定义是否需要新增打开数据,0=不需要新增,1=需要新增 var UserViewData = SetoffToolUserViewBLL.QueryByEntity(new SetoffToolUserViewEntity() { ObjectId = para.ObjectId, UserID = CurrentUserInfo.UserID }, null); if (!string.IsNullOrEmpty(para.SetoffToolID)) { UserViewData = SetoffToolUserViewBLL.QueryByEntity(new SetoffToolUserViewEntity() { ObjectId = para.ObjectId, UserID = CurrentUserInfo.UserID, SetoffToolID = new Guid(para.SetoffToolID) }, null); } if (UserViewData.Length == 0 && !string.IsNullOrEmpty(para.SetoffToolID) && para.PlatformType != "3") { flag = 1; //当为1时进行增加打开工具记录 } if (para.ToolType == "Coupon") //如果类型为优惠券则返回二维码 { #region 用户领优惠券过程 var CouponTypeBLL = new CouponTypeBLL(CurrentUserInfo); var couponBLL = new CouponBLL(CurrentUserInfo); var CouponSourceBLL = new CouponSourceBLL(CurrentUserInfo); var VipCouponMappingBLL = new VipCouponMappingBLL(CurrentUserInfo); int?SurplusCount = 0; //先获得剩余张数 int hasCouponCount = 0; //已领张数 如果>0表示已领取过就不让他领,=0就领取 var couponTypeInfo = CouponTypeBLL.QueryByEntity(new CouponTypeEntity() { CouponTypeID = new Guid(para.ObjectId) }, null); if (couponTypeInfo != null) { string couponIsVocher = string.Empty; if (couponTypeInfo[0].IsVoucher == null) { SurplusCount = couponTypeInfo[0].IssuedQty - 0; } else { SurplusCount = couponTypeInfo[0].IssuedQty - couponTypeInfo[0].IsVoucher; } if (SurplusCount != 0 && para.ShareVipId != null && para.ShareVipId != "")// 通过列表进详细自己不能领券 { //当剩余数量不为0时,进行下一步判断是否存在已领券的信息 hasCouponCount = VipCouponMappingBLL.GetReceiveCouponCount(CurrentUserInfo.UserID, para.ObjectId, "Share"); if (hasCouponCount == 0)//如果等于零,开始领券流程 { //关联优惠券让用户领券 var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL(); try { //执行领取操作 redisVipMappingCouponBLL.InsertDataBase(CurrentUserInfo.CurrentUser.customer_id, CurrentUserInfo.UserID, para.SetoffToolID, "Share", new CC_Coupon() { CustomerId = CurrentUserInfo.CurrentUser.customer_id, CouponTypeId = para.ObjectId }); setoffToolDetailRD.Name = couponTypeInfo[0].CouponTypeName + ",已飞入您的账户"; } catch (Exception ex) { setoffToolDetailRD.Name = "很遗憾此次优惠券" + couponTypeInfo[0].CouponTypeName + "的分享已失效,下次请及时领取."; } } } else { //如果剩余数量为0时,给出已领完提示 if (para.ShareVipId != null && para.ShareVipId != "") { setoffToolDetailRD.Name = "很遗憾您来迟一步优惠券" + couponTypeInfo[0].CouponTypeName + "已被领完."; //throw new APIException("很遗憾您来迟一步券已被领完.") { ErrorCode = ERROR_LOAD_WRONG }; } } if (setoffToolDetailRD.Name == null || setoffToolDetailRD.Name == "") { setoffToolDetailRD.Name = couponTypeInfo[0].CouponTypeName; } setoffToolDetailRD.StartTime = couponTypeInfo[0].BeginTime == null?Convert.ToDateTime(couponTypeInfo[0].CreateTime).ToString("yyyy-MM-dd") : Convert.ToDateTime(couponTypeInfo[0].BeginTime).ToString("yyyy-MM-dd"); setoffToolDetailRD.EndTime = couponTypeInfo[0].EndTime == null ? "" : Convert.ToDateTime(couponTypeInfo[0].EndTime).ToString("yyyy-MM-dd"); setoffToolDetailRD.ServiceLife = couponTypeInfo[0].ServiceLife.ToString(); } #endregion setoffToolDetailRD.ToolType = para.ToolType; //返回工具类别 setoffToolDetailRD.imageUrl = imageUrl; //返回临时二维码 setoffToolDetailRD.paraTemp = iResult.ToString().Insert(4, " "); //加空格,加空格有什么作用? } if (para.ToolType == "SetoffPoster") //如果为集客海报则返回背景图和二维码 { if (SetOffPosterInfo != null && SetOffPosterInfo.Length > 0) { var backImgInfo = imgBll.QueryByEntity(new ObjectImagesEntity() { ImageId = SetOffPosterInfo[0].ImageId }, null); setoffToolDetailRD.ToolType = para.ToolType; setoffToolDetailRD.imageUrl = imageUrl; setoffToolDetailRD.paraTemp = iResult.ToString().Insert(4, " "); //加空格,加空格有什么作用? setoffToolDetailRD.backImgUrl = backImgInfo[0].ImageURL; setoffToolDetailRD.Name = SetOffPosterInfo[0].Name; } } if (flag == 1)//当为1是需进行打开工具的记录 { var SetoffToolUserView = new SetoffToolUserViewEntity(); SetoffToolUserView.SetoffToolUserViewID = Guid.NewGuid(); SetoffToolUserView.SetoffEventID = setoffEventInfo[0].SetoffEventID; SetoffToolUserView.SetoffToolID = new Guid(para.SetoffToolID); SetoffToolUserView.ToolType = para.ToolType; SetoffToolUserView.ObjectId = para.ObjectId; SetoffToolUserView.NoticePlatformType = 1; SetoffToolUserView.UserID = CurrentUserInfo.UserID; SetoffToolUserView.IsOpen = 1; SetoffToolUserView.OpenTime = System.DateTime.Now; SetoffToolUserView.CustomerId = customerId; SetoffToolUserView.CreateTime = System.DateTime.Now; SetoffToolUserView.CreateBy = CurrentUserInfo.UserID; SetoffToolUserView.LastUpdateTime = System.DateTime.Now; SetoffToolUserView.LastUpdateBy = CurrentUserInfo.UserID; SetoffToolUserView.IsDelete = 0; SetoffToolUserViewBLL.Create(SetoffToolUserView); } } catch (Exception ex) { throw new APIException(ex.Message) { ErrorCode = ERROR_CODES.DEFAULT_ERROR }; } return(setoffToolDetailRD); }
protected override DownloadQRCodeRD ProcessRequest(DTO.Base.APIRequest <DownloadQRCodeRP> pRequest) { string content = string.Empty; string customerId = string.Empty; var RD = new DownloadQRCodeRD(); try { #region 解析传入参数 //解析请求字符串 var RP = pRequest.Parameters; //判断客户ID是否传递 customerId = CurrentUserInfo.CurrentUser.customer_id; #endregion var imageUrl = string.Empty; Random ro = new Random(); var iUp = 100000000; var iDown = 50000000; if (string.IsNullOrEmpty(RP.VipDCode.ToString()) || RP.VipDCode == 0) { throw new APIException("VipDCode参数不能为空"); } var rpVipDCode = 0; //临时二维码 var iResult = ro.Next(iDown, iUp); //随机数 if (RP.VipDCode == 9) //永久二维码 { var userQRCodeBll = new WQRCodeManagerBLL(CurrentUserInfo); var marketEventBll = new MarketEventBLL(CurrentUserInfo); var marketEventEntity = marketEventBll.QueryByEntity(new MarketEventEntity() { EventCode = "CA00002433", CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault(); var userQRCode = userQRCodeBll.QueryByEntity(new WQRCodeManagerEntity() { ObjectId = marketEventEntity.MarketEventID, CustomerId = CurrentUserInfo.ClientID }, null); // if (userQRCode != null && userQRCode.Length > 0) { RD.imageUrl = userQRCode[0].ImageUrl; return(RD); } //获取当前二维码 最大值 iResult = new WQRCodeManagerBLL(CurrentUserInfo).GetMaxWQRCod() + 1; rpVipDCode = 1; //永久 #region 获取微信帐号 //门店关联的公众号 var tueBll = new TUnitExpandBLL(CurrentUserInfo); var tueEntity = new TUnitExpandEntity(); if (!string.IsNullOrEmpty(CurrentUserInfo.CurrentUserRole.UnitId)) { tueEntity = tueBll.QueryByEntity(new TUnitExpandEntity() { UnitId = CurrentUserInfo.CurrentUserRole.UnitId }, null).FirstOrDefault(); } var server = new WApplicationInterfaceBLL(CurrentUserInfo); var wxObj = new WApplicationInterfaceEntity(); if (tueEntity != null && !string.IsNullOrEmpty(tueEntity.Field1)) { wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { AppID = tueEntity.Field1, CustomerId = customerId }, null).FirstOrDefault(); } else { wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { CustomerId = customerId }, null).FirstOrDefault(); } if (wxObj == null) { throw new APIException("没有对应公众号"); } else { var commonServer = new CommonBLL(); imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID , wxObj.AppSecret , rpVipDCode.ToString("") //二维码类型 0: 临时二维码 1:永久二维码 , iResult, CurrentUserInfo); //iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000 if (imageUrl != null && !imageUrl.Equals("")) { CPOS.Common.DownloadImage downloadServer = new DownloadImage(); string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"]; imageUrl = downloadServer.DownloadFile(imageUrl, downloadImageUrl); //如果名称不为空,就把图片放在一定的背景下面 //if (!string.IsNullOrEmpty(RP.Parameters.RetailTraderName)) //{ // string apiDomain = ConfigurationManager.AppSettings["website_url"]; // imageUrl = CombinImage(apiDomain + @"/HeadImage/qrcodeBack.jpg", imageUrl, RP.Parameters.RetailTraderName + "合作二维码"); //} } } #endregion if (!string.IsNullOrEmpty(imageUrl)) //永久二维码 { #region 创建店员永久二维码匹配表 var userQrTypeBll = new WQRCodeTypeBLL(CurrentUserInfo); var userQrType = userQrTypeBll.QueryByEntity(new WQRCodeTypeEntity() { TypeName = "签到" }, null); //"UserQrCode" if (userQrType != null && userQrType.Length > 0) { var userQrCodeBll = new WQRCodeManagerBLL(CurrentUserInfo); var userQrCode = new WQRCodeManagerEntity(); userQrCode.QRCode = iResult.ToString();//记录传过去的二维码场景值 userQrCode.QRCodeTypeId = userQrType[0].QRCodeTypeId; userQrCode.IsUse = 1; userQrCode.CustomerId = CurrentUserInfo.CurrentUser.customer_id; userQrCode.ImageUrl = imageUrl; userQrCode.ApplicationId = wxObj.ApplicationId; //objectId 为店员ID userQrCode.ObjectId = marketEventEntity.MarketEventID; userQrCodeBll.Create(userQrCode); } #endregion } } RD.imageUrl = imageUrl; } catch { throw new APIException("生成二维码错误"); } return(RD); }
public HttpResponseMessage QRCode(string UnitId, string ObjectID) { Loggers.Debug(new DebugLogInfo() { Message = $"[api/Vip/QRCode]接口,参数:\"UnitId:{UnitId}&ObjectID:{ObjectID}\"" }); try { string customerId = ConfigurationManager.AppSettings["CustomerId"].Trim(); var loggingSessionInfo = Default.GetLoggingSession(customerId, ObjectID); loggingSessionInfo.Conn = ConfigurationManager.AppSettings["Conn"].Trim(); var imageUrl = string.Empty; Random ro = new Random(); var iUp = 100000000; var iDown = 50000000; var rpVipDCode = 0; //临时二维码 var iResult = ro.Next(iDown, iUp); //随机数 string objectid = ObjectID; #region 获取微信帐号 //门店关联的公众号 var tuBll = new t_unitBLL(loggingSessionInfo); var tuEntity = new t_unitEntity(); if (!string.IsNullOrEmpty(UnitId)) { tuEntity = tuBll.QueryByEntity(new t_unitEntity() { unit_id = UnitId }, null) .FirstOrDefault(); } var server = new WApplicationInterfaceBLL(loggingSessionInfo); var wxObj = new WApplicationInterfaceEntity(); if (tuEntity != null && !string.IsNullOrEmpty(tuEntity.weiXinId)) { wxObj = server.QueryByEntity( new WApplicationInterfaceEntity { WeiXinID = tuEntity.weiXinId, CustomerId = customerId }, null).FirstOrDefault(); } else { wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { CustomerId = customerId }, null) .FirstOrDefault(); } if (wxObj == null) { throw new APIException("不存在对应的微信帐号") { ErrorCode = 302 }; } else { var commonServer = new CommonBLL(); imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID , wxObj.AppSecret , rpVipDCode.ToString("") //二维码类型 0: 临时二维码 1:永久二维码 , iResult, loggingSessionInfo); //iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000 //"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA=="; //"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA=="; if (imageUrl != null && !imageUrl.Equals("")) { DownloadImage downloadServer = new DownloadImage(); string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"]; imageUrl = downloadServer.DownloadFile(imageUrl, downloadImageUrl); } } #endregion #region 创建临时匹配表 VipDCodeBLL vipDCodeServer = new VipDCodeBLL(loggingSessionInfo); VipDCodeEntity info = new VipDCodeEntity(); info.DCodeId = iResult.ToString(); //记录传过去的二维码场景值****(保存到数据库时没加空格) info.CustomerId = customerId; info.UnitId = UnitId; //获取会集店 info.Status = "0"; info.IsReturn = 0; info.DCodeType = 2; // add by donal 2014-9-22 10:02:08 loggingSessionInfo.UserID = ObjectID; info.CreateBy = ObjectID; info.ImageUrl = imageUrl; //info.VipId = RP.UserID; info.ObjectId = ObjectID; //分享经销商的vipid vipDCodeServer.Create(info); #endregion var model = new QRCodeResponseModel() { IsSucess = true, ImageUrl = imageUrl, paraTmp = iResult.ToString().Insert(4, " ") }; Loggers.Debug(new DebugLogInfo() { Message = $"setSignUp content: {model}" }); return(Request.CreateResponse(HttpStatusCode.OK, model)); } catch (Exception ex) { var model = new QRCodeResponseModel() { IsSucess = false, ErrorMessage = string.Format("获取二维码出错:{0}", ex.Message) }; Loggers.Debug(new DebugLogInfo() { Message = string.Format("获取二维码出错:{0}", ex.Message) }); return(Request.CreateResponse(HttpStatusCode.InternalServerError, model)); } }
public void CreateQRCode(SetCTWEventRP para, WApplicationInterfaceEntity wapentity, string strPageParamJson, out string strQRCode, out string QRCodeUrl, out string RedirectUrl) { #region 获取Page信息 var pageBll = new SysPageBLL(loggingSessionInfo); //根据活动的抽奖方式获取:“HB” “BigDial“ string strPageKey = string.Empty; switch (para.DrawMethodCode) { case "HB": strPageKey = "RedPacket"; break; case "DZP": strPageKey = "BigDial"; break; case "QN": strPageKey = "Questionnaire"; break; default: strPageKey = "NewsActivityList"; break; } #endregion #region 生成URL var Domain = ConfigurationManager.AppSettings["interfacehost"].Replace("http://", ""); var Domain1 = ConfigurationManager.AppSettings["interfacehost1"].Replace("http://", ""); string URL = string.Empty; #region 系统模块 var page = pageBll.GetPageByCustomerIdAndPageKey(loggingSessionInfo.ClientID, strPageKey).SingleOrDefault(); if (page == null) { throw new APIException("未找到Page信息") { ErrorCode = 341 } } ; string path = string.Empty; //要替换的路径 string urlTemplate = page.URLTemplate; //模板URL string json = page.JsonValue; // JSON体 var jsonDic = json.DeserializeJSONTo <Dictionary <string, object> >(); //转换后的字典 var htmls = jsonDic["htmls"].ToJSON().DeserializeJSONTo <Dictionary <string, object>[]>().ToList(); //htmls是一个数组,里面有他的很多属性 Dictionary <string, object> html = null; //选择的html信息 var defaultHtmlId = jsonDic["defaultHtml"].ToString(); html = htmls.Find(t => t["id"].ToString() == defaultHtmlId); //默认的htmlid***** if (html != null) { path = html["path"].ToString(); } //判断高级oauth认证 var scope = "snsapi_userinfo"; //if (jsonDic.ContainsKey("scope"))//必须要判断key里是否包含scope //{ // scope = (jsonDic["scope"] == null || jsonDic["scope"].ToString() == "") ? "snsapi_base" : "snsapi_userinfo"; //} //判断是否有定制,没有则取JSON体中的默认 //找出订制内容 if (page != null) { //看是否有htmls的定制(Node值=2) if (page.Node == "2") { var nodeValue = page.NodeValue; //在Json解析后的集合中找到path html = htmls.Find(t => t["id"].ToString() == nodeValue); if (html != null) { path = html["path"].ToString(); } } } //读取配置信息域名,检查不用http://开头,如果有则去除 var IsAuth = false; //TODO:判断页面是否需要Auth认证,如果页面需要证则再判断这个客户有没有Auth认证,Type=3 if (page.IsAuth == 1) { //判断这个客户是否是认证客户,type=3 var applicationBll = new WApplicationInterfaceBLL(loggingSessionInfo); var application = applicationBll.GetByID(wapentity.ApplicationId);//取默认的第一个 if (application.WeiXinTypeId == "3") { IsAuth = true; } } //替换URL模板 #region 替换URL模板 urlTemplate = urlTemplate.Replace("_pageName_", path); //用path替换掉_pageName_***(可以查看红包或者客服的path信息即可以知道) var paraDic = strPageParamJson.DeserializeJSONTo <Dictionary <string, object>[]>(); foreach (var item in paraDic) //这里key和value对于活动来说,其实就是活动的eventId,和eventId的值 { if (item.ContainsKey("key") && item.ContainsKey("value")) { urlTemplate = urlTemplate.Replace("{" + item["key"] + "}", item["value"].ToString()); } } #endregion //根据规则组织URL #region 组织URL //读取配置文件中的域名 if (string.IsNullOrEmpty(Domain)) { throw new APIException("微信管理:未配置域名,请在web.config中添加<add key='host' value=''/>") { ErrorCode = 342 } } ; if (IsAuth) { //需要认证(传参数时,需要传递applicationId,对于一个商户有多个微信服务号的,不能取默认的第一个,而是精确地取固定的微信服务号) //通过urlTemplate(用path替换了_pageName_),生成了goUrl URL = string.Format("http://{0}/WXOAuth/AuthUniversal.aspx?customerId={1}&applicationId={2}&goUrl={3}&scope={4}", Domain.Trim('/'), loggingSessionInfo.ClientID, wapentity.ApplicationId, HttpUtility.UrlEncode(string.Format("{0}{1}", Domain.Trim('/'), urlTemplate)), scope); } else { //不需要认证 URL = string.Format("http://{0}/WXOAuth/NoAuthGoto.aspx?customerId={1}&goUrl={2}", Domain.Trim('/'), loggingSessionInfo.ClientID, HttpUtility.UrlEncode(string.Format("{0}{1}", Domain.Trim('/'), urlTemplate.Trim('/')))); } RedirectUrl = URL; #endregion #endregion #endregion string sourcePath = HttpContext.Current.Server.MapPath("/QRCodeImage/qrcode.jpg"); string targetPath = HttpContext.Current.Server.MapPath("/QRCodeImage/"); string currentDomain = "http://" + HttpContext.Current.Request.Url.Host;//当前项目域名 QRCodeUrl = Utils.GenerateQRCode(URL, currentDomain, sourcePath, targetPath); ObjectImagesBLL bllObjectImages = new ObjectImagesBLL(loggingSessionInfo); ObjectImagesEntity entityObjectImages = new ObjectImagesEntity(); entityObjectImages = new ObjectImagesEntity() { ImageId = Utils.NewGuid(), CustomerId = loggingSessionInfo.ClientID, ImageURL = QRCodeUrl, ObjectId = strCTWEventId, Title = "", Description = "创意仓库活动二维码" }; //把下载下来的图片的地址存到ObjectImages bllObjectImages.Create(entityObjectImages); strQRCode = entityObjectImages.ImageId.ToString(); }
public void CreateH5QRCode(SetCTWEventRP para, WApplicationInterfaceEntity wapentity, out string strQRCode, out string QRCodeUrl, out string RedirectUrl) { #region 图文,二维码 #region 生成图文素材 #region 获取Page信息 var pageBll = new SysPageBLL(loggingSessionInfo); var textBll = new WMaterialTextBLL(loggingSessionInfo); //组织图文实体 var entity = new WMaterialTextEntity() { ApplicationId = wapentity.ApplicationId, //用自己取出来的 CoverImageUrl = para.MaterialText.ImageUrl, //图片地址 PageId = Guid.NewGuid(), //页面模块的标识 PageParamJson = para.MaterialText.PageParamJson, //这个比较重要 Text = para.MaterialText.Text, TextId = "", //为空时在后面保存时生成 Title = para.MaterialText.Title, TypeId = para.MaterialText.TypeId }; #endregion #region 生成URL var Domain = ConfigurationManager.AppSettings["interfacehost"].Replace("http://", ""); var Domain1 = ConfigurationManager.AppSettings["interfacehost1"].Replace("http://", ""); string URL = string.Empty; bool IsAuth = false; URL = ConfigurationManager.AppSettings["LinKinUrl"] + "id=" + para.EventThemeInfo.WorksId; entity.IsAuth = Convert.ToInt32(IsAuth); entity.PageParamJson = para.MaterialText.PageParamJson; #endregion #endregion entity.OriginalUrl = URL;//图文素材要跳转到的页面 RedirectUrl = URL; #endregion #region 保存 var unionMappingBll = new WModelTextMappingBLL(loggingSessionInfo); entity.TextId = Guid.NewGuid().ToString("N"); textBll.Create(entity);//创建图文素材 #endregion string strQRCodeObjectId = Guid.NewGuid().ToString(); //活动的二维码自己查找QRCodeId var wqrCodeManagerEntity = new WQRCodeManagerBLL(loggingSessionInfo).QueryByEntity(new WQRCodeManagerEntity() { ObjectId = strQRCodeObjectId }, null).FirstOrDefault(); Guid QRCodeId; if (wqrCodeManagerEntity == null) { #region 生成二维码 var wqrentity = new WQRCodeTypeBLL(loggingSessionInfo).QueryByEntity( new WQRCodeTypeEntity { TypeCode = "CreativeCode" } , null).FirstOrDefault(); var wxCode = CretaeWxCode(); var WQRCodeManagerbll = new WQRCodeManagerBLL(loggingSessionInfo); QRCodeId = Guid.NewGuid(); if (!string.IsNullOrEmpty(wxCode.ImageUrl)) { wqrCodeManagerEntity = new WQRCodeManagerEntity() { QRCodeId = QRCodeId, QRCode = wxCode.MaxWQRCod.ToString(), QRCodeTypeId = wqrentity.QRCodeTypeId, IsUse = 1, ObjectId = strQRCodeObjectId, CreateBy = loggingSessionInfo.UserID, ApplicationId = wapentity.ApplicationId, IsDelete = 0, ImageUrl = wxCode.ImageUrl, CustomerId = loggingSessionInfo.ClientID }; WQRCodeManagerbll.Create(wqrCodeManagerEntity); } else { throw new APIException(wxCode.msg) { ErrorCode = 342 }; } #endregion //throw new APIException("活动没有生成二维码!") { ErrorCode = 342 }; } QRCodeId = (Guid)wqrCodeManagerEntity.QRCodeId;//活动二维码的标识 ////根据二维码标识查找是否有他的关键字回复 var WKeywordReplyentity = new WKeywordReplyBLL(loggingSessionInfo).QueryByEntity(new WKeywordReplyEntity() { Keyword = QRCodeId.ToString() //二维码的标识 }, null).FirstOrDefault(); var ReplyBLL = new WKeywordReplyBLL(loggingSessionInfo); var ReplyId = Guid.NewGuid().ToString();//创建临时 if (WKeywordReplyentity == null) { ReplyBLL.Create(new WKeywordReplyEntity() { ReplyId = ReplyId, Keyword = QRCodeId.ToString(), ReplyType = 3, //用图文素材 KeywordType = 4, //标识 IsDelete = 0, CreateBy = loggingSessionInfo.UserID, ApplicationId = wapentity.ApplicationId, }); } else { ReplyId = WKeywordReplyentity.ReplyId; //用取出来的数据查看 WKeywordReplyentity.Text = ""; WKeywordReplyentity.ReplyType = 3; //图文素材 ReplyBLL.Update(WKeywordReplyentity); } #region 添加图文消息 WMenuMTextMappingBLL MenuMTextMappingServer = new WMenuMTextMappingBLL(loggingSessionInfo); WMenuMTextMappingEntity MappingEntity = new WMenuMTextMappingEntity(); MappingEntity.MenuId = ReplyId; MappingEntity.TextId = entity.TextId; // 用图文素材标识****** MappingEntity.DisplayIndex = 1; //排列顺序 MappingEntity.CustomerId = loggingSessionInfo.ClientID; MappingEntity.MappingId = Guid.NewGuid(); MenuMTextMappingServer.Create(MappingEntity); strQRCode = QRCodeId.ToString(); QRCodeUrl = wqrCodeManagerEntity.ImageUrl; #endregion }
public bool setCreateWXMenu(WApplicationInterfaceEntity info) { return(_currentDAO.setCreateWXMenu(info)); }
public void Update(WApplicationInterfaceEntity pEntity, bool pIsUpdateNullField) { _currentDAO.Update(pEntity, pIsUpdateNullField); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <WApplicationInterfaceEntity> PagedQueryByEntity(WApplicationInterfaceEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex) { return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex)); }
private void SetToken() { string customerId = string.Empty; string applicationId = string.Empty; string userId = string.Empty; string openId = string.Empty; string eventId = string.Empty; string strAppId = string.Empty; string strAppSecret = string.Empty; LoggingSessionInfo loggingSessionInfo = new LoggingSessionInfo(); try { #region 解析参数 byte[] buff1 = Convert.FromBase64String(state); state = Encoding.UTF8.GetString(buff1); state = HttpUtility.UrlDecode(state, Encoding.UTF8); Loggers.Debug(new DebugLogInfo() { Message = string.Format("SetToken--state: {0}", state.ToString()) }); string[] array = state.Split(','); customerId = array[0]; applicationId = array[1]; userId = array[2]; openId = array[3]; eventId = array[4]; goUrl = array[5]; #endregion loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1"); WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(loggingSessionInfo); WApplicationInterfaceEntity info = server.GetByID(applicationId); if (info == null) { Response.Write("不存在对应的微信标识"); } else { Random rad = new Random(); int iRad = rad.Next(1000, 100000); strAppId = info.AppID; strAppSecret = info.AppSecret; JIT.CPOS.BS.BLL.WX.AuthBLL authServer = new BS.BLL.WX.AuthBLL(); string token = ""; string openIdNew = authServer.GetAccessToken(code, strAppId, strAppSecret, loggingSessionInfo, iRad, out token); //Response.Write("openId:" + openId); //Response.Write("------------"); //Response.Write("openIdNew:" + openIdNew); if (!openIdNew.Equals("")) { if (openId.Equals(openIdNew)) { goUrl = HttpUtility.UrlDecode(goUrl) + "?customerId=" + customerId + "&openId=" + openId + "&userId=" + userId + "&eventId=" + eventId + "&code=" + code + "&rid=" + rad.Next(1000, 100000) + ""; //"http://" + HttpUtility.UrlDecode(goUrl) + ""; //Response.Write(goUrl); Response.Redirect(goUrl); } } else { Response.Write("请关注微讯网(o2omarketing)公众平台,在登录该界面操作。"); } } } catch (Exception ex) { strError = ex.ToString(); } }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity"></param> public void Delete(WApplicationInterfaceEntity pEntity) { _currentDAO.Delete(pEntity); }
/// <summary> /// 保存微信信息 /// </summary> /// <param name="pwai"></param> /// <param name="paui"></param> /// <param name="clientId"></param> /// <returns></returns> public static bool SetWechatApp(QueryAuthResult pwai, GetAuthorizerInfoResult paui, string clientId) { #region 保存到微信信息表里 //var clientId = "eb17cc2569c74ab7888b1f403972d37d";//测试用 var loggingSessionInfo = Default.GetBSLoggingSession(clientId, "open"); var waiBll = new WApplicationInterfaceBLL(loggingSessionInfo); var waiEntitys = new WApplicationInterfaceEntity[] { }; var waiEntity = new WApplicationInterfaceEntity(); //去除之前授权的记录 //查询参数 List <IWhereCondition> complexCondition = new List <IWhereCondition> { }; complexCondition.Add(new EqualsCondition() { FieldName = "AppID", Value = pwai.authorization_info.authorizer_appid }); complexCondition.Add(new DirectCondition(" CustomerId != '" + clientId + "'")); complexCondition.Add(new EqualsCondition() { FieldName = "OpenOAuthAppid", Value = WebConfigurationManager.AppSettings["Component_Appid"] }); var tempList = waiBll.PagedQuery(complexCondition.ToArray(), null, 10, 1); if (tempList.Entities.Length > 0) { foreach (var item in tempList.Entities) { waiBll.Delete(item); } } var prevWaiEntitys = waiBll.QueryByEntity(new WApplicationInterfaceEntity { AppID = pwai.authorization_info.authorizer_appid, CustomerId = clientId, IsDelete = 0, OpenOAuthAppid = WebConfigurationManager.AppSettings["Component_Appid"] }, null); waiEntitys = waiBll.QueryByEntity(new WApplicationInterfaceEntity { AppID = pwai.authorization_info.authorizer_appid, CustomerId = clientId, IsDelete = 0 }, null); if (waiEntitys != null && waiEntitys.Length > 0) { waiEntity = waiEntitys.FirstOrDefault(); waiEntity.URL = Config.URL; waiEntity.Token = "jitmarketing";//老代码写死token//Config.ServerToken; //waiEntity.Token = "zmindclouds";//老代码写死token//Config.ServerToken, //waiEntity.AppID = "wx691c2f2bbac04b4b"; //waiEntity.AppSecret = "0c79e1fa963cd80cc0be99b20a18faeb"; //waiEntity.PrevEncodingAESKey = "F3Rd5xvdCqUsL5FFwhS1vSIqTRFoNpRcWhyGrOjQhAK"; //waiEntity.CurrentEncodingAESKey = "F3Rd5xvdCqUsL5FFwhS1vSIqTRFoNpRcWhyGrOjQhAK"; waiEntity.ServerIP = Config.ServerIP; waiEntity.AuthUrl = Config.AuthUrl; waiEntity.RequestToken = pwai != null ? pwai.authorization_info.authorizer_access_token : string.Empty; //waiEntity.RefreshToken = pwai != null ? pwai.authorization_info.authorizer_refresh_token : string.Empty,//刷新token waiEntity.ExpirationTime = DateTime.Now.AddSeconds(7000);//默认7200,提前200秒过期 waiEntity.IsMoreCS = 1; waiEntity.OpenOAuthAppid = WebConfigurationManager.AppSettings["Component_Appid"]; waiBll.Update(waiEntity); //提交管理平台 waiBll.setCposApMapping(waiEntity); } else { if (pwai != null && paui != null) { } var weixinTypeId = "3";//服务号 switch (paui.authorizer_info.service_type_info.id.ToString()) { case "0": weixinTypeId = "1"; //订阅号 break; case "1": weixinTypeId = "2"; //订阅号 break; } waiEntity = new WApplicationInterfaceEntity() { ApplicationId = Guid.NewGuid().ToString("N"), WeiXinName = paui != null ? paui.authorizer_info.nick_name : string.Empty, WeiXinID = paui != null ? paui.authorizer_info.user_name : string.Empty, URL = Config.URL, Token = "jitmarketing", //老代码写死token//Config.ServerToken, AppID = pwai != null ? pwai.authorization_info.authorizer_appid : string.Empty, AppSecret = string.Empty, //空 //Token = "zmindclouds",//老代码写死token//Config.ServerToken, //AppID = "wx691c2f2bbac04b4b", //AppSecret = "0c79e1fa963cd80cc0be99b20a18faeb",//空 //PrevEncodingAESKey = "F3Rd5xvdCqUsL5FFwhS1vSIqTRFoNpRcWhyGrOjQhAK", //CurrentEncodingAESKey = "F3Rd5xvdCqUsL5FFwhS1vSIqTRFoNpRcWhyGrOjQhAK", ServerIP = Config.ServerIP, WeiXinTypeId = weixinTypeId,// paui != null ? paui.authorizer_info.service_type_info.id.ToString() : "3", AuthUrl = Config.AuthUrl, RequestToken = pwai != null ? pwai.authorization_info.authorizer_access_token : string.Empty, //RefreshToken = pwai != null ? pwai.authorization_info.authorizer_refresh_token : string.Empty,//刷新token ExpirationTime = DateTime.Now.AddSeconds(7000), //默认7200,提前200秒过期 IsHeight = 1, //1=高级帐号 IsMoreCS = 1, OpenOAuthAppid = WebConfigurationManager.AppSettings["Component_Appid"], // component_AppId; CustomerId = clientId }; waiBll.Create(waiEntity); //提交微信初级菜单 waiBll.setCreateWXMenu(waiEntity); //提交管理平台 waiBll.setCposApMapping(waiEntity); } #endregion return(true); }
/// <summary> /// 根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public WApplicationInterfaceEntity[] QueryByEntity(WApplicationInterfaceEntity pQueryEntity, OrderBy[] pOrderBys) { return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys)); }