Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="FilePath"></param>
        /// <param name="Logo">如何没有Logo填写null</param>
        /// <returns></returns>
        public static Bitmap CreateQR(string Url, string FilePath, Image Logo, string Text = "")
        {
            IQBLog log = new IQBLog();
            Bitmap bt  = null;

            try
            {
                string        enCodeString  = Url;
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                qrCodeEncoder.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
                qrCodeEncoder.QRCodeScale        = 4;
                qrCodeEncoder.QRCodeVersion      = 9;
                bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
                //    log.log("CreateQR qrCodeEncoder");
                Bitmap blankBK = null;
                if (!string.IsNullOrEmpty(Text))
                {
                    blankBK = ImgHelper.CreateBlankImg(bt.Width + 20, bt.Height + 60, Brushes.White);
                    bt      = ImgHelper.CombineImage(blankBK, bt, 40);
                    using (Graphics g = Graphics.FromImage(blankBK))
                    {
                        string     s    = Text;
                        Font       font = new Font("宋体", 16);
                        SolidBrush b    = new SolidBrush(Color.Black);
                        g.DrawString(s, font, b, new PointF(45, bt.Height - 45));
                    }
                }
                else
                {
                    blankBK = ImgHelper.CreateBlankImg(bt.Width + 20, bt.Height + 20, Brushes.White);
                    bt      = ImgHelper.CombineImage(blankBK, bt);
                }

                if (Logo != null)
                {
                    Logo = ImgHelper.resizeImage(Logo, new Size(60, 60));
                    if (!string.IsNullOrEmpty(Text))
                    {
                        bt = ImgHelper.CombineImage(bt, Logo, 40);
                    }
                    else
                    {
                        bt = ImgHelper.CombineImage(bt, Logo);
                    }
                }

                //   log.log("CreateQR Combine Log");
                bt.Save(FilePath);
            }
            catch (Exception ex)
            {
                log.log("CreateQR Error:" + ex.Message);
                log.log("CreateQR Error:" + ex.InnerException.Message);
                throw ex;
            }


            return(bt);
        }
Example #2
0
        public string Push()
        {
            try
            {
                string strUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + _accessToken;
                string template;

                var data = SetData();
                template = JsonConvert.SerializeObject(data);
                //  log.log("Push Template File: " + template);
                string result = HttpHelper.RequestUrlSendMsg(strUrl, HttpHelper.HttpMethod.Post, template, "application/json");
                // log.log("Push Result: " + result);

                return(result);
            }
            catch (Exception ex)
            {
                log.log("Push Error: " + ex.Message);
                log.log("Push Inner Error: " + ex.StackTrace);
            }
            return("");
        }
Example #3
0
        /// <summary>
        /// 邀请码
        /// </summary>
        /// <param name="qr"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static EQRInfo CreateMasterUrlById(EQRInfo qr, HttpContext context)
        {
            try
            {
                if (qr.ID == 0)
                {
                    throw new Exception("创建QR错误,QR ID 不存在");
                }
                string url  = "http://wx.iqianba.cn/api/wx/CreateInviteQR";
                string data = string.Format("QRId={0}&QRType={1}", qr.ID, qr.Type);
                string res  = HttpHelper.RequestUrlSendMsg(url, HttpHelper.HttpMethod.Post, data, "application/x-www-form-urlencoded");
                SSOQR  obj  = JsonConvert.DeserializeObject <SSOQR>(res);
                qr.TargetUrl = obj.TargetUrl;

                System.Drawing.Image bkImg = ImgHelper.GetImgFromUrl(qr.TargetUrl);
                string filePath            = "/Content/QR/Invite/Orig_QRInvite_" + qr.ID + ".jpg";
                qr.OrigFilePath = filePath;

                string fullPath = context.Server.MapPath(filePath);
                bkImg.Save(fullPath);

                Bitmap logo = new Bitmap(context.Server.MapPath(@"/Content/QR/Logo_AR.png"));

                Bitmap finImg = ImgHelper.ImageWatermark(new Bitmap(bkImg), logo);

                filePath    = "/Content/QR/Invite/QRInvite_" + qr.ID + ".jpg";
                qr.FilePath = filePath;
                fullPath    = context.Server.MapPath(filePath);
                finImg.Save(fullPath);

                finImg.Dispose();
                bkImg.Dispose();

                return(qr);
            }
            catch (Exception ex)
            {
                IQBLog log = new IQBLog();
                log.log("CreateMasterUrlById Error:" + ex.Message);
                throw ex;
            }
        }
Example #4
0
        /// <summary>
        /// 更新收款二维码
        /// </summary>
        /// <param name="qrUser"></param>
        /// <param name="logoUrl"></param>
        /// <returns></returns>
        public static EQRUser UpdateReceiveQR(EQRUser qrUser, string SeqNo)
        {
            try
            {
                string   filename = qrUser.OrigQRFilePath;
                string   filePath = HttpContext.Current.Server.MapPath(qrUser.OrigQRFilePath);
                FileInfo fi       = new FileInfo(filePath);


                Bitmap qrImg = new Bitmap(filePath);

                //BK
                //+ "ARUserBK1.jpg";
                string bkAdree = HttpContext.Current.Server.MapPath("/Content/QR/BK/bk_spring.jpg");
                Bitmap bkImg   = new Bitmap(bkAdree);
                Bitmap finImg  = ImgHelper.ImageWatermark(bkImg, qrImg);

                filePath  = ConfigurationManager.AppSettings["QR_ARUser_FP"];
                filename  = "BK_" + SeqNo + "_" + fi.Name;
                filePath += filename;

                finImg.Save(HttpContext.Current.Server.MapPath(filePath));
                finImg.Dispose();
                bkImg.Dispose();


                qrUser.FilePath = filePath;
            }
            catch (Exception ex)
            {
                IQBLog log = new IQBLog();
                log.log("CreateUserUrlById Error:" + ex.Message);
                throw ex;
            }

            return(qrUser);
        }
