Esempio n. 1
0
 public void SaveVShopSetting(WXShopInfo wxShop)
 {
     if (this.GetVShopSetting(wxShop.ShopId) == null)
     {
         this.AddVShopSetting(wxShop);
         return;
     }
     this.UpdateVShopSetting(wxShop);
 }
Esempio n. 2
0
 public void SaveVShopSetting(WXShopInfo wxShop)
 {
     if (GetVShopSetting(wxShop.ShopId) == null)
     {
         AddVShopSetting(wxShop);
     }
     else
     {
         UpdateVShopSetting(wxShop);
     }
 }
Esempio n. 3
0
 void AddVShopSetting(WXShopInfo vshopSetting)
 {
     if (string.IsNullOrEmpty(vshopSetting.AppId))
     {
         throw new Himall.Core.HimallException("微信AppId不能为空!");
     }
     if (string.IsNullOrEmpty(vshopSetting.AppSecret))
     {
         throw new HimallException("微信AppSecret不能为空!");
     }
     Context.WXShopInfo.Add(vshopSetting);
     Context.SaveChanges();
 }
Esempio n. 4
0
        public ActionResult BasicVShopSettings()
        {
            WXShopInfo vShopSetting = ServiceHelper.Create <IVShopService>().GetVShopSetting(base.CurrentSellerManager.ShopId) ?? new WXShopInfo();

            if (string.IsNullOrEmpty(vShopSetting.Token))
            {
                vShopSetting.Token = CreateKey(8);
            }
            ViewBag.Url    = string.Format("http://{0}/wx/index/{1}", base.Request.Url.Host, base.CurrentSellerManager.ShopId);
            ViewBag.VShop  = ServiceHelper.Create <IVShopService>().GetVShopByShopId(base.CurrentSellerManager.ShopId);
            ViewBag.ShopId = base.CurrentSellerManager.ShopId;
            return(View(vShopSetting));
        }
Esempio n. 5
0
        public JsonResult SaveVShopSettings(string weixinAppId, string weixinAppSecret, string weixinfollowUrl, string weixiToken)
        {
            Result result       = new Result();
            var    vshopSetting = new WXShopInfo();

            vshopSetting.ShopId    = CurrentSellerManager.ShopId;
            vshopSetting.AppId     = weixinAppId;
            vshopSetting.AppSecret = weixinAppSecret;
            vshopSetting.FollowUrl = weixinfollowUrl;
            vshopSetting.Token     = weixiToken;
            _iVShopService.SaveVShopSetting(vshopSetting);
            result.success = true;
            return(Json(result));
        }
 public ShakeAroundController()
 {
     _settings   = ServiceHelper.Create <IVShopService>().GetVShopSetting(base.CurrentSellerManager.ShopId);
     _saService  = ServiceHelper.Create <IShakeAroundService>();
     _poiService = ServiceHelper.Create <IPoiService>();
     try
     {
         _saService.init(_settings.AppId, _settings.AppSecret);
         _poiService.init(_settings.AppId, _settings.AppSecret);
     }
     catch
     {
         _isdeploy = false;
     }
 }
Esempio n. 7
0
        // GET: Web/WX
        public void Index(long shopId = 1)
        {
            WXShopInfo vShopSetting = ServiceHelper.Create <IVShopService>().GetVShopSetting(shopId);
            string     token        = vShopSetting.Token;
            string     echoStr      = Request.QueryString["echoStr"];

            if (CheckSignature(token))
            {
                if (!string.IsNullOrEmpty(echoStr))
                {
                    Response.Write(echoStr);
                    Response.End();
                }
            }
        }
Esempio n. 8
0
        public ActionResult ShopCouponList(long shopid)
        {
            long num;
            IEnumerable <CouponInfo> couponList = GetCouponList(shopid);
            VShopInfo vShopByShopId             = ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopid);

            if (couponList != null)
            {
                dynamic      viewBag = base.ViewBag;
                CouponInfo[] array   = couponList.ToArray();
                viewBag.CouponList =
                    from a in array
                    select new UserCouponInfo()
                {
                    ShopId      = a.ShopId,
                    CouponId    = a.Id,
                    Price       = a.Price,
                    PerMax      = a.PerMax,
                    OrderAmount = a.OrderAmount,
                    Num         = a.Num,
                    StartTime   = a.StartTime,
                    EndTime     = a.EndTime,
                    CreateTime  = a.CreateTime,
                    CouponName  = a.CouponName,
                    VShop       = vShopByShopId
                };
            }
            ViewBag.Shopid = shopid;
            dynamic obj = base.ViewBag;

            num         = (vShopByShopId != null ? vShopByShopId.Id : 0);
            obj.VShopid = num;
            if (!ServiceHelper.Create <IShopService>().IsFavoriteShop(base.CurrentUser.Id, shopid))
            {
                ViewBag.FavText = "收藏供应商";
            }
            else
            {
                ViewBag.FavText = "已收藏";
            }
            WXShopInfo vShopSetting = ServiceHelper.Create <IVShopService>().GetVShopSetting(shopid) ?? new WXShopInfo()
            {
                FollowUrl = string.Empty
            };

            ViewBag.FollowUrl = vShopSetting.FollowUrl;
            return(View());
        }
