Exemplo n.º 1
0
        /// <summary>
        /// 获取二维码图片
        /// </summary>
        /// <param name="sData"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static string GetQrCode(string sData, int size)
        {
            //二维码版本,大小获取
            Color qrCodeBackgroundColor = Color.White;
            Color qrCodeForegroundColor = Color.Black;
            int   length = System.Text.Encoding.UTF8.GetBytes(sData).Length;

            //生成二维码数据
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

            qrCodeEncoder.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H; //使用H纠错级别
            qrCodeEncoder.QRCodeVersion      = 0;
            var encodedData = qrCodeEncoder.Encode(sData, System.Text.Encoding.UTF8);

            //绘制图片
            int x = 0, y = 0;
            int w = 0, h = 0;
            // 二维码矩阵单边数据点数目
            int count = encodedData.Length;
            // 获取单个数据点边长
            double sideLength = Convert.ToDouble(size) / count;
            // 初始化背景色画笔
            SolidBrush backcolor = new SolidBrush(qrCodeBackgroundColor);
            // 初始化前景色画笔
            SolidBrush forecolor = new SolidBrush(qrCodeForegroundColor);
            // 定义画布
            Bitmap image = new Bitmap(size, size);
            // 获取GDI+绘图图画
            Graphics graph = Graphics.FromImage(image);

            // 先填充背景色
            graph.FillRectangle(backcolor, 0, 0, size, size);

            // 变量数据矩阵生成二维码
            for (int row = 0; row < count; row++)
            {
                for (int col = 0; col < count; col++)
                {
                    // 计算数据点矩阵起始坐标和宽高
                    x = Convert.ToInt32(Math.Round(col * sideLength));
                    y = Convert.ToInt32(Math.Round(row * sideLength));
                    w = Convert.ToInt32(Math.Ceiling((col + 1) * sideLength) - Math.Floor(col * sideLength));
                    h = Convert.ToInt32(Math.Ceiling((row + 1) * sideLength) - Math.Floor(row * sideLength));

                    // 绘制数据矩阵
                    graph.FillRectangle(encodedData[col][row] ? forecolor : backcolor, x, y, w, h);
                }
            }

            //添加LOGO
            string         url        = Fetch.GetUploadFileUrl("/Site/qrsmall.png");
            Bitmap         logoImage  = null;
            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);

            try
            {
                HttpWebResponse webReponse = (HttpWebResponse)webRequest.GetResponse();
                if (webReponse.StatusCode == HttpStatusCode.OK)
                {
                    using (Stream stream = webReponse.GetResponseStream())
                    {
                        System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
                        logoImage = new Bitmap(img);
                        img.Dispose();

                        if (logoImage != null)
                        {
                            image = CoverImage(image, logoImage, graph);
                            logoImage.Dispose();
                        }

                        using (MemoryStream ms = new MemoryStream())
                        {
                            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            byte[] bts     = ms.ToArray();
                            string baseImg = Convert.ToBase64String(bts);
                            image.Dispose();
                            return("data:image/jpeg;base64," + baseImg);
                        }
                    }
                }
                return("");
            }
            catch (Exception)
            {
                return("");
            }
        }
Exemplo n.º 2
0
 public static string GetYesterdayTime()
 {
     System.DateTime dateTime = System.DateTime.Now.AddDays(-1.0);
     return(Fetch.GetTimeByDate(dateTime, dateTime));
 }
Exemplo n.º 3
0
 public static string GetTodayTime()
 {
     System.DateTime now = System.DateTime.Now;
     return(Fetch.GetTimeByDate(now, now));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 删除用户cookie
 /// </summary>
 public static void DeleteUserCookie()
 {
     Fetch.SetCookie(Fetch.UC_COOKIE_LOGON_TOKEN, "");
 }
Exemplo n.º 5
0
        /// <summary>
        /// 获取老的密保回答
        /// </summary>
        /// <returns></returns>
        public static AccountsProtect GetOldProtectionInfo(int userID)
        {
            string sessionKey = string.Format("old_{0}", Fetch.GetSessionProtectionKey(userID));

            return(SessionState.Get(sessionKey) as AccountsProtect);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取老的密保回答
        /// </summary>
        /// <returns></returns>
        public static AccountsProtect GetOldProtectionInfo(int userID)
        {
            string sessionKey = string.Format("old_{0}", Fetch.GetSessionProtectionKey(userID));

            return(WHCache.Default.Get <SessionCache>(sessionKey) as AccountsProtect);
        }