コード例 #1
0
        /// <summary>
        /// 获取微信统一凭证接口
        /// </summary>
        /// <returns></returns>
        public string GetAccessToken(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <EmptyRequestParameter> >();
            var loggingSessionInfo = Default.GetBSLoggingSession(rp.CustomerID, rp.UserID);
            var appService         = new WApplicationInterfaceBLL(loggingSessionInfo);


            var appEntity = appService.QueryByEntity(new WApplicationInterfaceEntity()
            {
                CustomerId = rp.CustomerID
            }, null)[0];

            var tempAccessToke = new CommonBLL().GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, loggingSessionInfo);

            //重新取一次
            appEntity = appService.QueryByEntity(new WApplicationInterfaceEntity()
            {
                CustomerId = rp.CustomerID
            }, null)[0];

            WxAccessToken accessToken = new WxAccessToken()
            {
                access_token   = tempAccessToke.access_token,//appEntity.RequestToken,
                expires_in     = tempAccessToke.expires_in,
                ExpirationTime = appEntity.ExpirationTime.ToString()
            };

            return(new SuccessResponse <IAPIResponseData>(accessToken).ToJSON());
        }
コード例 #2
0
        /// <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());
        }
コード例 #3
0
        protected override GetModuleListRD ProcessRequest(DTO.Base.APIRequest <EmptyRequestParameter> pRequest)
        {
            var rd = new GetModuleListRD();
            var loggingSessionInfo              = new SessionManager().CurrentUserLoginInfo;
            WApplicationInterfaceBLL bllApp     = new WApplicationInterfaceBLL(loggingSessionInfo);
            T_UserGuideModulesBLL    bll        = new T_UserGuideModulesBLL(loggingSessionInfo);
            List <ModuleInfo>        moduleList = new List <ModuleInfo>();
            //是否绑定微信公众号
            var entityApp = bllApp.QueryByEntity(new WApplicationInterfaceEntity()
            {
                CustomerId = loggingSessionInfo.ClientID, IsDelete = 0
            }, null);

            if (entityApp.Count() > 0)
            {
                rd.IsBindWeChat = 1;
            }
            ///新手引导大模块
            var entity = bll.QueryByEntity(new T_UserGuideModulesEntity()
            {
                ModuleStep = 0, IsDelete = 0
            }, null);
            IEnumerable <ModuleInfo> ModuleList = from e in entity
                                                  select new ModuleInfo()
            {
                ModuleName         = e.ModuleName,
                ModuleCode         = e.ModuleCode,
                UserGuideModulesId = e.UserGuideModulesId.ToString(),
                ParentModule       = e.ParentModule.ToString(),
                Url      = e.Url,
                VideoUrl = e.VideoUrl,
                //ImageUrl1=e.ImageUrl1,
                //ImageUrl2=e.ImageUrl2,
                //ImageUrl3=e.ImageUrl3
            };
            ///每个用户最后一次的记录,已经模块是否完成
            T_UserGuideAccessLogBLL bllUserGuideLog = new T_UserGuideAccessLogBLL(loggingSessionInfo);
            var LogList = bllUserGuideLog.QueryByEntity(new Entity.T_UserGuideAccessLogEntity()
            {
                CustomerId = loggingSessionInfo.ClientID, UserId = loggingSessionInfo.CurrentLoggingManager.User_Id, IsDelete = 0
            }, null);

            foreach (var m in ModuleList)
            {
                foreach (var log in LogList)
                {
                    if (m.UserGuideModulesId == log.UserGuideModulesId.ToString())
                    {
                        m.LastStep       = (int)log.LastAccessStep;
                        m.LastUrl        = log.Url;
                        m.FinishedStatus = (int)log.FinishedStatus;
                    }
                }
                moduleList.Add(m);
            }
            rd.ModuleInfoList = moduleList;

            return(rd);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
ファイル: BaseBLL.cs プロジェクト: radtek/CustomerManage
        public void ReplyImage(string ImageId)
        {
            var wMaterialImageBll    = new WMaterialImageBLL(requestParams.LoggingSessionInfo);
            var wMaterialImageEntity = wMaterialImageBll.GetByID(ImageId);

            var commonService = new CommonBLL();
            var appService    = new WApplicationInterfaceBLL(requestParams.LoggingSessionInfo);
            var appEntity     = appService.QueryByEntity(new WApplicationInterfaceEntity()
            {
                WeiXinID = requestParams.WeixinId
            }, null).FirstOrDefault();
            var accessToken = commonService.GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, requestParams.LoggingSessionInfo);

            UploadMediaEntity media = commonService.UploadMediaFile(accessToken.access_token, wMaterialImageEntity.ImageUrl, MediaType.Image);

            commonService.ResponseImageMessage(requestParams.WeixinId, requestParams.OpenId, media.media_id, httpContext, requestParams);
        }