Esempio n. 9
0
 public PoiController()
 {
     _settings = ServiceHelper.Create <IVShopService>().GetVShopSetting(base.CurrentSellerManager.ShopId);
     if (_settings != null)
     {
         _poiService = ServiceHelper.Create <IPoiService>();
         try
         {
             _poiService.init(_settings.AppId, _settings.AppSecret);
         }
         catch
         {
             _isdeploy = false;
         }
     }
 }
Esempio n. 10
0
        public JsonResult SaveVShopSettings(string weixinAppId, string weixinAppSecret, string weixinfollowUrl, string weixiToken)
        {
            Result     result     = new Result();
            WXShopInfo wXShopInfo = new WXShopInfo()
            {
                ShopId    = base.CurrentSellerManager.ShopId,
                AppId     = weixinAppId,
                AppSecret = weixinAppSecret,
                FollowUrl = weixinfollowUrl,
                Token     = weixiToken
            };

            ServiceHelper.Create <IVShopService>().SaveVShopSetting(wXShopInfo);
            result.success = true;
            return(Json(result));
        }
Esempio n. 11
0
        public ActionResult ShopCouponList(long shopid)
        {
            var       coupons = GetCouponList(shopid);
            VShopInfo vshop   = _iVShopService.GetVShopByShopId(shopid);

            if (coupons != null)
            {
                ViewBag.CouponList = coupons.ToArray().Select(a => new UserCouponInfo
                {
                    ShopId        = a.ShopId,
                    CouponId      = a.Id,
                    Price         = a.Price,
                    PerMax        = a.PerMax,
                    OrderAmount   = a.OrderAmount,
                    Num           = a.Num,
                    StartTime     = a.StartTime,
                    EndTime       = a.EndTime,
                    CreateTime    = a.CreateTime,
                    CouponName    = a.CouponName,
                    VShop         = vshop,
                    ReceiveStatus = Receive(a.Id)
                }).Where(p => p.ReceiveStatus != 2 && p.ReceiveStatus != 4);//优惠券已经过期、优惠券已领完,则不显示在店铺优惠券列表中
            }
            ViewBag.Shopid  = shopid;
            ViewBag.VShopid = vshop != null ? vshop.Id : 0;
            var    isFav = _iShopService.IsFavoriteShop(CurrentUser.Id, shopid);
            string favText;

            if (isFav)
            {
                favText = "已收藏";
            }
            else
            {
                favText = "收藏店铺";
            }
            ViewBag.FavText = favText;

            WXShopInfo wxinfo = _iVShopService.GetVShopSetting(shopid) ?? new WXShopInfo()
            {
                FollowUrl = string.Empty
            };

            ViewBag.FollowUrl = wxinfo.FollowUrl;
            return(View());
        }
Esempio n. 12
0
        public ActionResult BasicVShopSettings()
        {
            var vshopSetting = _iVShopService.GetVShopSetting(CurrentSellerManager.ShopId);

            if (vshopSetting == null)
            {
                vshopSetting = new WXShopInfo();
            }
            if (string.IsNullOrEmpty(vshopSetting.Token))
            {
                vshopSetting.Token = CreateKey(8);
            }
            ViewBag.Url    = String.Format("http://{0}/m-Weixin/WXApi/{1}", Request.Url.Host, CurrentSellerManager.ShopId);
            ViewBag.VShop  = _iVShopService.GetVShopByShopId(CurrentSellerManager.ShopId);
            ViewBag.ShopId = CurrentSellerManager.ShopId;
            return(View(vshopSetting));
        }
Esempio n. 13
0
        private void UpdateVShopSetting(WXShopInfo vshopSetting)
        {
            WXShopInfo vShopSetting = this.GetVShopSetting(vshopSetting.ShopId);

            if (string.IsNullOrEmpty(vshopSetting.AppId))
            {
                throw new HimallException("微信AppId不能为空!");
            }
            if (string.IsNullOrEmpty(vshopSetting.AppSecret))
            {
                throw new HimallException("微信AppSecret不能为空!");
            }
            vShopSetting.ShopId    = vshopSetting.ShopId;
            vShopSetting.AppId     = vshopSetting.AppId;
            vShopSetting.AppSecret = vshopSetting.AppSecret;
            vShopSetting.FollowUrl = vshopSetting.FollowUrl;
            this.context.SaveChanges();
        }
