/// <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);
        }
Esempio n. 2
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);
        }