コード例 #6
0
        /// <summary>
        /// 获取列表
        /// </summary>
        public string GetListData()
        {
            var service = new WApplicationInterfaceBLL(new SessionManager().CurrentUserLoginInfo);
            IList <WApplicationInterfaceEntity> data = new List <WApplicationInterfaceEntity>();
            string content = string.Empty;

            data = service.QueryByEntity(new WApplicationInterfaceEntity
            {
                CustomerId = new SessionManager().CurrentUserLoginInfo.CurrentUser.customer_id
            }, null);
            //data = service.GetAll().ToList();

            var jsonData = new JsonData();

            jsonData.totalCount = data.Count.ToString();
            jsonData.data       = data;

            content = jsonData.ToJSON();
            return(content);
        }
コード例 #7
0
        /// <summary>
        /// 获取列表
        /// </summary>
        public string GetListData()
        {
            var service = new WModelBLL(new SessionManager().CurrentUserLoginInfo);
            var wApplicationInterfaceBLL = new WApplicationInterfaceBLL(new SessionManager().CurrentUserLoginInfo);
            IList <WModelEntity> data    = new List <WModelEntity>();
            string content = string.Empty;

            string key = "";

            if (Request("pid") != null && Request("pid") != string.Empty)
            {
                key = Request("pid").ToString().Trim();
            }
            string type = "";

            if (Request("type") != null && Request("type") != string.Empty)
            {
                type = Request("type").ToString().Trim();
            }
            if (type == "2")
            {
                var appList = wApplicationInterfaceBLL.QueryByEntity(new WApplicationInterfaceEntity()
                {
                    WeiXinID = key
                }, null);
                if (appList != null && appList.Length > 0)
                {
                    key = appList[0].ApplicationId;
                }
            }
            data = service.GetWModelListByAppId(key);

            var jsonData = new JsonData();

            jsonData.totalCount = data.Count.ToString();
            jsonData.data       = data;

            content = jsonData.ToJSON();
            return(content);
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        //响应微信平台推送消息
        private void ResponseMsg(HttpContext httpContext, RequestParams requestParams)
        {
            BaseBLL  weixin  = null;
            IFactory factory = null;

            #region 通过微信类型生成对应的业务处理类

            var application = new WApplicationInterfaceBLL(requestParams.LoggingSessionInfo);
            var appEntitys  = application.QueryByEntity(new WApplicationInterfaceEntity()
            {
                WeiXinID = requestParams.WeixinId
            }, null);

            if (appEntitys != null && appEntitys.Length > 0)
            {
                var entity = appEntitys.FirstOrDefault();
                BaseService.WriteLogWeixin("通过微信类型生成对应的业务处理类");
                BaseService.WriteLogWeixin("WeiXinTypeId(微信类型):  " + entity.WeiXinTypeId);

                switch (entity.WeiXinTypeId)
                {
                case WeiXinType.SUBSCRIPTION:
                    factory = new SubscriptionFactory();
                    weixin  = factory.CreateWeiXin(httpContext, requestParams);
                    BaseService.WriteLogWeixin("订阅号");
                    break;

                case WeiXinType.SERVICE:
                    factory = new ServiceFactory();
                    weixin  = factory.CreateWeiXin(httpContext, requestParams);
                    BaseService.WriteLogWeixin("服务号");
                    break;

                case WeiXinType.CERTIFICATION:        //目前我们的客户一般是认证服务号,所以关注事件从这里查看
                    factory = new CertificationFactory();
                    weixin  = factory.CreateWeiXin(httpContext, requestParams);
                    BaseService.WriteLogWeixin("认证服务号");
                    break;

                case WeiXinType.SUBSCRIPTION_EXTEND:
                    BaseService.WriteLogWeixin("可扩展订阅号");
                    break;

                case WeiXinType.SERVICE_EXTEND:
                    BaseService.WriteLogWeixin("可扩展服务号");
                    break;

                case WeiXinType.CERTIFICATION_EXTEND:
                    BaseService.WriteLogWeixin("可扩展认证服务号");
                    break;

                default:
                    factory = new SubscriptionFactory();
                    weixin  = factory.CreateWeiXin(httpContext, requestParams);
                    BaseService.WriteLogWeixin("默认订阅号");
                    break;
                }
            }

            #endregion

            weixin.ResponseMsg();//根据消息类型,回应事件。有文本消息、图片消息、多客服、地理位置、事件
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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));
            }
        }