Esempio n. 14
0
        void UpdateVShopSetting(WXShopInfo vshopSetting)
        {
            var wxShop = GetVShopSetting(vshopSetting.ShopId);

            if (string.IsNullOrEmpty(vshopSetting.AppId))
            {
                throw new Himall.Core.HimallException("微信AppId不能为空!");
            }
            if (string.IsNullOrEmpty(vshopSetting.AppSecret))
            {
                throw new HimallException("微信AppSecret不能为空!");
            }
            wxShop.ShopId    = vshopSetting.ShopId;
            wxShop.AppId     = vshopSetting.AppId;
            wxShop.AppSecret = vshopSetting.AppSecret;
            wxShop.FollowUrl = vshopSetting.FollowUrl;
            Context.SaveChanges();
        }
Esempio n. 15
0
        public ShakeAroundController(IVShopService iVShopService, IShakeAroundService iShakeAroundService, IPoiService iPoiService)
        {
            var _ivshop = iVShopService;

            if (CurrentSellerManager != null)
            {
                this._settings            = _ivshop.GetVShopSetting(CurrentSellerManager.ShopId);
                this._iShakeAroundService = iShakeAroundService;
                this._iPoiService         = iPoiService;
                try
                {
                    this._iShakeAroundService.init(this._settings.AppId, this._settings.AppSecret);
                    this._iPoiService.init(this._settings.AppId, this._settings.AppSecret);
                }
                catch
                {
                    this._isdeploy = false;
                }
            }
        }
Esempio n. 16
0
 public PoiController(IPoiService iPoiService, IVShopService iVShopService)
 {
     _iVShopService = iVShopService;
     if (CurrentSellerManager != null)
     {
         this._settings = _iVShopService.GetVShopSetting(CurrentSellerManager.ShopId);
         if (this._settings != null)
         {
             this._iPoiService = iPoiService;
             try
             {
                 this._iPoiService.init(this._settings.AppId, this._settings.AppSecret);
             }
             catch
             {
                 this._isdeploy = false;
             }
         }
     }
 }
Esempio n. 17
0
        public ActionResult Detail(long id, int?couponid, int?shop, bool sv = false)
        {
            IVShopService      vShopService = ServiceHelper.Create <IVShopService>();
            VShopInfo          vShop        = vShopService.GetVShop(id);
            List <SlideAdInfo> list         = ServiceHelper.Create <ISlideAdsService>().GetSlidAds(vShop.ShopId, SlideAdInfo.SlideAdType.VShopHome).ToList();
            IQueryable <MobileHomeProductsInfo> mobileHomeProductsInfos = (
                from item in ServiceHelper.Create <IMobileHomeProductsService>().GetMobileHomePageProducts(vShop.ShopId, ChemCloud.Core.PlatformType.WeiXin)
                orderby item.Sequence, item.Id descending
                select item).Take(8);
            IEnumerable <ProductItem> array =
                from item in mobileHomeProductsInfos.ToArray()
                select new ProductItem()
            {
                Id          = item.ProductId,
                ImageUrl    = item.ChemCloud_Products.GetImage(ProductInfo.ImageSize.Size_350, 1),
                Name        = item.ChemCloud_Products.ProductName,
                MarketPrice = item.ChemCloud_Products.MarketPrice,
                SalePrice   = item.ChemCloud_Products.MinSalePrice
            };
            List <BannerInfo>        bannerInfos = ServiceHelper.Create <INavigationService>().GetSellerNavigations(vShop.ShopId, ChemCloud.Core.PlatformType.WeiXin).ToList();
            IEnumerable <CouponInfo> couponList  = GetCouponList(vShop.ShopId);

            if (base.Request.UserAgent.Contains("AppWebview(iOS)"))
            {
                foreach (SlideAdInfo slideAdInfo in list)
                {
                    slideAdInfo.Url = slideAdInfo.Url.ToLower().Replace("/m-weixin", "/m-IOS").Replace("/m-wap", "/m-IOS");
                }
                foreach (BannerInfo bannerInfo in bannerInfos)
                {
                    bannerInfo.Url = bannerInfo.Url.ToLower().Replace("/m-weixin", "/m-IOS").Replace("/m-wap", "/m-IOS");
                }
            }
            dynamic viewBag = base.ViewBag;

            SlideAdInfo[] slideAdInfoArray = list.ToArray();
            viewBag.SlideAds =
                from item in slideAdInfoArray
                select new HomeSlideAdsModel()
            {
                ImageUrl = item.ImageUrl,
                Url      = item.Url
            };

            ViewBag.Banner   = bannerInfos;
            ViewBag.Products = array;
            if (base.CurrentUser != null)
            {
                ViewBag.IsFavorite = ServiceHelper.Create <IShopService>().IsFavoriteShop(base.CurrentUser.Id, vShop.ShopId);
            }
            else
            {
                ViewBag.IsFavorite = false;
            }
            WXShopInfo vShopSetting = ServiceHelper.Create <IVShopService>().GetVShopSetting(vShop.ShopId);

            if (vShopSetting != null)
            {
                ViewBag.FollowUrl = vShopSetting.FollowUrl;
            }
            ViewBag.Coupon  = couponList;
            ViewBag.VshopId = vShop.Id;
            if (couponid.HasValue)
            {
                ViewBag.AcceptId = couponid.Value;
            }
            if (!sv)
            {
                vShopService.LogVisit(id);
            }
            if (shop.HasValue)
            {
                ViewBag.IsPlatform = 1;
            }
            return(View(vShop));
        }
