/// <summary>
        /// 获取渠道的二维码
        /// </summary>
        /// <param name="channelName">渠道实体</param>
        /// <returns></returns>
        private void GetQrcode(ChannelEntity entity)
        {
            //获取微信公众平台接口访问凭据
            string accessToken = AccessTokenContainer.TryGetToken(ConfigurationManager.AppSettings["appID"], ConfigurationManager.AppSettings["appsecret"]);
            //找出一个未被使用的场景值ID,确保不同渠道使用不同的场景值ID
            int scenid = GetNotUsedSmallSceneId();

            if (scenid <= 0 || scenid > 100000)
            {
                throw new Exception("抱歉,您的二维码已经用完,请删除部分后重新添加");
            }
            CreateQrCodeResult createQrCodeResult = QrCode.Create(accessToken, 0, scenid);

            if (!string.IsNullOrEmpty(createQrCodeResult.ticket))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    //根据ticket获取二维码
                    QrCode.ShowQrCode(createQrCodeResult.ticket, stream);
                    //将获取到的二维码图片转换为Base64String格式
                    byte[] imageBytes  = stream.ToArray();
                    string base64Image = System.Convert.ToBase64String(imageBytes);
                    //由于SqlServerCompact数据库限制最长字符4000,本测试项目将二维码保存到磁盘,正式项目中可直接保存到数据库
                    string imageFile = "QrcodeImage" + scenid.ToString() + ".img";
                    File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/") + imageFile, base64Image);
                    entity.Qrcode  = imageFile;
                    entity.SceneId = scenid;
                }
            }
            else
            {
                throw new Exception("抱歉!获取二维码失败");
            }
        }
        public async Task <IActionResult> UrlWithScene(string scene)
        {
            var accessToken        = _weixinAccessToken.GetToken();
            var createQrcodeResult = await QrCode.Create(accessToken, "QR_LIMIT_STR_SCENE", scene);

            return(Json(createQrcodeResult));
        }
        public async Task <IActionResult> QrcodeWithScene(string scene)
        {
            var accessToken        = _weixinAccessToken.GetToken();
            var createQrcodeResult = await QrCode.Create(accessToken, "QR_LIMIT_STR_SCENE", scene);

            var url = QrCode.ShowQrcode(createQrcodeResult.ticket);

            return(Content(url));
        }