コード例 #12
0
        protected override GetMenuListRD ProcessRequest(DTO.Base.APIRequest <GetMenuListRP> pRequest)
        {
            var rd = new GetMenuListRD();

            string applicationId = pRequest.Parameters.ApplicationId;
            string customerId    = this.CurrentUserInfo.ClientID;

            var bll = new WMenuBLL(this.CurrentUserInfo);

            var wappBll = new WApplicationInterfaceBLL(CurrentUserInfo);

            var wappEntity = wappBll.QueryByEntity(new WApplicationInterfaceEntity()
            {
                ApplicationId = applicationId
            }, null);

            if (wappEntity.Length == 0 || wappEntity.Any() == false)
            {
                throw new APIException("该微信公众号无效")
                      {
                          ErrorCode = 120
                      };
            }
            var weixinId = wappEntity[0].WeiXinID;


            var ds = bll.GetMenuList(customerId, applicationId);

            if (ds.Tables[0].Rows.Count == 0)
            {
                rd.MenuList = null;
            }
            else
            {
                string menuList =
                    ds.Tables[0].AsEnumerable().Aggregate("", (x, j) =>
                {
                    x += string.Format("'{0}',", j["ID"].ToString());
                    return(x);
                }).Trim(',');

                #region 根据菜单ID从图文映射表里面关联到图文表里面数据

                //  var textDs = bll.GetMenuTextIdList(customerId, weixinId, menuList);

                #endregion

                var temp =
                    ds.Tables[0].AsEnumerable()
                    .Where(t => t["level"].ToString() == "1")     //先取第一层
                    .OrderBy(t => t["Status"].ToString())
                    .OrderBy(t => Convert.ToInt32(t["DisplayColumn"]))
                    .Select(t => new MenuInfo
                {
                    MenuId        = t["ID"].ToString(),
                    WeiXinId      = t["WeiXinID"].ToString(),
                    ApplicationId = applicationId,
                    Name          = t["Name"].ToString(),
                    DisplayColumn = Convert.ToInt32(t["DisplayColumn"]),
                    Level         = Convert.ToInt32(t["Level"]),
                    ParentId      = t["ParentId"].ToString(),
                    Status        = Convert.ToInt32(t["Status"]),
                    SubMenus      =
                        ds.Tables[0].AsEnumerable()
                        .Where(
                            tt =>
                            tt["ParentId"].ToString() == t["ID"].ToString() &&
                            tt["level"].ToString() == "2")                //子菜单里取第二层
                        .OrderBy(tt => tt["Status"].ToString())
                        .OrderBy(tt => Convert.ToInt32(tt["DisplayColumn"]))
                        .Select(tt => new MenuChildInfo
                    {
                        MenuId        = tt["ID"].ToString(),
                        WeiXinId      = tt["WeiXinID"].ToString(),
                        ApplicationId = applicationId,
                        Name          = tt["Name"].ToString(),
                        DisplayColumn = Convert.ToInt32(tt["DisplayColumn"]),
                        Level         = Convert.ToInt32(tt["Level"]),
                        ParentId      = tt["ParentId"].ToString(),
                        Status        = Convert.ToInt32(tt["Status"]),
                    }).ToArray()
                });
                rd.MenuList = temp.ToArray();
            }
            return(rd);
        }