Esempio n. 18
0
        public ActionResult CouponInfo(long id, int?accept)
        {
            VshopCouponInfoModel model   = new VshopCouponInfoModel();
            ICouponService       service = ServiceHelper.Create <ICouponService>();
            CouponInfo           info    = service.GetCouponInfo(id) ?? new CouponInfo();

            if (info.EndTime < DateTime.Now)
            {
                model.CouponStatus = (CouponInfo.CouponReceiveStatus) 2;
            }
            if (base.CurrentUser != null)
            {
                CouponRecordQuery query = new CouponRecordQuery
                {
                    CouponId = new long?(id),
                    UserId   = new long?(base.CurrentUser.Id)
                };
                PageModel <CouponRecordInfo> couponRecordList = service.GetCouponRecordList(query);
                if ((info.PerMax != 0) && (couponRecordList.Total >= info.PerMax))
                {
                    model.CouponStatus = (CouponInfo.CouponReceiveStatus) 3;
                }
                query = new CouponRecordQuery
                {
                    CouponId = new long?(id),
                    PageNo   = 1,
                    PageSize = 0x270f
                };
                if (service.GetCouponRecordList(query).Total >= info.Num)
                {
                    model.CouponStatus = (CouponInfo.CouponReceiveStatus) 4;
                }
                if (((int)info.ReceiveType == 1) && (ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id).AvailableIntegrals < info.NeedIntegral))
                {
                    model.CouponStatus = (CouponInfo.CouponReceiveStatus) 5;
                }
                if (ServiceHelper.Create <IShopService>().IsFavoriteShop(base.CurrentUser.Id, info.ShopId))
                {
                    model.IsFavoriteShop = true;
                }
            }
            model.CouponId = id;
            if (accept.HasValue)
            {
                model.AcceptId = new int?(accept.Value);
            }
            VShopInfo vShopByShopId = ServiceHelper.Create <IVShopService>().GetVShopByShopId(info.ShopId);
            string    wxlogo        = this.wxlogo;

            if (vShopByShopId != null)
            {
                model.VShopid = vShopByShopId.Id;
                if (!string.IsNullOrWhiteSpace(vShopByShopId.WXLogo))
                {
                    wxlogo = vShopByShopId.WXLogo;
                }
                if (string.IsNullOrWhiteSpace(this.wxlogo) && !string.IsNullOrWhiteSpace(_siteSetting.WXLogo))
                {
                    wxlogo = _siteSetting.WXLogo;
                }
            }
            ((dynamic)base.ViewBag).ShopLogo = wxlogo;
            WXShopInfo vShopSetting = ServiceHelper.Create <IVShopService>().GetVShopSetting(info.ShopId);

            if (vShopSetting != null)
            {
                model.FollowUrl = vShopSetting.FollowUrl;
            }
            model.ShopId     = info.ShopId;
            model.CouponData = info;
            ((dynamic)base.ViewBag).ShopId    = model.ShopId;
            ((dynamic)base.ViewBag).FollowUrl = model.FollowUrl;
            ((dynamic)base.ViewBag).FavText   = model.IsFavoriteShop ? "己收藏" : "收藏供应商";
            ((dynamic)base.ViewBag).VShopid   = model.VShopid;
            return(View(model));
        }
Esempio n. 19
0
 public static void SaveVShopSetting(WXShopInfo wxShop)
 {
     _iVShopService.SaveVShopSetting(wxShop);
 }