Esempio n. 4
0
        public void TestChineseHanzuKanji()
        {
            var str = "梨阜埼茨栃";
            var bmp = QrCode.Create(str);

            bmp.Save("TestChineseHanzuKanji.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestChineseHanzuKanji.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 5
0
        public void TestArabic()
        {
            var str = "ه تعبير كان بيستخدم ";
            var bmp = QrCode.Create(str);

            bmp.Save("TestArabic.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestArabic.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 6
0
        public void TestSpecialChars()
        {
            var str = "!\"§$%&/()=??`*'Äöüä;><,.-#d+´ß";
            var bmp = QrCode.Create(str);

            bmp.Save("TestSpecialChars.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestSpecialChars.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 7
0
        public void TestGeorgisch()
        {
            var str = "აზრდოებელი დედა) თანამედროვე მნიშვნელობ";
            var bmp = QrCode.Create(str);

            bmp.Save("TestGeorgisch.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestGeorgisch.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 8
0
        public void TestNewLine()
        {
            const string str = "A\r\nB";
            var          bmp = QrCode.Create(str);

            bmp.Save("TestNewLine.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestNewLine.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 9
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btCreate_Click(object sender, EventArgs e)
        {
            var sizeItem   = this.cbSize.SelectedItem as SelectItem;
            var borderText = this.tbBorder.Text;
            var border     = 0;

            int.TryParse(borderText, out border);
            QrPicture.Image = QrCode.Create(this.tbTxt.Text, sizeItem.Value)
                              .SetColor(this.plBackground.BackColor, this.plForeground.BackColor)
                              .SetBorder(this.plBorder.BackColor, border)
                              .SetIcon(this.tbLogo.Text, this.plBackground.BackColor)
                              .GetBitmap();
        }
Esempio n. 10
0
        public void TestRussisch()
        {
            var str = "ў дачыненні да іншых скончаных";
            var bmp = QrCode.Create(str);

            bmp.Save("TestRussisch.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestRussisch.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 11
0
        public void CheckRandomCharWithPattern(QRErrorLevel errLevel)
        {
            Trace.WriteLine(errLevel);
            var    watch       = System.Diagnostics.Stopwatch.StartNew();
            int    numSuccess  = 0;
            int    numFails    = 0;
            int    sampleFail  = 0;
            double successRate = 0;
            double elapsedMs   = 0;

            for (int i = 999; i >= 0; i--)
            {
                string str = "";
                try
                {
                    var    mandant   = FakerRandom.Rand.Next(999);
                    int    anzSeiten = FakerRandom.Rand.Next(99);
                    var    numSeite  = FakerRandom.Rand.Next(anzSeiten);
                    string codGoTyp  = Lorem.GetWord();
                    string codGoNr   = Lorem.GetWord();
                    int    codHuelle = FakerRandom.Rand.Next(9999);
                    str = $"SAMDMS: MANDANT ={mandant}; NUMSEITE = {numSeite}; ANZSEITEN ={anzSeiten}; ABLAGE = (COD_GO_TYP = {codGoTyp}; COD_GO_NR ={codGoNr};COD_HUELLE ={codHuelle})";
                    var bmp = QrCode.Create(str, errLevel);
                    bmp.Save("TestRandomCharWithPattern.bmp", ImageFormat.Bmp);
                    var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);
                    emf.Save("TestRandomCharWithPattern.emf", ImageFormat.Emf);
                    var result = QrCode.ReadAsString(bmp);
                    Assert.AreEqual(str, result);
                    numSuccess++;
                }
                catch (System.Exception x)
                {
                    numFails++;
                    if (sampleFail == 0)
                    {
                        Trace.WriteLine(message: $"{x.Message} with this Input: \n{str}");
                    }
                    sampleFail = 1;
                }
            }
            successRate = System.Math.Round((double)numSuccess / (numSuccess + numFails) * 100, 2);
            Trace.WriteLine("Success: " + numSuccess + ", Fail: " + numFails);
            Trace.WriteLine("Successrate: " + successRate + "%");
            watch.Stop();

            elapsedMs = watch.ElapsedMilliseconds / 1000;
            Trace.WriteLine("Elapsed Time: " + elapsedMs);
            Trace.WriteLine("");
        }
Esempio n. 12
0
        public void TestJapaneseKatakana()
        {
            var str = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミム";
            var bmp = QrCode.Create(str);

            bmp.Save("TestJapaneseKatakana.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestJapaneseKatakana.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.IsNull(result, "This issue has been fixed by Aspose");
            var bytes = QrCode.ReadAsBinary(bmp);

            Assert.IsNull(bytes, "This issue has been fixed by Aspose");
            //Assert.AreEqual(str, result); //works with Mobile Phone
        }
Esempio n. 13
0
        public void TestJapaneseHiragana()
        {
            var str = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむ";
            var bmp = QrCode.Create(str);

            bmp.Save("TestJapaneseHiragana.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestJapaneseHiragana.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.IsNull(result, "This issue has been fixed by Aspose");
            var bytes = QrCode.ReadAsBinary(bmp);

            Assert.IsNull(bytes, "This issue has been fixed by Aspose");
            //Assert.AreEqual(str, result); //works with Mobile Phone
        }
Esempio n. 14
0
        public void TestMaxTextLength()
        {
            var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890_abcdefghijklmnopqrstuvwxyz"; //64

            QrCode.Create(str); str += str;                                               //128
            QrCode.Create(str); str += str;                                               //256
            QrCode.Create(str); str += str;                                               //512
            QrCode.Create(str); str += str;                                               //1024
            QrCode.Create(str); str += str;                                               //2048 max: 1273.
            var bmp = QrCode.Create(str, QRErrorLevel.LevelM);

            bmp.Save("TestMaxTextLength.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestMaxTextLength.emf", ImageFormat.Emf); str += str;    //4096 max: 2953
            QrCode.Create(str, QREncodeMode.AlphaNumber, QRErrorLevel.LevelL); //8192 max:
        }
Esempio n. 15
0
    /// <summary>
    /// 创建二维码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCreateQrCode_Click(object sender, EventArgs e)
    {
        string       userName   = lbPublicAccount.SelectedValue;
        string       strSceneId = txtSceneId.Text;
        QrCode       qrcode     = null;
        ErrorMessage errorMessage;

        if (cbIsTemple.Checked)
        {
            int expireSeconds = int.Parse(txtExpireSeconds.Text);
            int sceneId;
            if (int.TryParse(strSceneId, out sceneId))
            {
                qrcode = QrCode.Create(userName, expireSeconds, sceneId, out errorMessage);
            }
            else
            {
                errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "场景值id必须为整数。");
            }
        }
        else
        {
            int sceneId;
            if (int.TryParse(strSceneId, out sceneId))
            {
                qrcode = QrCode.Create(userName, sceneId, out errorMessage);
            }
            else
            {
                qrcode = QrCode.Create(userName, strSceneId, out errorMessage);
            }
        }
        if (errorMessage.IsSuccess && qrcode != null)
        {
            imgQrCode.ImageUrl = QrCode.GetUrl(qrcode.ticket);
            ltrMessage.Text    = "创建二维码成功。";
        }
        else
        {
            imgQrCode.ImageUrl = "";
            ltrMessage.Text    = string.Format("创建二维码失败。\r\n{0}", errorMessage);
        }
    }
Esempio n. 16
0
 public ActionResult MpQrCodeEditProvide()
 {
     Ocean.Entity.MpQrScene mp = new Entity.MpQrScene();
     TryUpdateModel <MpQrScene>(mp);
     if (mp.Id.ToString().StartsWith("0000"))
     {
         string token = GetAccessToken();
         int    iTemp = MpQrSceneService.GetMaxSceneId(mp.ActionName) + 1;
         try
         {
             if (mp.ActionName == 0)
             {
                 mp.TimeoutTicks = 1800;
                 mp.SceneId      = iTemp;
                 CreateQrCodeResult result = QrCode.Create(token, 1800, iTemp);
                 //QrCode.ShowQrCode(result.ticket, new MemoryStream(), WebHelper.MapPaths("~/images/Qrimg/Qr_" + iTemp.ToString() + ".jpg"));
                 //mp.ImgUrl = GlobalConfig.GetConfig()["ResourceDomain"] + "/Qrimg/Qr_" + iTemp.ToString() + ".jpg";
                 mp.ImgUrl = QrCode.ShowQrCode(result.ticket);
             }
             else
             {
                 mp.TimeoutTicks = 0;
                 mp.SceneId      = iTemp;
                 CreateQrCodeResult result = QrCode.Create(token, 0, iTemp);
                 //QrCode.ShowQrCode(result.ticket, new MemoryStream(), WebHelper.MapPaths("~/images/Qrimg/Qr_" + iTemp.ToString() + ".jpg"));
                 //mp.ImgUrl = GlobalConfig.GetConfig()["ResourceDomain"] + "/Qrimg/Qr_" + iTemp.ToString() + ".jpg";
                 mp.ImgUrl = QrCode.ShowQrCode(result.ticket);
             }
             MpQrSceneService.Insert(mp);
             return(JsonMessage(true, "生成二维码成功"));
         }
         catch (Exception e)
         {
             Log4NetImpl.Write("MpQrCodeEditProvide失败:" + e.Message);
             return(JsonMessage(false, "生成二维码失败"));
         }
     }
     else
     {
     }
     return(JsonMessage(false, "生成二维码失败"));
 }
Esempio n. 17
0
        public void TestRandomCharWithPattern2()
        {
            var    mandant   = FakerRandom.Rand.Next(999);
            int    anzSeiten = FakerRandom.Rand.Next(99);
            var    numSeite  = FakerRandom.Rand.Next(anzSeiten);
            string codGoTyp  = Lorem.GetWord();
            string codGoNr   = Lorem.GetWord();
            int    codHuelle = FakerRandom.Rand.Next(9999);
            //var str = "SAMDMS: MANDANT =181; NUMSEITE = 4; ANZSEITEN =7; ABLAGE = (COD_GO_TYP = facilis; COD_GO_NR =tempore;COD_HUELLE =3258)";
            var str = "SAMDMS: MANDANT =922; NUMSEITE = 6; ANZSEITEN =76; ABLAGE = (COD_GO_TYP = dignissimos; COD_GO_NR =qui;COD_HUELLE =6834)";
            var bmp = QrCode.Create(str);

            bmp.Save("C:\\Users\\taod\\Downloads\\TestRandomCharWithPattern.bmp", ImageFormat.Bmp);
            var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);

            emf.Save("TestRandomCharWithPattern.emf", ImageFormat.Emf);
            var result = QrCode.ReadAsString(bmp);

            Assert.AreEqual(str, result);
        }
Esempio n. 18
0
        public static void Main(string[] args)
        {
            DirectoryInfo directoryInfo = Directory.CreateDirectory("output");
            QrCode        qrCode        = new QrCode();

            using (Image <Rgba32> image = new Image <Rgba32>(qrCode.WidthInPixels, qrCode.HeightInPixels))
            {
                QrCodeBlock[,] qrCodeBlocks = qrCode.Create();

                for (int x = 0; x < qrCode.xMaxBlocks; x++)
                {
                    for (int y = 0; y < qrCode.yMaxBlocks; y++)
                    {
                        QrCodeBlock qrCodeBlock = qrCodeBlocks[x, y];
                        Draw(image, qrCodeBlock);
                    }
                }

                image.Save("output/qrCode.jpg");
            }
        }
Esempio n. 19
0
        public void TestMaxTNumberLength()
        {
            var str = "1234567890";

            QrCode.Create(str); str += str;                           //20
            QrCode.Create(str); str += str;                           //40
            QrCode.Create(str); str += str;                           //80
            QrCode.Create(str); str += str;                           //160
            QrCode.Create(str); str += str;                           //320
            QrCode.Create(str); str += str;                           //640
            QrCode.Create(str); str += str;                           //1280
            QrCode.Create(str, QREncodeMode.AlphaNumber); str += str; //2560 max: 1852
            QrCode.Create(str, QREncodeMode.Numeric); str     += str; //5120 max: 4296
            Image bmp = QrCode.Create(str, QREncodeMode.Numeric, QRErrorLevel.LevelL);

            bmp.Save("TestMaxTNumberLength.bmp", ImageFormat.Bmp);
            Image emf = QrCode.CreateEmf(str, QREncodeMode.Numeric, QRErrorLevel.LevelL);

            emf.Save("TestMaxTNumberLength.emf", ImageFormat.Emf); str += str; //10240 max: 7089.
            QrCode.Create(str, QREncodeMode.Numeric, QRErrorLevel.LevelL);     //20480
        }
Esempio n. 20
0
        /// <summary>
        /// 获取公众号二维码地址
        /// </summary>
        public string ShowQrCodeUrl(int lineId)
        {
            try
            {
                //微信用户信息
                if (!YiYouLun.Weixin.MP.CommonAPIs.AccessTokenContainer.CheckRegistered(appId))
                {
                    YiYouLun.Weixin.MP.CommonAPIs.AccessTokenContainer.Register(appId, secret);
                }
                var tokenResult        = YiYouLun.Weixin.MP.CommonAPIs.AccessTokenContainer.GetTokenResult(appId);
                var createQrCodeResult = QrCode.Create(tokenResult.access_token, 3600, lineId);
                var showQrCodeUrl      = QrCode.GetShowQrCodeUrl(createQrCodeResult.ticket);
                LoggerHelper.ToLog("CreateQrCodeResult:" + JsonConvert.SerializeObject(createQrCodeResult));
                LoggerHelper.ToLog("ShowQrCodeUrl:" + showQrCodeUrl);

                return(showQrCodeUrl);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger().Error(ex);
            }

            return("");
        }