Ejemplo n.º 1
0
        public ActionResult Index()
        {
            string str;

            ViewBag.WeiXin = false;
            if (!string.IsNullOrWhiteSpace(_siteSetting.WeixinAppId) && !string.IsNullOrWhiteSpace(_siteSetting.WeixinAppSecret) && base.PlatformType == ChemCloud.Core.PlatformType.WeiXin)
            {
                ViewBag.WeiXin = true;
                string        empty        = string.Empty;
                IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
                empty = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
                JSSDKHelper jSSDKHelper = new JSSDKHelper();
                string      timestamp   = JSSDKHelper.GetTimestamp();
                string      noncestr    = JSSDKHelper.GetNoncestr();
                string      signature   = jSSDKHelper.GetSignature(empty, noncestr, timestamp, base.Request.Url.AbsoluteUri);
                ViewBag.Timestamp = timestamp;
                ViewBag.NonceStr  = noncestr;
                ViewBag.Signature = signature;
                ViewBag.AppId     = _siteSetting.WeixinAppId;
            }
            long                        id = base.CurrentUser.Id;
            UserInviteModel             memberInviteInfo   = ServiceHelper.Create <IMemberInviteService>().GetMemberInviteInfo(id);
            InviteRuleInfo              inviteRule         = ServiceHelper.Create <IMemberInviteService>().GetInviteRule();
            MemberIntegralExchangeRules integralChangeRule = ServiceHelper.Create <IMemberIntegralService>().GetIntegralChangeRule();

            if (integralChangeRule != null)
            {
                dynamic viewBag = base.ViewBag;
                int     value   = inviteRule.InviteIntegral.Value / integralChangeRule.IntegralPerMoney;
                viewBag.IntergralMoney = value.ToString("f2");
            }
            string host = base.Request.Url.Host;
            string str1 = host;

            if (base.Request.Url.Port != 80)
            {
                int port = base.Request.Url.Port;
                str = string.Concat(":", port.ToString());
            }
            else
            {
                str = "";
            }
            host = string.Concat(str1, str);
            memberInviteInfo.InviteLink = string.Format("http://{0}/Register/index/{1}", host, id);
            inviteRule.ShareIcon        = string.Format("http://{0}{1}", host, inviteRule.ShareIcon);
            Bitmap       bitmap       = QRCodeHelper.Create(memberInviteInfo.InviteLink);
            MemoryStream memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Gif);
            string str2 = string.Concat("data:image/gif;base64,", Convert.ToBase64String(memoryStream.ToArray()));

            memoryStream.Dispose();
            memberInviteInfo.QR = str2;
            Tuple <UserInviteModel, InviteRuleInfo, UserMemberInfo> tuple = new Tuple <UserInviteModel, InviteRuleInfo, UserMemberInfo>(memberInviteInfo, inviteRule, base.CurrentUser);

            return(View(tuple));
        }
Ejemplo n.º 2
0
        private void SetShareData()
        {
            IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
            string        ticket       = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
            JSSDKHelper   jSSDKHelper  = new JSSDKHelper();
            string        timestamp    = JSSDKHelper.GetTimestamp();
            string        noncestr     = JSSDKHelper.GetNoncestr();
            string        signature    = jSSDKHelper.GetSignature(ticket, noncestr, timestamp, base.Request.Url.AbsoluteUri);

            ViewBag.Timestamp = timestamp;
            ViewBag.NonceStr  = noncestr;
            ViewBag.Signature = signature;
            ViewBag.AppId     = _siteSetting.WeixinAppId;
        }