Esempio n. 20
0
        public MobileOAuthUserInfo GetUserInfo(ActionExecutingContext filterContext, out string redirectUrl, WXShopInfo settings)
        {
            MobileOAuthUserInfo mobileOAuthUserInfo = null;

            redirectUrl = string.Empty;
            if (!string.IsNullOrEmpty(settings.AppId))
            {
                string item = filterContext.HttpContext.Request["code"];
                if (string.IsNullOrEmpty(item))
                {
                    string str = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", settings.AppId, HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()));
                    redirectUrl = str;
                }
                else
                {
                    string responseResult = GetResponseResult(string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", settings.AppId, settings.AppSecret, item));
                    if (responseResult.Contains("access_token"))
                    {
                        JObject  jObjects        = JsonConvert.DeserializeObject(responseResult) as JObject;
                        string[] strArrays       = new string[] { "https://api.weixin.qq.com/sns/userinfo?access_token=", jObjects["access_token"].ToString(), "&openid=", jObjects["openid"].ToString(), "&lang=zh_CN" };
                        string   responseResult1 = GetResponseResult(string.Concat(strArrays));
                        if (responseResult1.Contains("nickname"))
                        {
                            JObject             jObjects1            = JsonConvert.DeserializeObject(responseResult1) as JObject;
                            MobileOAuthUserInfo mobileOAuthUserInfo1 = new MobileOAuthUserInfo()
                            {
                                NickName      = jObjects1["nickname"].ToString(),
                                RealName      = jObjects1["nickname"].ToString(),
                                OpenId        = jObjects1["openid"].ToString(),
                                UnionId       = (jObjects1["unionid"] == null || string.IsNullOrWhiteSpace(jObjects1["unionid"].ToString()) ? jObjects1["openid"].ToString() : jObjects1["unionid"].ToString()),
                                Headimgurl    = jObjects1["headimgurl"].ToString(),
                                LoginProvider = "Himall.Plugin.OAuth.WeiXin"
                            };
                            mobileOAuthUserInfo = mobileOAuthUserInfo1;
                        }
                    }
                }
            }
            return(mobileOAuthUserInfo);
        }
        private bool ProcessInvalidUser_NormalRequest(ActionExecutingContext filterContext)
        {
            string       str;
            bool         flag        = true;
            IMobileOAuth weixinOAuth = null;

            if (base.PlatformType == ChemCloud.Core.PlatformType.WeiXin)
            {
                weixinOAuth = new WeixinOAuth();
            }
            string str1 = string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()));

            if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != ChemCloud.Core.PlatformType.WeiXin)
            {
                filterContext.Result = Redirect(str1);
            }
            else
            {
                WXShopInfo wXShopInfo = new WXShopInfo();
                string     item       = filterContext.HttpContext.Request["shop"];
                MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal;
                if (!string.IsNullOrEmpty(item))
                {
                    long num = 0;
                    long.TryParse(item, out num);
                    if (num > 0)
                    {
                        wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num);
                    }
                }
                if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret))
                {
                    WXShopInfo wXShopInfo1 = new WXShopInfo()
                    {
                        AppId     = base.CurrentSiteSetting.WeixinAppId,
                        AppSecret = base.CurrentSiteSetting.WeixinAppSecret,
                        Token     = base.CurrentSiteSetting.WeixinToken
                    };
                    wXShopInfo    = wXShopInfo1;
                    appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment;
                }
                MobileOAuthUserInfo userInfo = weixinOAuth.GetUserInfo(filterContext, out str, wXShopInfo);
                if (!string.IsNullOrWhiteSpace(str))
                {
                    filterContext.Result = Redirect(str);
                }
                else if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.OpenId))
                {
                    filterContext.Result = Redirect(str1);
                }
                else
                {
                    if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment)
                    {
                        string str2 = SecureHelper.AESEncrypt(userInfo.OpenId, "Mobile");
                        WebHelper.SetCookie("Himall-User_OpenId", str2);
                    }
                    UserMemberInfo memberByOpenId = null;
                    if (memberByOpenId == null)
                    {
                        memberByOpenId = ServiceHelper.Create <IMemberService>().GetMemberByOpenId(userInfo.LoginProvider, userInfo.OpenId);
                    }
                    if (memberByOpenId == null)
                    {
                        object[] objArray = new object[] { base.PlatformType.ToString(), userInfo.OpenId, "ChemCloud.Plugin.OAuth.WeiXin", HttpUtility.UrlEncode(userInfo.NickName), HttpUtility.UrlEncode(userInfo.RealName), HttpUtility.UrlEncode(userInfo.Headimgurl), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()), appIdTypeEnum, userInfo.UnionId };
                        str1 = string.Format("/m-{0}/Login/Entrance?openId={1}&serviceProvider={2}&nickName={3}&realName={4}&headimgurl={5}&returnUrl={6}&AppidType={7}&unionid={8}", objArray);
                        filterContext.Result = Redirect(str1);
                    }
                    else
                    {
                        string str3 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile");
                        WebHelper.SetCookie("ChemCloud-User", str3);
                    }
                }
            }
            return(flag);
        }