コード例 #13
0
        /// <summary>
        /// 获取门店二维码
        /// </summary>
        /// <returns></returns>
        public string SetUnitWXCode()
        {
            #region 参数处理
            string WeiXinId     = Request("WeiXinId");
            string UnitId       = Request("UnitId");
            string WXCode       = Request("WXCode");
            var    responseData = new ResponseData();
            if (WeiXinId == null || WeiXinId.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "公众号不能为空";
                return(responseData.ToJSON());
            }

            //if (UnitId == null || UnitId.Trim().Length == 0)
            //{
            //    responseData.success = false;
            //    responseData.msg = "门店标识不能为空";
            //    return responseData.ToJSON();
            //}
            //if (WXCode == null || WXCode.Equals(""))
            //{
            //    VwUnitPropertyBLL unitServer = new VwUnitPropertyBLL(CurrentUserInfo);
            //    WXCode = unitServer.GetUnitWXCode(UnitId).ToString();
            //}
            #endregion

            #region 获取微信公众号信息
            WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(CurrentUserInfo);
            var wxObj = server.QueryByEntity(new WApplicationInterfaceEntity
            {
                CustomerId = CurrentUserInfo.CurrentUser.customer_id
                ,
                IsDelete = 0
                ,
                ApplicationId = WeiXinId
            }, null);
            if (wxObj == null || wxObj.Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "不存在对应的微信帐号";
                return(responseData.ToJSON().ToString());
            }
            else
            {
                JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL();
                string imageUrl = commonServer.GetQrcodeUrl(wxObj[0].AppID.ToString().Trim()
                                                            , wxObj[0].AppSecret.Trim()
                                                            , "1"
                                                            , Convert.ToInt32(WXCode), CurrentUserInfo);
                if (imageUrl != null && !imageUrl.Equals(""))
                {
                    string host = ConfigurationManager.AppSettings["DownloadImageUrl"];

                    try
                    {
                        CPOS.Common.DownloadImage downloadServer = new DownloadImage();
                        imageUrl             = downloadServer.DownloadFile(imageUrl, host);
                        responseData.success = true;
                        responseData.msg     = imageUrl;
                        responseData.status  = WXCode;
                    }
                    catch (Exception ex)
                    {
                        responseData.success = false;
                        responseData.data    = imageUrl;
                        responseData.msg     = ex.ToString();
                        return(responseData.ToJSON().ToString());
                    }
                    return(responseData.ToJSON().ToString());
                }
                else
                {
                    responseData.success = false;
                    responseData.msg     = "图片不存在";
                    return(responseData.ToJSON().ToString());
                }
            }
            #endregion
        }