Ejemplo n.º 3
0
        public ActionResult HasReceive(long id)
        {
            IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
            string        ticket       = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
            JSSDKHelper   jSSDKHelper  = new JSSDKHelper();
            string        timestamp    = JSSDKHelper.GetTimestamp();
            string        noncestr     = JSSDKHelper.GetNoncestr();
            string        signature    = jSSDKHelper.GetSignature(ticket, noncestr, timestamp, base.Request.Url.AbsoluteUri);

            ViewBag.Timestamp = timestamp;
            ViewBag.NonceStr  = noncestr;
            ViewBag.Signature = signature;
            ViewBag.AppId     = _siteSetting.WeixinAppId;
            BonusModel bonusModel = new BonusModel(_bonusService.Get(id))
            {
            };

            bonusModel.ImagePath = string.Concat("http://", base.Request.Url.Host.ToString(), bonusModel.ImagePath);

            return(View(bonusModel));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取微信票据
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="secret"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public string GetTicket(string appid, string secret, string type = "jsapi")
        {
            string result = "";

            if (type == "jsapi")
            {
                result = ser_wxapi.GetTicket(appid, secret);
            }
            else
            {
                try
                {
                    result = GetTicketByToken(GetAccessToken(appid, secret), type);
                }
                catch (Exception e)
                {
                    Log.Info("请求Ticket出错,强制刷新acess_token", e);
                    result = GetTicketByToken(GetAccessToken(appid, secret, true), type);
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        public string GetTicket(string appid, string secret, string type = "jsapi")
        {
            string ticketByToken = "";

            if (type != "jsapi")
            {
                try
                {
                    ticketByToken = GetTicketByToken(GetAccessToken(appid, secret, false), type, false);
                }
                catch (Exception exception)
                {
                    Log.Info("请求Ticket出错,强制刷新acess_token", exception);
                    ticketByToken = GetTicketByToken(GetAccessToken(appid, secret, true), type, false);
                }
            }
            else
            {
                ticketByToken = ser_wxapi.GetTicket(appid, secret);
            }
            return(ticketByToken);
        }
Ejemplo n.º 6
0
        public ActionResult Completed(long id, string openId = "", [DecimalConstant(0, 0, 0, 0, 0)] decimal price = default(decimal))
        {
            IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
            string        ticket       = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
            JSSDKHelper   jSSDKHelper  = new JSSDKHelper();
            string        timestamp    = JSSDKHelper.GetTimestamp();
            string        noncestr     = JSSDKHelper.GetNoncestr();
            string        signature    = jSSDKHelper.GetSignature(ticket, noncestr, timestamp, base.Request.Url.AbsoluteUri);

            ViewBag.Timestamp = timestamp;
            ViewBag.NonceStr  = noncestr;
            ViewBag.Signature = signature;
            ViewBag.AppId     = _siteSetting.WeixinAppId;
            ViewBag.Price     = price;
            BonusModel bonusModel = new BonusModel(_bonusService.Get(id))
            {
            };

            bonusModel.ImagePath = string.Concat("http://", base.Request.Url.Host.ToString(), bonusModel.ImagePath);

            ViewBag.OpenId = openId;
            return(View(bonusModel));
        }
Ejemplo n.º 7
0
        public ActionResult Index(long id)
        {
            ActionResult actionResult;

            if (base.PlatformType != ChemCloud.Core.PlatformType.WeiXin)
            {
                return(base.Content("只能在微信端访问"));
            }
            BonusInfo bonusInfo = _bonusService.Get(id);

            if (bonusInfo == null)
            {
                return(Redirect("/m-weixin/Bonus/Invalidtwo"));
            }
            BonusModel             bonusModel  = new BonusModel(bonusInfo);
            string                 item        = base.HttpContext.Request["code"];
            OAuthAccessTokenResult accessToken = null;

            if (string.IsNullOrEmpty(item))
            {
                string absoluteUri  = base.Request.Url.AbsoluteUri;
                string authorizeUrl = OAuthApi.GetAuthorizeUrl(_siteSetting.WeixinAppId.Trim(), absoluteUri, "123321#wechat_redirect", OAuthScope.snsapi_base, "code");
                return(Redirect(authorizeUrl));
            }
            try
            {
                accessToken = OAuthApi.GetAccessToken(_siteSetting.WeixinAppId.Trim(), _siteSetting.WeixinAppSecret.Trim(), item, "authorization_code");
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                actionResult = base.Content(((exception.InnerException == null ? exception : exception.InnerException)).Message);
                return(actionResult);
            }
            if (bonusModel.Type == BonusInfo.BonusType.Attention)
            {
                throw new Exception("红包异常");
            }
            if (bonusModel.EndTime <= DateTime.Now || bonusModel.IsInvalid)
            {
                return(Redirect(string.Concat("/m-weixin/Bonus/Invalid/", bonusModel.Id)));
            }
            if (bonusModel.StartTime > DateTime.Now)
            {
                object[] objArray = new object[] { "/m-weixin/Bonus/NotStart/", bonusModel.Id, "?openId=", accessToken.openid };
                return(Redirect(string.Concat(objArray)));
            }
            IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
            string        ticket       = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
            JSSDKHelper   jSSDKHelper  = new JSSDKHelper();
            string        timestamp    = JSSDKHelper.GetTimestamp();
            string        noncestr     = JSSDKHelper.GetNoncestr();
            string        signature    = jSSDKHelper.GetSignature(ticket, noncestr, timestamp, base.Request.Url.AbsoluteUri);

            ViewBag.Timestamp    = timestamp;
            ViewBag.NonceStr     = noncestr;
            ViewBag.Signature    = signature;
            ViewBag.AppId        = _siteSetting.WeixinAppId;
            ViewBag.OpenId       = accessToken.openid;
            bonusModel.ImagePath = string.Concat("http://", base.Request.Url.Host.ToString(), bonusModel.ImagePath);
            return(View(bonusModel));
        }
Ejemplo n.º 8
0
        public ActionResult PaymentToOrders(string ids)
        {
            Log.Info(string.Concat("ids = ", ids));
            Dictionary <long, ShopBonusInfo> nums = new Dictionary <long, ShopBonusInfo>();
            string str = string.Concat("http://", base.Request.Url.Host.ToString(), "/m-weixin/shopbonus/index/");

            if (!string.IsNullOrEmpty(ids))
            {
                string[]    strArrays  = ids.Split(new char[] { ',' });
                List <long> nums1      = new List <long>();
                string[]    strArrays1 = strArrays;
                for (int i = 0; i < strArrays1.Length; i++)
                {
                    nums1.Add(long.Parse(strArrays1[i]));
                }
                IShopBonusService shopBonusService = ServiceHelper.Create <IShopBonusService>();
                foreach (OrderInfo order in ServiceHelper.Create <IOrderService>().GetOrders(nums1.AsEnumerable <long>()))
                {
                    Log.Info(string.Concat("ShopID = ", order.ShopId));
                    ShopBonusInfo byShopId = shopBonusService.GetByShopId(order.ShopId);
                    if (byShopId == null)
                    {
                        continue;
                    }
                    Log.Info(string.Concat("商家活动价格:", byShopId.GrantPrice));
                    Log.Info(string.Concat("买家支付价格:", order.OrderTotalAmount));
                    if (byShopId.GrantPrice > order.OrderTotalAmount)
                    {
                        continue;
                    }
                    long num = shopBonusService.GenerateBonusDetail(byShopId, base.CurrentUser.Id, order.Id, str);
                    Log.Info(string.Concat("生成红包组,红包Grantid = ", num));
                    nums.Add(num, byShopId);
                }
            }
            ViewBag.Path          = str;
            ViewBag.BonusGrantIds = nums;
            ViewBag.BaseAddress   = string.Concat("http://", base.Request.Url.Host.ToString());
            SiteSettingsInfo siteSettings = ServiceHelper.Create <ISiteSettingService>().GetSiteSettings();
            IWXApiService    wXApiService = ServiceHelper.Create <IWXApiService>();
            string           ticket       = wXApiService.GetTicket(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret);
            JSSDKHelper      jSSDKHelper  = new JSSDKHelper();
            string           timestamp    = JSSDKHelper.GetTimestamp();
            string           noncestr     = JSSDKHelper.GetNoncestr();
            string           signature    = jSSDKHelper.GetSignature(ticket, noncestr, timestamp, base.Request.Url.AbsoluteUri);

            ViewBag.Timestamp = timestamp;
            ViewBag.NonceStr  = noncestr;
            ViewBag.Signature = signature;
            ViewBag.AppId     = siteSettings.WeixinAppId;
            IQueryable <OrderInfo> topOrders  = ServiceHelper.Create <IOrderService>().GetTopOrders(2147483647, base.CurrentUser.Id);
            OrderQuery             orderQuery = new OrderQuery()
            {
                Status    = new OrderInfo.OrderOperateStatus?(OrderInfo.OrderOperateStatus.Finish),
                UserId    = new long?(base.CurrentUser.Id),
                PageSize  = 2147483647,
                PageNo    = 1,
                Commented = new bool?(false)
            };
            OrderQuery orderQuery1 = orderQuery;

            ViewBag.WaitingForComments = ServiceHelper.Create <IOrderService>().GetOrders <OrderInfo>(orderQuery1, null).Total;
            ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id);
            ViewBag.AllOrders = topOrders.Count();
            base.ViewBag.WaitingForRecieve = topOrders.Count((OrderInfo item) => (int)item.OrderStatus == 3);
            base.ViewBag.WaitingForPay     = topOrders.Count((OrderInfo item) => (int)item.OrderStatus == 1);
            return(View("~/Areas/Mobile/Templates/Default/Views/Member/Orders.cshtml"));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 获取微信ticket
 /// </summary>
 public static string GetTicket(string appid, string appsecret)
 {
     return(_wxApiService.GetTicket(appid, appsecret));
 }