Esempio n. 22
0
        public void ConsistentToWeixin(long shopId)
        {
            string empty           = string.Empty;
            string weixinAppSecret = string.Empty;

            if (shopId == 0)
            {
                SiteSettingsInfo siteSettings = Instance <ISiteSettingService> .Create.GetSiteSettings();

                if (string.IsNullOrEmpty(siteSettings.WeixinAppId) || string.IsNullOrEmpty(siteSettings.WeixinAppSecret))
                {
                    throw new HimallException("您的服务号配置存在问题,请您先检查配置!");
                }
                empty           = siteSettings.WeixinAppId;
                weixinAppSecret = siteSettings.WeixinAppSecret;
            }
            if (shopId > 0)
            {
                WXShopInfo vShopSetting = Instance <IVShopService> .Create.GetVShopSetting(shopId);

                if (string.IsNullOrEmpty(vShopSetting.AppId) || string.IsNullOrEmpty(vShopSetting.AppSecret))
                {
                    throw new HimallException("您的服务号配置存在问题,请您先检查配置!");
                }
                empty           = vShopSetting.AppId;
                weixinAppSecret = vShopSetting.AppSecret;
            }
            string str = CommonApi.GetToken(empty, weixinAppSecret).access_token;
            IQueryable <MenuInfo> allMenu = GetAllMenu(shopId);

            if (allMenu == null)
            {
                throw new HimallException("你还没有添加菜单!");
            }
            List <MenuInfo> list = (
                from item in allMenu
                where item.ParentId == 0
                select item).ToList();

            foreach (MenuInfo menuInfo in list)
            {
                if (GetMenuByParentId(menuInfo.Id).Count() != 0)
                {
                    continue;
                }
                MenuInfo.UrlTypes?urlType = menuInfo.UrlType;
                if ((urlType.GetValueOrDefault() != MenuInfo.UrlTypes.Nothing ? true : !urlType.HasValue))
                {
                    continue;
                }
                throw new HimallException("你有一级菜单下没有二级菜单并且也没有绑定链接");
            }
            Menu menu = new Menu();

            foreach (MenuInfo menuInfo1 in list)
            {
                if (GetMenuByParentId(menuInfo1.Id).Count() != 0)
                {
                    SubMenu subMenu = new SubMenu()
                    {
                        name = menuInfo1.Title
                    };
                    foreach (MenuInfo menuByParentId in GetMenuByParentId(menuInfo1.Id))
                    {
                        subMenu.sub_button.Add(BuildMenu(menuByParentId));
                    }
                    menu.menu.button.Add(subMenu);
                }
                else
                {
                    menu.menu.button.Add(BuildMenu(menuInfo1));
                }
            }
            string str1 = JsonConvert.SerializeObject(menu.menu);
            string str2 = MenuApi.CreateMenus(str, str1);

            Log.Info(string.Concat("微信菜单:", str1));
            if (!str2.Contains("ok"))
            {
                Log.Info(string.Concat("微信菜单同步错误,返回内容:", str2));
                throw new HimallException("服务号配置信息错误或没有微信自定义菜单权限,请检查配置信息以及菜单的长度。");
            }
        }
        private bool BindOpenIdToUser(ActionExecutingContext filterContext)
        {
            string       str;
            bool         flag        = true;
            IMobileOAuth weixinOAuth = null;

            if (base.PlatformType == ChemCloud.Core.PlatformType.WeiXin)
            {
                weixinOAuth = new WeixinOAuth();
            }
            string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()));
            if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != ChemCloud.Core.PlatformType.WeiXin)
            {
                flag = false;
            }
            else
            {
                WXShopInfo wXShopInfo = new WXShopInfo();
                string     item       = filterContext.HttpContext.Request["shop"];
                MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal;
                if (!string.IsNullOrEmpty(item))
                {
                    long num = 0;
                    long.TryParse(item, out num);
                    if (num > 0)
                    {
                        wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num);
                    }
                }
                if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret))
                {
                    WXShopInfo wXShopInfo1 = new WXShopInfo()
                    {
                        AppId     = base.CurrentSiteSetting.WeixinAppId,
                        AppSecret = base.CurrentSiteSetting.WeixinAppSecret,
                        Token     = base.CurrentSiteSetting.WeixinToken
                    };
                    wXShopInfo    = wXShopInfo1;
                    appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment;
                }
                MobileOAuthUserInfo userInfoBequiet = weixinOAuth.GetUserInfo_bequiet(filterContext, out str, wXShopInfo);
                if (!string.IsNullOrWhiteSpace(str))
                {
                    filterContext.Result = Redirect(str);
                }
                else
                {
                    flag = false;
                    if (userInfoBequiet != null && !string.IsNullOrWhiteSpace(userInfoBequiet.OpenId))
                    {
                        if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment)
                        {
                            string str1 = SecureHelper.AESEncrypt(userInfoBequiet.OpenId, "Mobile");
                            WebHelper.SetCookie("Himall-User_OpenId", str1);
                        }
                        IMemberService memberService  = ServiceHelper.Create <IMemberService>();
                        UserMemberInfo memberByOpenId = null;
                        if (memberByOpenId == null)
                        {
                            memberByOpenId = memberService.GetMemberByOpenId(userInfoBequiet.LoginProvider, userInfoBequiet.OpenId);
                        }
                        if (memberByOpenId == null)
                        {
                            memberService.BindMember(base.CurrentUser.Id, "ChemCloud.Plugin.OAuth.WeiXin", userInfoBequiet.OpenId, appIdTypeEnum, null, userInfoBequiet.UnionId);
                        }
                        else
                        {
                            string str2 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile");
                            WebHelper.SetCookie("ChemCloud-User", str2);
                        }
                    }
                }
            }
            return(flag);
        }