Example #5
0
        /// <summary>
        /// 收款二维码
        /// </summary>
        public static EQRUser CreateUserUrlById(EQRUser qrUser, string logoUrl = "")
        {
            try
            {
                string site = ConfigurationManager.AppSettings["IQBWX_SiteUrl"];
                string url  = site + "PP/PaySelection?Id=" + qrUser.OpenId;

                string filePath = ConfigurationManager.AppSettings["QR_ARUser_FP"];
                string filename = "QRARU_" + qrUser.ID + "_" + System.DateTime.Now.ToString("yyyyMMdd") + (new Random()).Next(1, 100).ToString()
                                  + ".jpg";

                filePath += filename;

                qrUser.OrigQRFilePath = filePath;
                //Create QR
                filePath = System.Web.HttpContext.Current.Server.MapPath(filePath);

                //Logo
                Image LogoImg = null;
                //根据头像创建收款码Logo
                //if (!string.IsNullOrEmpty(logoUrl))
                //{
                //    LogoImg = ImgHelper.GetImgFromUrl(logoUrl);
                //    LogoImg = ImgHelper.resizeImage(LogoImg, new Size(56, 56));
                //    LogoImg = ImgHelper.AddImgBorder(new Bitmap(LogoImg), 4, Color.Wheat);
                //}

                //收款码统一Logo
                string LogoAddr = HttpContext.Current.Server.MapPath("/Content/QR/ReceiveMoney_Logo.png");
                LogoImg = new Bitmap(LogoAddr);

                Bitmap qrImg = QRManager.CreateQR(url, filePath, LogoImg);


                //BK
                //+ "ARUserBK1.jpg";
                string bkAdree = HttpContext.Current.Server.MapPath("/Content/QR/BK/bk_spring.jpg");
                Bitmap bkImg   = new Bitmap(bkAdree);

                //添加文字
                using (Graphics g = Graphics.FromImage(bkImg))
                {
                    string s    = "欢迎使用支付宝付款";
                    Font   font = new Font("黑体", 12, FontStyle.Bold);

                    SolidBrush b = new SolidBrush(Color.FromArgb(50, 159, 250));

                    g.DrawString(s, font, b, new PointF(96, 125));
                }

                Bitmap finImg = ImgHelper.ImageWatermark(bkImg, qrImg);

                filePath  = ConfigurationManager.AppSettings["QR_ARUser_FP"];
                filename  = "BK_" + qrUser.ID + "_" + filename;
                filePath += filename;

                finImg.Save(HttpContext.Current.Server.MapPath(filePath));
                finImg.Dispose();
                bkImg.Dispose();


                qrUser.FilePath  = filePath;
                qrUser.TargetUrl = url;
            }
            catch (Exception ex)
            {
                IQBLog log = new IQBLog();
                log.log("CreateUserUrlById Error:" + ex.Message);
                throw ex;
            }

            return(qrUser);
        }
Example #6
0
        /// <summary>
        /// O2O入口
        /// </summary>
        public static EQRUser CreateO2OEntryQR(EQRUser qrUser)
        {
            try
            {
                string site = ConfigurationManager.AppSettings["Main_SiteUrl"];
                string url  = site + "/O2OWap/Index?aoId=" + qrUser.OpenId;

                string filePath = "/Content/QR/O2O/";
                string filename = "QRO2O_" + qrUser.ID + "_" + System.DateTime.Now.ToString("yyyyMMdd") + (new Random()).Next(1, 100).ToString()
                                  + ".jpg";

                filePath += filename;

                qrUser.OrigQRFilePath = filePath;
                //Create QR
                filePath = System.Web.HttpContext.Current.Server.MapPath(filePath);

                //Logo
                Image LogoImg = null;

                //O2O统一Logo
                string LogoAddr = HttpContext.Current.Server.MapPath("/Content/QR/O2O_Logo.png");
                LogoImg = new Bitmap(LogoAddr);

                Bitmap qrImg = QRManager.CreateQR(url, filePath, LogoImg);


                //BK
                string bkAdree = HttpContext.Current.Server.MapPath("/Content/QR/BK/bk_O2O.jpg");
                Bitmap bkImg   = new Bitmap(bkAdree);

                //添加文字
                //using (Graphics g = Graphics.FromImage(bkImg))
                //{
                //    string s = "欢迎来到O2O特惠商城";
                //    Font font = new Font("黑体", 12, FontStyle.Bold);

                //    SolidBrush b = new SolidBrush(Color.FromArgb(50, 159, 250));

                //    g.DrawString(s, font, b, new PointF(96, 125));
                //}

                Bitmap finImg = ImgHelper.ImageWatermark(bkImg, qrImg);

                filePath  = "/Content/QR/O2O/";
                filename  = "BK_" + qrUser.ID + "_" + filename;
                filePath += filename;

                finImg.Save(HttpContext.Current.Server.MapPath(filePath));
                finImg.Dispose();
                bkImg.Dispose();


                qrUser.FilePath  = filePath;
                qrUser.TargetUrl = url;
            }
            catch (Exception ex)
            {
                IQBLog log = new IQBLog();
                log.log("CreateUserUrlById Error:" + ex.Message);
                throw ex;
            }

            return(qrUser);
        }