コード例 #14
0
        protected override SetMenuRD ProcessRequest(DTO.Base.APIRequest <SetMenuRP> pRequest)
        {
            var rd = new SetMenuRD();

            string menuId          = pRequest.Parameters.MenuId;
            string name            = pRequest.Parameters.Name;
            string parentId        = pRequest.Parameters.ParentId;
            string displayIndex    = pRequest.Parameters.DisplayColumn;
            int    status          = pRequest.Parameters.Status;
            string applicationId   = pRequest.Parameters.ApplicationId;//某个公众号在数据库里的标识
            string text            = pRequest.Parameters.Text;
            string menuUrl         = pRequest.Parameters.MenuUrl;
            string imageUrl        = pRequest.Parameters.ImageUrl;
            string messageType     = pRequest.Parameters.MessageType;
            int    unionTypeId     = pRequest.Parameters.UnionTypeId;
            Guid?  pageId          = pRequest.Parameters.PageId;
            string pageParamJson   = pRequest.Parameters.PageParamJson;
            var    materialTextIds = pRequest.Parameters.MaterialTextIds;
            string pageUrlJson     = pRequest.Parameters.PageUrlJson;

            int    level = pRequest.Parameters.Level;
            string type  = "";

            var bll = new WMenuBLL(this.CurrentUserInfo);

            #region  一级节点 节点名称长度不能超过3个汉字,二级节点 不能超过7个汉字

            #endregion

            #region type = view时,菜单链接MenuUrl不能为空

            #endregion

            #region 图文消息只能增加10条

            if (unionTypeId == 1 || unionTypeId == 3)
            {
                type = "view";
                if (unionTypeId == 1 && (string.IsNullOrEmpty(menuUrl) || menuUrl == ""))
                {
                    throw new APIException("菜单链接不能为空")
                          {
                              ErrorCode = 123
                          };
                }

                if (unionTypeId == 1 && (menuUrl.Length > 500))
                {
                    throw new APIException("菜单链接地址超长,请重新填写")
                          {
                              ErrorCode = 140
                          };
                }
            }
            else if (unionTypeId == 2)
            {
                type = "click";
                if (messageType == "3")
                {
                    if (materialTextIds == null || materialTextIds.Any() == false)
                    {
                        throw new APIException("图文消息不能为空")
                              {
                                  ErrorCode = 124
                              };
                    }
                    if (materialTextIds.Any() == true && materialTextIds.Length > 10)
                    {
                        throw new APIException("图文消息最大不能超过10条数据")
                              {
                                  ErrorCode = 125
                              };
                    }
                }

                if (messageType == "1")
                {
                    if (text == "" || string.IsNullOrEmpty(text))
                    {
                        throw new APIException("文本不能为空")
                              {
                                  ErrorCode = 126
                              };
                    }
                    if (Encoding.Default.GetBytes(text).Length > 2048)
                    {
                        throw new APIException("文本超过了最大限制(2M)")
                              {
                                  ErrorCode = 127
                              };
                    }
                }
                if (messageType == "2")
                {
                    if (imageUrl == "" || string.IsNullOrEmpty(imageUrl))
                    {
                        throw new APIException("图片不能为空")
                              {
                                  ErrorCode = 128
                              };
                    }
                }
            }

            #endregion


            #region 确保每个一级节点下面不能超过五个状态已启用的二级菜单

            if (level == 2)
            {
                int count = bll.GetLevel2CountByMenuId(parentId, applicationId, this.CurrentUserInfo.ClientID);

                if (count >= 5 && status == 1 && (menuId == "" || string.IsNullOrEmpty(menuId)))
                {
                    throw new APIException("二级节点的数量最大为5条启用的菜单")
                          {
                              ErrorCode = 120
                          };
                }
                if (!string.IsNullOrEmpty(menuId) && count >= 5)
                {
                    var ds = bll.GetMenuDetail(menuId);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        var oldStatus = Convert.ToInt32(ds.Tables[0].Rows[0]["Status"]);
                        if (oldStatus == 0 && status == 1)   //如果已经目前已经有五个已经启用了,这个之前是没启用的,现在启用了
                        {
                            throw new APIException("二级节点的数量最大为5条启用的菜单")
                                  {
                                      ErrorCode = 130
                                  };
                        }
                    }
                }
                //取没被删除的,id
                int countDisplayCoulumn = bll.GetLevel2CountByDisplayColumn(parentId, menuId, int.Parse(displayIndex), applicationId, this.CurrentUserInfo.ClientID);
                if (countDisplayCoulumn > 0)
                {
                    throw new APIException("同一个一级菜单下的二级菜单,序号不能相同")
                          {
                              ErrorCode = 130
                          };
                }


                if (Encoding.Default.GetBytes(name).Length > 16)
                {
                    throw new APIException("二级节点的名称最多不能超过8个汉字")
                          {
                              ErrorCode = 121
                          };
                }

                //判断一级菜单的类型 如果一级菜单的类型为View改为Click

                var menuEntity = bll.QueryByEntity(new WMenuEntity()
                {
                    ID = parentId
                }, null).FirstOrDefault();

                if (menuEntity != null)
                {
                    if (menuEntity.Type == "view")
                    {
                        menuEntity.Type = "click";
                        bll.Update(menuEntity);
                    }
                }
            }
            else if (level == 1)
            {
                //判断是否有二级菜单

                var b = bll.CheckExistLevel2Menu(menuId);

                //有,type=Click

                if (b)
                {
                    type = "click";
                }

                //没有根据当前选择的点击关联到来判断Click或View
                else
                {
                    if (unionTypeId == 1 || unionTypeId == 3)
                    {
                        type = "view";
                    }
                    else if (unionTypeId == 2)
                    {
                        type = "click";
                    }
                }
                if (Encoding.Default.GetBytes(name).Length > 12)
                {
                    throw new APIException("一级节点的名称最多不能超过6个汉字")
                          {
                              ErrorCode = 122
                          };
                }
            }
            else
            {
                throw new APIException("菜单级别参数错误【Level】")
                      {
                          ErrorCode = 131
                      };
            }

            #endregion



            var    wappBll    = new WApplicationInterfaceBLL(CurrentUserInfo);
            string weixinId   = "";
            var    wappEntity = wappBll.QueryByEntity(new WApplicationInterfaceEntity()
            {
                CustomerId    = CurrentUserInfo.ClientID,
                ApplicationId = applicationId
            }, null);
            if (wappEntity.Length > 0)
            {
                weixinId = wappEntity[0].WeiXinID;
            }

            if (unionTypeId == 3)
            {
                var sysPageBll = new SysPageBLL(CurrentUserInfo);

                var pages = sysPageBll.GetPageByID(pageId);

                if (pages.Length > 0)
                {
                    var page = pages.FirstOrDefault();

                    if (page != null)
                    {
                        //获取生成的URL
                        menuUrl = page.GetUrl(pageParamJson, CurrentUserInfo.ClientID, applicationId, weixinId);
                    }
                    else
                    {
                        throw new APIException("缺少页面参数配置")
                              {
                                  ErrorCode = 141
                              };
                    }
                }
            }

            //上传图文素材
            //获取access_token/

            /**
             * var commonService = new CommonBLL();
             * var appService = new WApplicationInterfaceBLL(CurrentUserInfo);
             * var appEntity = appService.GetByID(applicationId);//
             * //var accessToken = commonService.GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, CurrentUserInfo);
             * //UploadMediaEntity media = commonService.UploadMediaFileFOREVER(accessToken.access_token, imageUrl, MediaType.Image);
             * string filePath = commonService.DownloadFile(imageUrl);
             ***/
            var wMaterialImageBll    = new WMaterialImageBLL(CurrentUserInfo);
            var wMaterialImageEntity = new WMaterialImageEntity();
            var imageId = Utils.NewGuid();

            wMaterialImageEntity.ApplicationId = applicationId;
            wMaterialImageEntity.ImageUrl      = imageUrl;
            wMaterialImageEntity.ImageId       = imageId;
            // wMaterialImageEntity.ImageName = filePath;//存物理路径,用于在微信端发送图片
            wMaterialImageBll.Create(wMaterialImageEntity);



            var           entity = new WMenuEntity();
            WMenuEntity[] wMenuEntityArrayByName;
            if (level == 1)
            {
                var wMenuEntityArraybyIndex = bll.QueryByEntity(new WMenuEntity()
                {
                    DisplayColumn = displayIndex, WeiXinID = weixinId, Level = "1"
                }, null);
                if (wMenuEntityArraybyIndex.Length != 0 && wMenuEntityArraybyIndex[0].ID != menuId)
                {
                    throw new APIException("一级菜单序号不可重复")
                          {
                              ErrorCode = 143
                          };
                }
                wMenuEntityArrayByName = bll.QueryByEntity(new WMenuEntity()
                {
                    Name = name, WeiXinID = weixinId, Level = "1"
                }, null);
                if (string.IsNullOrEmpty(menuId) || menuId == "")
                {
                    if (wMenuEntityArrayByName.Length != 0)
                    {
                        throw new APIException("菜单名称不可重复")
                              {
                                  ErrorCode = 142
                              };
                    }
                }
                else if (wMenuEntityArrayByName.Length != 0 && wMenuEntityArrayByName[0].ID != menuId)
                {
                    throw new APIException("菜单名称不可重复")
                          {
                              ErrorCode = 142
                          };
                }
            }
            if (level == 2)
            {
                wMenuEntityArrayByName = bll.QueryByEntity(new WMenuEntity()
                {
                    Name = name, WeiXinID = weixinId, Level = "2"
                }, null);
                if (string.IsNullOrEmpty(menuId) || menuId == "")
                {
                    if (wMenuEntityArrayByName.Length != 0)
                    {
                        throw new APIException("菜单名称不可重复")
                              {
                                  ErrorCode = 142
                              };
                    }
                }
                else if (wMenuEntityArrayByName.Length != 0 && wMenuEntityArrayByName[0].ID != menuId)
                {
                    throw new APIException("菜单名称不可重复")
                          {
                              ErrorCode = 142
                          };
                }
            }
            if (string.IsNullOrEmpty(menuId) || menuId == "")
            {
                var newMenuId = Utils.NewGuid().ToString();
                entity.ID             = newMenuId;
                entity.Name           = name;
                entity.ParentId       = parentId;
                entity.DisplayColumn  = displayIndex;
                entity.ImageId        = imageId; //和图片做了关联
                entity.Status         = status;
                entity.Level          = level.ToString();
                entity.MenuURL        = menuUrl;
                entity.Key            = Utils.NewGuid().Substring(0, 7);
                entity.WeiXinID       = weixinId;
                entity.Type           = type;
                entity.PageId         = pageId;
                entity.BeLinkedType   = unionTypeId;
                entity.MaterialTypeId = messageType;
                entity.Text           = text;

                bll.Create(entity);
                rd.MenuId = newMenuId;
            }
            else
            {
                if (unionTypeId == 2)
                {
                    menuUrl = null;
                }

                entity.ID             = menuId;
                entity.Name           = name;
                entity.ParentId       = parentId;
                entity.DisplayColumn  = displayIndex;
                entity.ImageId        = imageId;
                entity.Status         = status;
                entity.MaterialTypeId = messageType;
                entity.MenuURL        = menuUrl;
                entity.Key            = Utils.NewGuid().Substring(0, 7);
                entity.Level          = level.ToString();
                entity.WeiXinID       = weixinId;
                entity.Type           = type;
                entity.PageId         = pageId;
                entity.Text           = text;
                entity.BeLinkedType   = unionTypeId;
                bll.Update(entity);

                rd.MenuId = menuId;
            }

            bll.UpdateMenuData(rd.MenuId, status, pageId, pageParamJson, pageUrlJson, unionTypeId);

            #region unionTypeId 为回复消息的时候,素材类型必须有值,MenuUrl必须为空,反之 清空表中的所有素材类型,MuneUrl必须有值

            var mappingBll = new WMenuMTextMappingBLL(CurrentUserInfo);

            var mappingEntity = mappingBll.QueryByEntity(new WMenuMTextMappingEntity()
            {
                MenuId = rd.MenuId
            }, null);

            if (mappingEntity.Length > 0)
            {
                mappingBll.Delete(mappingEntity);
            }

            if (unionTypeId == 2)
            {
                if (messageType == "3")
                {
                    var textMappingEntity = new WMenuMTextMappingEntity();
                    foreach (var materialTextIdInfo in materialTextIds)
                    {
                        textMappingEntity.MappingId    = Guid.NewGuid();
                        textMappingEntity.MenuId       = rd.MenuId;
                        textMappingEntity.DisplayIndex = materialTextIdInfo.DisplayIndex;
                        textMappingEntity.TextId       = materialTextIdInfo.TestId;
                        textMappingEntity.CustomerId   = CurrentUserInfo.ClientID;
                        mappingBll.Create(textMappingEntity);
                    }
                }
            }

            #endregion

            return(rd);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: ZOSignPush.cs プロジェクト: radtek/CustomerManage
        /// <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())
                });
            }
        }
