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";
                }
            }
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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";
                }
            }
        }
Beispiel #5
0
        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";
                }
            }
        }
Beispiel #6
0
        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();
            }
        }
Beispiel #7
0
        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();
        }
        protected override SetMaterialTextRD ProcessRequest(APIRequest <SetMaterialTextRP> pRequest)
        {
            SetMaterialTextRD rd = new SetMaterialTextRD();
            var para             = pRequest.Parameters;

            #region 获取Page信息
            var pageBll = new SysPageBLL(CurrentUserInfo);
            var textBll = new WMaterialTextBLL(CurrentUserInfo);

            //组织图文实体
            var entity = new WMaterialTextEntity()
            {
                ApplicationId = para.MaterialText.ApplicationId,
                CoverImageUrl = para.MaterialText.ImageUrl,
                PageId        = para.MaterialText.PageID,

                PageParamJson    = para.MaterialText.PageParamJson,
                Text             = para.MaterialText.Text,
                TextId           = para.MaterialText.TextId,
                Title            = para.MaterialText.Title,
                TypeId           = para.MaterialText.TypeId,
                Author           = para.MaterialText.Abstract,//摘要使用原来的字段
                IsTitlePageImage = para.MaterialText.IsTitlePageImage
            };
            #endregion

            #region 生成URL
            var Domain = ConfigurationManager.AppSettings["interfacehost"].Replace("http://", "");

            var    Domain1 = ConfigurationManager.AppSettings["interfacehost1"].Replace("http://", "");
            string URL     = string.Empty;
            switch (para.MaterialText.UnionTypeId)
            {
            case "1":    //链接
                #region 链接
                URL = para.MaterialText.OriginalUrl;
                #endregion
                break;

            case "2":    //详情
                #region 详情
                URL = string.Format("http://{0}/Module/WeiXin/MaterialTextDetail.aspx?news_id=#TextId#&customerId=#cutomerId#&interfacehost={1}", Domain1.Trim('/'), ConfigurationManager.AppSettings["interfacehost1"]);
                #endregion
                break;

            case "3":                                                      //系统模块
                #region 系统模块
                var pages = pageBll.GetPageByID(para.MaterialText.PageID); //通过pageid查找syspage信息
                if (pages.Length == 0)
                {
                    throw new APIException("未找到Page:" + para.MaterialText.PageID)
                          {
                              ErrorCode = 341
                          }
                }
                ;
                SysPageEntity CurrentPage;
                string        path               = string.Empty;                                                                           //要替换的路径
                string        urlTemplate        = pages[0].URLTemplate;                                                                   //模板URL
                string        json               = pages[0].JsonValue;                                                                     // JSON体
                var           jsonDic            = json.DeserializeJSONTo <Dictionary <string, object> >();                                //转换后的字典
                var           htmls              = jsonDic["htmls"].ToJSON().DeserializeJSONTo <Dictionary <string, object>[]>().ToList(); //所有的Html模板
                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_base";
                if (jsonDic.ContainsKey("scope"))
                {
                    scope = (jsonDic["scope"] == null || jsonDic["scope"] == "") ? "snsapi_base" : "snsapi_userinfo";
                }


                //判断是否有定制,没有则取JSON体中的默认
                //找出订制内容
                var customerPages = pages.ToList().FindAll(t => t.CustomerID == CurrentUserInfo.ClientID);
                if (customerPages.Count > 0)
                {
                    //看是否有htmls的定制(Node值=2)
                    CurrentPage = customerPages.Find(t => t.Node == "2");
                    if (CurrentPage != null)
                    {
                        var nodeValue = CurrentPage.NodeValue;
                        //在Json解析后的集合中找到path
                        html = htmls.Find(t => t["id"].ToString() == nodeValue);
                        if (html != null)
                        {
                            path = html["path"].ToString();
                        }
                    }
                    else
                    {
                        CurrentPage = pages[0];
                    }
                }
                else
                {
                    CurrentPage = pages[0];
                }
                //读取配置信息域名,检查不用http://开头,如果有则去除
                var IsAuth = false;
                //TODO:判断页面是否需要Auth认证,如果页面需要证则再判断这个客户有没有Auth认证,Type=3
                if (CurrentPage.IsAuth == 1)
                {
                    //判断这个客户是否是认证客户,type=3
                    var applicationBll = new WApplicationInterfaceBLL(CurrentUserInfo);
                    var application    = applicationBll.GetByID(para.MaterialText.ApplicationId);
                    if (application.WeiXinTypeId == "3")
                    {
                        IsAuth = true;
                    }
                }

                //替换URL模板
                #region 替换URL模板
                urlTemplate = urlTemplate.Replace("_pageName_", path);
                var paraDic = para.MaterialText.PageParamJson.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)
                {
                    //需要认证,并加上scope类型
                    URL = string.Format("http://{0}/WXOAuth/AuthUniversal.aspx?customerId={1}&applicationId={2}&goUrl={3}&scope={4}", Domain.Trim('/'), CurrentUserInfo.ClientID, para.MaterialText.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('/'), CurrentUserInfo.ClientID, HttpUtility.UrlEncode(string.Format("{0}{1}", Domain.Trim('/'), urlTemplate.Trim('/'))));
                }
                entity.IsAuth        = Convert.ToInt32(IsAuth);
                entity.PageParamJson = para.MaterialText.PageParamJson;
                #endregion
                #endregion
                break;

            default:
                break;
            }

            entity.OriginalUrl = URL;//图文素材
            #endregion

            #region 保存
            var unionMappingBll = new WModelTextMappingBLL(CurrentUserInfo);
            //检查图文素材是否重复
            if (textBll.CheckName(entity.ApplicationId, entity.Title, entity.TextId))
            {
                throw new APIException("标题重复,请重新输入.")
                      {
                          ErrorCode = ERROR_CODES.INVALID_REQUEST
                      };
            }
            if (string.IsNullOrEmpty(entity.TextId))
            {
                entity.TextId = Guid.NewGuid().ToString("N");
                #region 图文详情要对占位符#TextId#和#customerId#进行替换
                entity.OriginalUrl = entity.OriginalUrl.Replace("#TextId#", entity.TextId).Replace("#cutomerId#", CurrentUserInfo.ClientID);
                #endregion
                textBll.Create(entity);
                var mapping = new WModelTextMappingEntity()
                {
                    MappingId = Guid.NewGuid().ToString("N"),
                    ModelId   = entity.TypeId,
                    TextId    = entity.TextId,
                };
                unionMappingBll.Create(mapping);
            }
            else
            {
                #region 图文详情要对占位符#textId和#customerId进行替换
                entity.OriginalUrl = entity.OriginalUrl.Replace("#TextId#", entity.TextId).Replace("#cutomerId#", CurrentUserInfo.ClientID);
                #endregion
                textBll.Update(entity);
            }

            #region 图文分类和图文Mapping关系,先删除再增加
            var modelMappingBll = new WModelTextMappingBLL(CurrentUserInfo);
            modelMappingBll.DeleteByTextId(entity.TextId);
            var modelMapping = new WModelTextMappingEntity()
            {
                MappingId = Guid.NewGuid().ToString("N"),
                ModelId   = entity.TypeId, //模板的标识竟然是和图文类型的标识
                TextId    = entity.TextId
            };
            modelMappingBll.Create(modelMapping);
            #endregion

            #endregion

            rd.MaterialTextId = entity.TextId;
            return(rd);
        }