Пример #1
0
 /// <summary>
 /// 生成一个二维码
 /// </summary>
 /// <param name="wqt">类型</param>
 /// <returns></returns>
 private WechatQrCodes InsertOneWechatQrCodes(WechatQrCodeType wqt)
 {
     try
     {
         var ModelContext = new RabbitMPEntities();
         var e            = (int)Enum.Parse(typeof(WechatQrCodeType), wqt.ToString());
         var Max          = ModelContext.WechatQrCodes.Where(item => item.WechatQrCodeType == e).OrderByDescending(item => item.Id).FirstOrDefault();
         var newContent   = int.Parse(Max.Content) + 1;
         var newWecahatQR = new WechatQrCodes()
         {
             WechatUrl = Wechat.WechatQR.GetQrcode(
                 System.Configuration.ConfigurationManager.AppSettings["appid"],
                 System.Configuration.ConfigurationManager.AppSettings["appsecrect"],
                 wqt.ToString() + newContent
                 ),
             WechatQrCodeType = e,
             Content          = newContent.ToString(),
             CreateDateTime   = DateTime.Now
         };
         ModelContext.WechatQrCodes.Add(newWecahatQR);
         ModelContext.SaveChanges();
         return(newWecahatQR);
     }
     catch (Exception e)
     {
         var isbool = AboutLog.WriteBugLog(e);
         return(null);
     }
 }
Пример #2
0
        /// <summary>
        /// 合成图片
        /// </summary>
        /// <param name="imgUrl">二维码图片地址</param>
        /// <param name="wqt">二维码类型</param>
        /// <returns></returns>
        public Dictionary <string, string> Generate(string imgUrl, WechatQrCodeType wqt)
        {
            _bigSaveFile = _smallSaveFile = _saveFile = _saveFile + _communityId + @"\";
            var smallPath = DownOriginalImg(imgUrl, _doorId.ToString(), _saveFile, "small", wqt);

            _imgExtension = Path.GetExtension(smallPath);
            Dictionary <string, string> d = new Dictionary <string, string>
            {
                { "original", smallPath.Replace(@"D:\AllWeb", _serverPath) },
                { "small", Small(smallPath, wqt).Replace(@"D:\AllWeb", _serverPath) },
                { "big", Big(DownOriginalImg(imgUrl, _doorId.ToString(), _saveFile, "big", wqt), wqt).Replace(@"D:\AllWeb", _serverPath) }
            };

            return(d);
        }
Пример #3
0
        /// <summary>
        /// 小图片模板
        /// </summary>
        /// <param name="originalImgPath"></param>
        /// <returns></returns>
        private string Small(string originalImgPath, WechatQrCodeType wqt)
        {
            string imgBackPath      = _smallBackPath;
            string imgBackExtension = Path.GetExtension(originalImgPath);
            Image  imgBack          = Image.FromFile(imgBackPath);
            Image  img        = Image.FromFile(originalImgPath);
            Bitmap bmp        = CombinImage(imgBack, img, 37, 155, 555, 555);
            Image  wechatLogo = Image.FromFile(_wechatLog + @"wechatLog.png");

            bmp = CombinImageBig(bmp, wechatLogo, 257, 373, 120, 120);
            bmp = AddText(bmp, fontType, 40f, System.Configuration.ConfigurationManager.AppSettings["werchatSmallTitle"], 38, 720, 555, 100, true);
            bmp = AddText(bmp, fontType, 50f, _communityName, 35, 50, 555, 100, true);
            bmp = UpdateResolution(bmp, 300f, 300f);
            MemoryStream ms = new MemoryStream();

            Directory.CreateDirectory(_smallSaveFile + @"small\");
            _smallSaveFile = _smallSaveFile + @"small\" + wqt.ToString() + "-" + _doorId + _imgExtension;
            bmp.Save(_smallSaveFile, ImageFormat.Jpeg);
            return(_smallSaveFile);
        }
Пример #4
0
        /// <summary>
        /// 大图片模板
        /// </summary>
        private string Big(string originalImgPath, WechatQrCodeType wqt)
        {
            string imgBackPath      = _bigBackPath;
            string imgBackExtension = Path.GetExtension(originalImgPath);
            Image  imgBack          = Image.FromFile(imgBackPath);
            Image  img        = Image.FromFile(originalImgPath);
            Bitmap bmp        = CombinImage(imgBack, img, 574, 468, 340, 340);
            Image  wechatLogo = Image.FromFile(_wechatLog + @"wechatLog.png");

            bmp = CombinImageBig(bmp, wechatLogo, 705, 599, 80, 80);
            bmp = AddText(bmp, fontType, 35f, System.Configuration.ConfigurationManager.AppSettings["werchatQRTitle"], 575, 400, 340, 200, true);
            bmp = AddText(bmp, fontType, 28f, _doorName, 570, 820, 340, 200, true);
            bmp = AddText(bmp, fontType, 23f, _communityName, 680, 1290, 300, 100, false);
            bmp = AddText(bmp, fontType, 23f, System.Configuration.ConfigurationManager.AppSettings["communityNameNextText"], 680, 1330, 300, 100, false);
            bmp = PicSized(bmp, 1122, 1674);
            bmp = UpdateResolution(bmp, 300f, 300f);
            MemoryStream ms = new MemoryStream();

            Directory.CreateDirectory(_bigSaveFile + @"big\");
            _bigSaveFile = _bigSaveFile + @"big\" + wqt.ToString() + "-" + _doorId + _imgExtension;
            bmp.Save(_bigSaveFile, ImageFormat.Jpeg);
            return(_bigSaveFile);
        }
Пример #5
0
        /// <summary>
        /// 下载原始二维码图片
        /// </summary>
        /// <param name="url">二维码地址</param>
        /// <param name="name">id</param>
        /// <param name="savePath">保存基地址</param>
        /// <param name="firstName">名称前缀</param>
        /// <param name="wqt">二维码类型</param>
        /// <returns></returns>
        private string DownOriginalImg(string url, string name, string savePath, string firstName, WechatQrCodeType wqt)
        {
            WebClient myWebClient = new WebClient();

            Directory.CreateDirectory(savePath + @"Original\");
            var path = savePath + @"Original\" + firstName + "-" + wqt.ToString() + "-" + name + ".jpg";

            myWebClient.DownloadFile(new Uri(url), path);
            myWebClient.Dispose();
            return(path);
        }