コード例 #17
0
        /// <summary>
        ///
        /// </summary>
        public string GetWQRCodeTypeData()
        {
            var billService = new WQRCodeTypeBLL(new SessionManager().CurrentUserLoginInfo);
            var wApplicationInterfaceBLL = new WApplicationInterfaceBLL(new SessionManager().CurrentUserLoginInfo);
            //IList<BillStatusModel> list = new List<BillStatusModel>();
            //list.Add(new BillStatusModel() { Id = "1", Description = "基本" });
            //list.Add(new BillStatusModel() { Id = "2", Description = "高级" });

            string key = "";

            if (Request("pid") != null && Request("pid") != string.Empty)
            {
                key = Request("pid").ToString().Trim();
            }
            string type = "";

            if (Request("type") != null && Request("type") != string.Empty)
            {
                type = Request("type").ToString().Trim();
            }

            var appId = "";

            if (type == "2")
            {
                var appObjs = wApplicationInterfaceBLL.QueryByEntity(new WApplicationInterfaceEntity()
                {
                    ApplicationId = key
                }, null);
                if (appObjs != null && appObjs.Length > 0)
                {
                    appId = appObjs[0].ApplicationId;
                }
                else
                {
                    appId = "-99";
                }
            }
            else
            {
                var appObjs = wApplicationInterfaceBLL.QueryByEntity(new WApplicationInterfaceEntity()
                {
                    WeiXinID = key
                }, null);
                if (appObjs != null && appObjs.Length > 0)
                {
                    appId = appObjs[0].ApplicationId;
                }
                else
                {
                    appId = "-99";
                }
            }

            var list = billService.GetList(new WQRCodeTypeEntity()
            {
                ApplicationId = appId
            }, 0, 1000);

            string content = string.Empty;

            var jsonData = new JsonData();

            jsonData.totalCount = list.Count.ToString();
            jsonData.data       = list;

            content = jsonData.ToJSON();
            return(content);
        }