Esempio n. 24
0
        public MobileOAuthUserInfo GetUserInfo_bequiet(ActionExecutingContext filterContext, out string redirectUrl, WXShopInfo settings)
        {
            MobileOAuthUserInfo mobileOAuthUserInfo = null;

            redirectUrl = string.Empty;
            if (!string.IsNullOrEmpty(settings.AppId))
            {
                string item = filterContext.HttpContext.Request["code"];
                if (string.IsNullOrEmpty(item))
                {
                    string str = filterContext.HttpContext.Request.Url.ToString();
                    str         = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", settings.AppId, HttpUtility.UrlEncode(str));
                    redirectUrl = str;
                }
                else
                {
                    string responseResult = GetResponseResult(string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", settings.AppId, settings.AppSecret, item));
                    if (responseResult.Contains("access_token"))
                    {
                        JObject             jObjects             = JsonConvert.DeserializeObject(responseResult) as JObject;
                        MobileOAuthUserInfo mobileOAuthUserInfo1 = new MobileOAuthUserInfo()
                        {
                            OpenId        = jObjects["openid"].ToString(),
                            LoginProvider = "ChemCloud.Plugin.OAuth.WeiXin",
                            UnionId       = (jObjects["unionid"] == null || string.IsNullOrWhiteSpace(jObjects["unionid"].ToString()) ? jObjects["openid"].ToString() : jObjects["unionid"].ToString())
                        };
                        mobileOAuthUserInfo = mobileOAuthUserInfo1;
                    }
                }
            }
            return(mobileOAuthUserInfo);
        }
Esempio n. 25
0
        public bool Add(WXCardLogInfo info)
        {
            string           str;
            bool             flag         = false;
            string           accessToken  = "";
            string           str1         = string.Concat("http://", WebHelper.GetHost());
            string           str2         = string.Concat(str1, "/images/defaultwxlogo.png");
            SiteSettingsInfo siteSettings = Instance <ISiteSettingService> .Create.GetSiteSettings();

            IShopService         create               = Instance <IShopService> .Create;
            IVShopService        vShopService         = Instance <IVShopService> .Create;
            CardCreateResultJson cardCreateResultJson = new CardCreateResultJson();
            Card_BaseInfoBase    cardBaseInfoBase     = new Card_BaseInfoBase()
            {
                logo_url   = str2,
                brand_name = siteSettings.SiteName,
                code_type  = Card_CodeType.CODE_TYPE_BARCODE,
                title      = info.CardTitle,
                sub_title  = info.CardSubTitle,
                color      = info.CardColor,
                notice     = string.Concat("专供", siteSettings.SiteName, "使用")
            };
            Card_BaseInfoBase cardBaseInfoBase1 = cardBaseInfoBase;

            string[] strArrays  = new string[5];
            string[] strArrays1 = strArrays;
            if (info.LeastCost > 0)
            {
                int leastCost = info.LeastCost / 100;
                str = string.Concat("满¥", leastCost.ToString("F2"), "使用");
            }
            else
            {
                str = "无门槛使用";
            }
            strArrays1[0] = str;
            strArrays[1]  = ",有效期至";
            strArrays[2]  = info.BeginTime.ToString("yyyy年MM月dd日");
            strArrays[3]  = "-";
            strArrays[4]  = info.EndTime.ToString("yyyy年MM月dd日");
            cardBaseInfoBase1.description = string.Concat(strArrays);
            Card_BaseInfo_DateInfo cardBaseInfoDateInfo = new Card_BaseInfo_DateInfo()
            {
                type            = Card_DateInfo_Type.DATE_TYPE_FIX_TIME_RANGE.ToString(),
                begin_timestamp = Senparc.Weixin.Helpers.DateTimeHelper.GetWeixinDateTime(info.BeginTime),
                end_timestamp   = Senparc.Weixin.Helpers.DateTimeHelper.GetWeixinDateTime(info.EndTime)
            };

            cardBaseInfoBase.date_info = cardBaseInfoDateInfo;
            Card_BaseInfoBase cardBaseInfoBase2 = cardBaseInfoBase;
            Card_BaseInfo_Sku cardBaseInfoSku   = new Card_BaseInfo_Sku()
            {
                quantity = (info.Quantity == 0 ? MaxStock : info.Quantity)
            };

            cardBaseInfoBase2.sku            = cardBaseInfoSku;
            cardBaseInfoBase.get_limit       = (info.GetLimit == 0 ? MaxStock : info.GetLimit);
            cardBaseInfoBase.use_custom_code = false;
            cardBaseInfoBase.bind_openid     = false;
            cardBaseInfoBase.can_share       = false;
            cardBaseInfoBase.can_give_friend = false;
            cardBaseInfoBase.custom_url_name = "立即使用";
            Card_BaseInfoBase      shopName = cardBaseInfoBase;
            Card_GeneralCouponData cardGeneralCouponDatum = new Card_GeneralCouponData()
            {
                base_info      = shopName,
                default_detail = info.DefaultDetail
            };
            Card_GeneralCouponData cardGeneralCouponDatum1 = cardGeneralCouponDatum;

            if (info.ShopId > 0)
            {
                long shopId = info.ShopId;
                shopName.custom_url = string.Concat(str1, "/Shop/Home/", shopId.ToString());
            }
            WXShopInfo vShopSetting  = vShopService.GetVShopSetting(info.ShopId);
            VShopInfo  vShopByShopId = vShopService.GetVShopByShopId(info.ShopId);
            ShopInfo   shop          = create.GetShop(info.ShopId, false);

            if (vShopSetting != null && shop != null && vShopByShopId != null && !string.IsNullOrWhiteSpace(vShopSetting.AppId) && !string.IsNullOrWhiteSpace(vShopSetting.AppSecret))
            {
                accessToken = GetAccessToken(vShopSetting.AppId, vShopSetting.AppSecret);
                if (!string.IsNullOrWhiteSpace(accessToken))
                {
                    shopName.brand_name = shop.ShopName;
                    if (!string.IsNullOrWhiteSpace(vShopByShopId.WXLogo))
                    {
                        shopName.logo_url = string.Concat(str1, vShopByShopId.WXLogo);
                    }
                    cardCreateResultJson = CardApi.CreateCard(accessToken, cardGeneralCouponDatum1, 10000);
                    if (cardCreateResultJson.errcode == ReturnCode.请求成功)
                    {
                        info.AppId     = vShopSetting.AppId;
                        info.AppSecret = vShopSetting.AppSecret;
                        info.CardId    = cardCreateResultJson.card_id;
                        flag           = true;
                    }
                }
            }
            if (!flag)
            {
                if (!string.IsNullOrWhiteSpace(siteSettings.WeixinAppId) && !string.IsNullOrWhiteSpace(siteSettings.WeixinAppSecret))
                {
                    accessToken = GetAccessToken(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret);
                    if (!string.IsNullOrWhiteSpace(accessToken))
                    {
                        shopName.brand_name = shop.ShopName;
                        if (!string.IsNullOrWhiteSpace(siteSettings.WXLogo))
                        {
                            shopName.logo_url = string.Concat(str1, siteSettings.WXLogo);
                        }
                        cardCreateResultJson = CardApi.CreateCard(accessToken, cardGeneralCouponDatum1, 10000);
                        if (cardCreateResultJson.errcode == ReturnCode.请求成功)
                        {
                            info.AppId     = siteSettings.WeixinAppId;
                            info.AppSecret = siteSettings.WeixinAppSecret;
                            info.CardId    = cardCreateResultJson.card_id;
                            flag           = true;
                        }
                    }
                }
                if (info.ShopId < 1)
                {
                    shopName.custom_url = string.Concat(str1, "/");
                }
            }
            if (flag)
            {
                info.AuditStatus = new int?(0);
                context.WXCardLogInfo.Add(info);
                context.SaveChanges();
            }
            return(flag);
        }