Ejemplo n.º 1
0
        public byte[] GetPass2(HttpContextBase context, CouponInfoResponse coupponInfo)
        {
            var generator = new PassGenerator();

            var request = new CouponPassGeneratorRequest
            {
                Identifier = ConfigurationManager.AppSettings["Identifier"],
                CertThumbprint =
                    ConfigurationManager.AppSettings["PassBookCertificateThumbprint"].Replace(" ", String.Empty),
                CertLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
                SerialNumber = coupponInfo.Id.ToString(CultureInfo.InvariantCulture),
                Description = coupponInfo.ProductDescription,
                OrganizationName = ConfigurationManager.AppSettings["OrganizationName"],
                TeamIdentifier = ConfigurationManager.AppSettings["TeamIdentifier"],
                BackgroundColor = "rgb(229,1,80)",
                ForegroundColor = "rgb(255,255,255)",
                LabelColor = "rgb(255,255,255)",
                AssociatedStoreIdentifiers = new List<int>(1)
                        {
                            ConfigManager.AppleAppid
                        }
            };
            

            // override icon and icon retina
            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(context.Server.MapPath("~/Icons/coupon/icon.png")));
            request.Images.Add(PassbookImage.Logo, System.IO.File.ReadAllBytes(context.Server.MapPath("~/Icons/coupon/logo.png")));
            request.AddBarCode(coupponInfo.CouponId, BarcodeType.PKBarcodeFormatPDF417, "iso-8859-1" /*"UTF-8"*/, coupponInfo.CouponId);
            request.SuppressStripShine = false;

            //获取品牌 ,获取 STORE
            var store = GetStore(coupponInfo);
            var brands = GetBrand(coupponInfo);

            string bName = String.Empty;
            //折扣部分
            if (brands.Count > 0)
            {
                bName = brands[0].Name;
            }

            if (coupponInfo.SourceType == (int)SourceType.Product)
            {
                request.AddPrimaryField(new StandardField("primary1", bName, coupponInfo.ProductName));
            }

            if (coupponInfo.SourceType == (int)SourceType.Promotion)
            {
                request.AddPrimaryField(new StandardField("primary1", String.Empty, coupponInfo.ProductName));
            }

            //有效期

            request.AddSecondaryField(new DateField("secondary1", "有效期", coupponInfo.ValidStartDate.ToUniversalTime(), FieldDateTimeStyle.PKDateStyleLong, FieldDateTimeStyle.PKDateStyleNone));
            //
            request.AddSecondaryField(new StandardField("secondary2", String.Empty, "-"));

            request.AddSecondaryField(new DateField("secondary3", String.Empty, coupponInfo.ValidEndDate.ToUniversalTime(), FieldDateTimeStyle.PKDateStyleLong, FieldDateTimeStyle.PKDateStyleNone));

            request.AddBackField(new StandardField("back info1", coupponInfo.ProductName, coupponInfo.ProductDescription));
            request.AddBackField(new StandardField("back info2", "有效期", String.Format("{0} - {1}", coupponInfo.ValidStartDate.ToUniversalTime().ToString("yyyy-M-d"), coupponInfo.ValidEndDate.ToUniversalTime().ToString("yyyy-M-d"))));

            if (store != null)
            {
                request.LogoText = store.Name;//couponName;

                request.AddBackField(new StandardField("address", "地址", store.Location));
                request.AddBackField(new StandardField("ad2", "联系电话", store.Tel));
                var relevantest = String.Format("您附近的{0}正在做促销,详情进店查看", store.Name);
                request.Locations.Add(
                    new Location
                    {
                        Latitude = (double)store.Latitude,
                        Longitude = (double)store.Longitude,
                        RelevantText = relevantest
                    });

                if (store.GpsLat != null && store.GpsLng != null)
                {
                    request.Locations.Add(new Location
                    {
                        Latitude = (double)store.GpsLat.Value,
                        Longitude = (double)store.GpsLng.Value,
                        RelevantText = relevantest
                    });
                }
            }

            byte[] generatedPass = generator.Generate(request);

            return generatedPass;

            //return null;
        }