コード例 #18
0
        public string SetVipInfoByToken(string token, string openId, LoggingSessionInfo loggionSesionInfo, HttpResponse Response)
        {
            string vipId = string.Empty;
            var    url   = "https://api.weixin.qq.com/sns/userinfo?";

            var postData = "access_token=" + token + "&openid=" + openId + "&lang=zh_CN";

            // Response.Write(url + postData);

            string method = "GET";
            // var data = HttpWebClient.DoHttpRequest(url, postData);
            var data     = CommonBLL.GetRemoteData(url + postData, method, string.Empty);
            var openInfo = data.DeserializeJSONTo <WxOpenInfoResponse>();

            if (openInfo == null)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "获取微信用户信息失败:" + data.ToJSON()
                });
                return(vipId);
            }
            else
            {
                try
                {
                    //insert into vip
                    CPOS.Common.DownloadImage downloadServer = new DownloadImage();
                    string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"];
                    var    headimgurl       = downloadServer.DownloadFile(openInfo.headimgurl, downloadImageUrl);

                    vipId = BaseService.NewGuidPub();
                    VipBLL vipServiceUnion = new VipBLL(loggionSesionInfo);

                    var vipInfo = new VipEntity();
                    vipInfo.VIPID            = vipId;
                    vipInfo.WeiXinUserId     = openId;                        //openId微信提供
                    vipInfo.City             = openInfo.city;                 //城市,微信提供
                    vipInfo.Gender           = Convert.ToInt32(openInfo.sex); //性别,微信提供
                    vipInfo.VipName          = openInfo.nickname;             //微信昵称,微信提供
                    vipInfo.VipCode          = vipServiceUnion.GetVipCode();
                    vipInfo.UnionID          = openInfo.unionid;
                    vipInfo.VipSourceId      = "3";                                        //写死
                    vipInfo.HeadImgUrl       = headimgurl;                                 //注意,需要先传到我们本地服务器,可以参考(需要download下来)
                    vipInfo.ClientID         = loggionSesionInfo.ClientID;                 //客户标识
                    vipInfo.RegistrationTime = DateTime.Now;
                    vipInfo.Status           = 0;                                          //客户没有关注
                    vipInfo.VipPasswrod      = "e10adc3949ba59abbe56e057f20f883e";         //初始密码123456
                    UnitService unitServer = new UnitService(loggionSesionInfo);
                    vipInfo.CouponInfo = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识

                    var    wappBll    = new WApplicationInterfaceBLL(loggionSesionInfo);
                    string weixinId   = "";
                    var    wappEntity = wappBll.QueryByEntity(new WApplicationInterfaceEntity()
                    {
                        CustomerId = loggionSesionInfo.ClientID
                    }, null);
                    if (wappEntity.Length > 0)
                    {
                        weixinId = wappEntity[0].WeiXinID;
                    }
                    vipInfo.WeiXin = weixinId;          //微信号码,通过数据库可以查出


                    vipServiceUnion.Create(vipInfo);
                }
                catch (Exception ex)
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "新增微信用户信息失败:" + ex.ToString()
                    });
                }

                return(vipId);
            }
        }