Ejemplo n.º 2
0
        public byte[] GetPass2(HttpContextBase context, CouponInfoResponse coupponInfo)
        {
            var generator = new PassGenerator();

            var request = new CouponPassGeneratorRequest
            {
                Identifier     = ConfigurationManager.AppSettings["Identifier"],
                CertThumbprint =
                    ConfigurationManager.AppSettings["PassBookCertificateThumbprint"].Replace(" ", String.Empty),
                CertLocation               = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
                SerialNumber               = coupponInfo.Id.ToString(CultureInfo.InvariantCulture),
                Description                = coupponInfo.ProductDescription,
                OrganizationName           = ConfigurationManager.AppSettings["OrganizationName"],
                TeamIdentifier             = ConfigurationManager.AppSettings["TeamIdentifier"],
                BackgroundColor            = "rgb(229,1,80)",
                ForegroundColor            = "rgb(255,255,255)",
                LabelColor                 = "rgb(255,255,255)",
                AssociatedStoreIdentifiers = new List <int>(1)
                {
                    ConfigManager.AppleAppid
                }
            };


            // override icon and icon retina
            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(context.Server.MapPath("~/Icons/coupon/icon.png")));
            request.Images.Add(PassbookImage.Logo, System.IO.File.ReadAllBytes(context.Server.MapPath("~/Icons/coupon/logo.png")));
            request.AddBarCode(coupponInfo.CouponId, BarcodeType.PKBarcodeFormatPDF417, "iso-8859-1" /*"UTF-8"*/, coupponInfo.CouponId);
            request.SuppressStripShine = false;

            //获取品牌 ,获取 STORE
            var store  = GetStore(coupponInfo);
            var brands = GetBrand(coupponInfo);

            string bName = String.Empty;

            //折扣部分
            if (brands.Count > 0)
            {
                bName = brands[0].Name;
            }

            if (coupponInfo.SourceType == (int)SourceType.Product)
            {
                request.AddPrimaryField(new StandardField("primary1", bName, coupponInfo.ProductName));
            }

            if (coupponInfo.SourceType == (int)SourceType.Promotion)
            {
                request.AddPrimaryField(new StandardField("primary1", String.Empty, coupponInfo.ProductName));
            }

            //有效期

            request.AddSecondaryField(new DateField("secondary1", "有效期", coupponInfo.ValidStartDate, FieldDateTimeStyle.PKDateStyleLong, FieldDateTimeStyle.PKDateStyleNone));
            //
            request.AddSecondaryField(new StandardField("secondary2", String.Empty, "-"));

            request.AddSecondaryField(new DateField("secondary3", String.Empty, coupponInfo.ValidEndDate, FieldDateTimeStyle.PKDateStyleLong, FieldDateTimeStyle.PKDateStyleNone));

            request.AddBackField(new StandardField("back info1", coupponInfo.ProductName, coupponInfo.ProductDescription));
            request.AddBackField(new StandardField("back info2", "有效期", String.Format("{0} - {1}", coupponInfo.ValidStartDate.ToString("yyyy-M-d"), coupponInfo.ValidEndDate.ToString("yyyy-M-d"))));

            if (store != null)
            {
                request.LogoText = store.Name;//couponName;

                request.AddBackField(new StandardField("address", "地址", store.Location));
                request.AddBackField(new StandardField("ad2", "联系电话", store.Tel));
                var relevantest = String.Format("您附近的{0}正在做促销,详情进店查看", store.Name);
                request.Locations.Add(
                    new Location
                {
                    Latitude     = (double)store.Latitude,
                    Longitude    = (double)store.Longitude,
                    RelevantText = relevantest
                });

                if (store.GpsLat != null && store.GpsLng != null)
                {
                    request.Locations.Add(new Location
                    {
                        Latitude     = (double)store.GpsLat.Value,
                        Longitude    = (double)store.GpsLng.Value,
                        RelevantText = relevantest
                    });
                }
            }

            byte[] generatedPass = generator.Generate(request);

            return(generatedPass);

            //return null;
        }