예제 #1
0
        private void generate_barcode(String queryString, int width, int height, PictureBox targetPictureBox)
        {
            Regex rg = new Regex("^[0-9]{11}$");

            if (!rg.IsMatch(queryString))
            {
                // MessageBox.Show("本例子采用EAN_13编码,需要输入13位数字");
                MessageBox.Show("本例子采用EAN_11编码,需要输入11位数字");
                return;
            }

            try
            {
                MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
                ByteMatrix        bm         = mutiWriter.encode(queryString, com.google.zxing.BarcodeFormat.EAN_13, 363, 150);
                Bitmap            img        = bm.ToBitmap();
                targetPictureBox.Image = img;

                //自动保存图片到当前目录
                //string filename = System.Environment.CurrentDirectory + "\\EAN_13" + DateTime.Now.Ticks.ToString() + ".jpg";
                //img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ee)
            { MessageBox.Show(ee.Message); }
        }
예제 #2
0
        //生成条形码
        private void button1_Click(object sender, EventArgs e)
        {
            lbshow.Text = "";
            Regex rg = new Regex("^[0-9]{13}$");

            if (!rg.IsMatch(txtMsg.Text))
            {
                MessageBox.Show("本例子采用EAN_13编码,需要输入13位数字");
                return;
            }

            try
            {
                MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
                ByteMatrix        bm         = mutiWriter.encode(txtMsg.Text, com.google.zxing.BarcodeFormat.EAN_13, 363, 150);
                Bitmap            img        = bm.ToBitmap();
                pictureBox1.Image = img;

                //自动保存图片到当前目录
                string filename = System.Environment.CurrentDirectory + "\\EAN_13" + DateTime.Now.Ticks.ToString() + ".jpg";
                img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                lbshow.Text = "图片已保存到:" + filename;
            }
            catch (Exception ee)
            { MessageBox.Show(ee.Message); }
        }
예제 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
            {
                MessageBox.Show("请输入需要转换的信息!");
            }

            string content = this.textBox1.Text;
            SaveFileDialog sFD = new SaveFileDialog();
            sFD.DefaultExt = "*.png|*.png";
            sFD.AddExtension = true;            
            
            try
            {
                if (sFD.ShowDialog() == DialogResult.OK)
                {
                    //string content = @"url:http://writeblog.csdn.net/PostEdit.aspx; name:nickwar";
                    COMMON.ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 350, 350);
                    writeToFile(byteMatrix, System.Drawing.Imaging.ImageFormat.Png, sFD.FileName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #4
0
        //Look at http://code.google.com/p/zxing/wiki/BarcodeContents for formatting

        /// <summary>
        /// Returns a QRCode with the data embedded
        /// </summary>
        /// <param name="data">The data to embed in a QRCode.</param>
        public Task<ImageResult> QRCode(string data)
        {
            return AsyncHelper.RunAsync(() =>
            {
                var qrCode = new MultiFormatWriter();
                var byteIMG = qrCode.encode(data, BarcodeFormat.QR_CODE, 200, 200);
                sbyte[][] img = byteIMG.Array;
                var bmp = new Bitmap(200, 200);
                var g = Graphics.FromImage(bmp);
                g.Clear(Color.White);
                for (var y = 0; y <= img.Length - 1; y++)
                {
                    for (var x = 0; x <= img[y].Length - 1; x++)
                    {
                        g.FillRectangle(
                            img[y][x] == 0 ? Brushes.Black : Brushes.White, x, y, 1, 1);
                    }
                }

                var stream = new System.IO.MemoryStream();
                bmp.Save(stream, ImageFormat.Jpeg);
                var imageBytes = stream.ToArray();
                stream.Close();

                return this.Image(imageBytes, "image/jpeg");
            });
        }
예제 #5
0
        public void WriteQrcodeToFile(string content, string filePath)
        {
            ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 200, 200);
            Bitmap     bitmap     = toBitmap(byteMatrix);

            pictureBox1.Image = bitmap;
            writeToFile(byteMatrix, ImageFormat.Jpeg, filePath);
        }
예제 #6
0
        public static Bitmap Create(string content)
        {
            //构造二维码写码器
            MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
            ByteMatrix        bm         = mutiWriter.encode(content, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
            Bitmap            img        = bm.ToBitmap();

            return(img);
        }
예제 #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string     content    = textBox1.Text;
            ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 200, 200);
            Bitmap     bitmap     = toBitmap(byteMatrix);

            pictureBox1.Image = bitmap;
            writeToFile(byteMatrix, ImageFormat.Jpeg, "D:\\Qrcode_pic\\qr01.jpg");
        }
예제 #8
0
        private void txtContent_TextChanged(object sender, EventArgs e)
        {
            string content = txtContent.Text;

            if (content == "")
            {
                MessageBox.Show("请输入内容", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 200, 200);
            Bitmap     bitmap     = toBitmap(byteMatrix);

            orpic.Image = bitmap;
        }
예제 #9
0
        private void generate_qrcode(String queryString, Image logoImage, int size, PictureBox targetPictureBox)
        {
            try
            {
                //构造二维码写码器
                MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
                Hashtable         hint       = new Hashtable();
                hint.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
                hint.Add(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.H);
                //生成二维码
                ByteMatrix bm  = mutiWriter.encode(queryString, com.google.zxing.BarcodeFormat.QR_CODE, size, size, hint);
                Bitmap     img = bm.ToBitmap();

                //要插入到二维码中的图片
                Image middlImg = logoImage;
                //获取二维码实际尺寸(去掉二维码两边空白后的实际尺寸)
                System.Drawing.Size realSize = mutiWriter.GetEncodeSize(TrackingNumber.Text, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
                //计算插入图片的大小和位置
                int middleImgW = Math.Min((int)(realSize.Width / 3.5), middlImg.Width);
                int middleImgH = Math.Min((int)(realSize.Height / 3.5), middlImg.Height);
                int middleImgL = (img.Width - middleImgW) / 2;
                int middleImgT = (img.Height - middleImgH) / 2;

                //将img转换成bmp格式,否则后面无法创建 Graphics对象
                Bitmap bmpimg = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(bmpimg))
                {
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.DrawImage(img, 0, 0);
                }

                //在二维码中插入图片
                System.Drawing.Graphics MyGraphic = System.Drawing.Graphics.FromImage(bmpimg);
                //白底
                MyGraphic.FillRectangle(Brushes.White, middleImgL, middleImgT, middleImgW, middleImgH);
                MyGraphic.DrawImage(middlImg, middleImgL, middleImgT, middleImgW, middleImgH);

                targetPictureBox.Image = bmpimg;

                //自动保存图片到当前目录
                //string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";
                //bmpimg.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                //lbshow.Text = "图片已保存到:" + filename;
            }
            catch (Exception ee)
            { MessageBox.Show(ee.Message); }
        }
예제 #10
0
        //生成二维码
        private void button2_Click(object sender, EventArgs e)
        {
            lbshow.Text = "";
            try
            {
                MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
                ByteMatrix        bm         = mutiWriter.encode(txtMsg.Text, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
                Bitmap            img        = bm.ToBitmap();
                pictureBox1.Image = img;

                //自动保存图片到当前目录
                string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";
                img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                lbshow.Text = "图片已保存到:" + filename;
            }
            catch (Exception ee)
            { MessageBox.Show(ee.Message); }
        }
예제 #11
0
        public static Bitmap Create(string content, Image centralImage)
        {
            //构造二维码写码器
            MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
            Hashtable         hint       = new Hashtable();

            hint.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
            hint.Add(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.H);
            //生成二维码
            ByteMatrix bm  = mutiWriter.encode(content, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300, hint);
            Bitmap     img = bm.ToBitmap();

            //要插入到二维码中的图片
            Image middlImg = centralImage;
            //获取二维码实际尺寸(去掉二维码两边空白后的实际尺寸)
            //  System.Drawing.Size realSize = mutiWriter.GetEncodeSize(content, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
            var realSize = mutiWriter.encode(content, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
            //计算插入图片的大小和位置
            int middleImgW = Math.Min((int)(realSize.Width / 3.5), middlImg.Width);
            int middleImgH = Math.Min((int)(realSize.Height / 3.5), middlImg.Height);
            int middleImgL = (img.Width - middleImgW) / 2;
            int middleImgT = (img.Height - middleImgH) / 2;

            //将img转换成bmp格式,否则后面无法创建 Graphics对象
            Bitmap bmpimg = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bmpimg))
            {
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.DrawImage(img, 0, 0);
            }

            //在二维码中插入图片
            System.Drawing.Graphics MyGraphic = System.Drawing.Graphics.FromImage(bmpimg);
            //白底
            MyGraphic.FillRectangle(Brushes.White, middleImgL, middleImgT, middleImgW, middleImgH);
            MyGraphic.DrawImage(middlImg, middleImgL, middleImgT, middleImgW, middleImgH);

            return(bmpimg);
        }
예제 #12
0
        public override void Draw(Graphics g, List<Matrix> listMatrix)
        {
            //单位一定要是MM。
            g.PageUnit = GraphicsUnit.Millimeter;
            //如下的这个是偏移些位置

            //如下是先从绘制矩形中的拷贝的,然后再修改
            if (Route != 0)
            {
                PointF pZhongXin = getCentrePoint();
                g.TranslateTransform(pZhongXin.X, pZhongXin.Y, MatrixOrder.Prepend);
                g.RotateTransform((float)Route);
                g.TranslateTransform(-pZhongXin.X, -pZhongXin.Y);
            }

            //定义画笔
            Pen _myPen = new Pen(PenColor, _penWidth);
            _myPen.DashStyle = PenDashStyle;

            #region

            string strBarcodeNumber = "";

            //如果设置变量名,就用变量名的对应的变量值。
            if (_strVarName != "")
            {
                strBarcodeNumber = _strVarValue;
                //_strBarcodeNumber = "";

            }
            else//如果没有变量名就用默认的值
            {
                strBarcodeNumber = _strBarcodeNumber;
            }

            if (strBarcodeNumber == "")
                return;

            //条形码可能有异常,比如说位数不符等等
            try
            {

                RectangleF rect = getGraphicsPath(listMatrix).GetBounds();
                float fltx = rect.X;
                float flty = rect.Y;
                float fltw = rect.Width;
                float flth = rect.Height;

                /**
                float fltx = _X + _XAdd;
                float flty = _Y + _YAdd;
                float fltw = _Width + _WidthAdd;
                float flth = _Height + _HeightAdd;
                 * */

                PointF poingStr = new PointF(fltx, flty);//实际位置

                int intBarCodeWidth = (int)(fltw * g.DpiX / 25.4);
                int intBarCodeHeight = (int)(flth * g.DpiY / 25.4);
                ;
                string strEncoding = _BarcodeEncoding;
                BarcodeLib.TYPE myType = BarcodeLib.TYPE.EAN13;
                switch (_BarcodeEncoding)
                {
                    case "EAN13":
                        myType = BarcodeLib.TYPE.EAN13;
                        break;
                    case "EAN8":
                        myType = BarcodeLib.TYPE.EAN8;
                        break;
                    case "FIM":
                        myType = BarcodeLib.TYPE.FIM;
                        break;
                    case "Codabar":
                        myType = BarcodeLib.TYPE.Codabar;
                        break;
                    case "UPCA":
                        myType = BarcodeLib.TYPE.UPCA;
                        break;
                    case "UPCE":
                        myType = BarcodeLib.TYPE.UPCE;
                        break;
                    case "UPC_SUPPLEMENTAL_2DIGIT":
                        myType = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT;
                        break;
                    case "UPC_SUPPLEMENTAL_5DIGIT":
                        myType = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT;
                        break;
                    case "CODE39":
                        myType = BarcodeLib.TYPE.CODE39;
                        break;
                    case "CODE39Extended":
                        myType = BarcodeLib.TYPE.CODE39Extended;
                        break;
                    case "CODE128":
                        myType = BarcodeLib.TYPE.CODE128;
                        break;
                    case "CODE128A":
                        myType = BarcodeLib.TYPE.CODE128A;
                        break;
                    case "CODE128B":
                        myType = BarcodeLib.TYPE.CODE128B;
                        break;
                    case "CODE128C":
                        myType = BarcodeLib.TYPE.CODE128C;
                        break;
                    case "ISBN":
                        myType = BarcodeLib.TYPE.ISBN;
                        break;
                    case "Interleaved2of5":
                        myType = BarcodeLib.TYPE.Interleaved2of5;
                        break;
                    case "Standard2of5":
                        myType = BarcodeLib.TYPE.Standard2of5;
                        break;
                    case "Industrial2of5":
                        myType = BarcodeLib.TYPE.Industrial2of5;
                        break;
                    case "PostNet":
                        myType = BarcodeLib.TYPE.PostNet;
                        break;
                    case "BOOKLAND":
                        myType = BarcodeLib.TYPE.BOOKLAND;
                        break;
                    case "JAN13":
                        myType = BarcodeLib.TYPE.JAN13;
                        break;
                    case "MSI_Mod10":
                        myType = BarcodeLib.TYPE.MSI_Mod10;
                        break;
                    case "MSI_2Mod10":
                        myType = BarcodeLib.TYPE.MSI_2Mod10;
                        break;
                    case "MSI_Mod11":
                        myType = BarcodeLib.TYPE.MSI_Mod11;
                        break;
                    case "MSI_Mod11_Mod10":
                        myType = BarcodeLib.TYPE.MSI_Mod11_Mod10;
                        break;
                    case "Modified_Plessey":
                        myType = BarcodeLib.TYPE.Modified_Plessey;
                        break;
                    case "CODE11":
                        myType = BarcodeLib.TYPE.CODE11;
                        break;
                    case "USD8":
                        myType = BarcodeLib.TYPE.USD8;
                        break;
                    case "UCC12":
                        myType = BarcodeLib.TYPE.UCC12;
                        break;
                    case "UCC13":
                        myType = BarcodeLib.TYPE.UCC13;
                        break;
                    case "LOGMARS":
                        myType = BarcodeLib.TYPE.LOGMARS;
                        break;
                    case "ITF14":
                        myType = BarcodeLib.TYPE.ITF14;
                        break;
                    case "TELEPEN":
                        myType = BarcodeLib.TYPE.TELEPEN;
                        break;
                    case "QR_CODE":
                        //如下得判断长度和宽度是否可以显示,我得茶皂他们最短需要多少。
                        if ((intBarCodeWidth < 21) || (intBarCodeHeight < 21))
                        {
                            g.DrawString("图像太小显示不了", new Font("Arial", 6), new SolidBrush(Color.Black), poingStr);
                            g.DrawRectangle(new Pen(Color.Black, 0.5f), fltx, flty, fltw, flth);
                        }
                        else
                        {
                            //只有在这两个中有一个不相等的情况下才需要更新。
                            if ((_fltOldW != _Width) || (_fltOldh != _Height) || isChangeed)
                            {
                                isChangeed = false;//重新设置成没有更新。

                                _fltOldW = _Width;
                                _fltOldh = _Height;

                                Hashtable hints = new Hashtable();
                                //hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);//容错能力

                                hints.Add(EncodeHintType.ERROR_CORRECTION, _QRCODEErrorLevel);//设置容错率

                                //如下是读取编码,只有在这个不为空的时候才选择
                                if (_strLanguageEncodingName != "")
                                {
                                    hints.Add(EncodeHintType.CHARACTER_SET, _strLanguageEncodingName);//字符集
                                }

                                COMMON.ByteMatrix byteMatrix = new MultiFormatWriter().encode(strBarcodeNumber, BarcodeFormat.QR_CODE, intBarCodeWidth, intBarCodeHeight, hints);
                                _imageOld = toBitmap(byteMatrix, g.DpiX, g.DpiY);
                                g.DrawImage(_imageOld, rect);

                            }
                            else//如果没有更新,就直接绘图就可以了。
                            {
                                g.DrawImage(_imageOld, rect);
                            }

                        }
                        return;//这个是直接返回的。因为下边的是调用的一维码的程序
                }

                BarcodeLib.Barcode bar = new BarcodeLib.Barcode();

                bar.IncludeLabel = _isIncludeLabel;
                bar.LabelFont = _RealFont;
                bar.LabelPosition = LabelPosition;//条形码文字的位置

                //不能少于这个大小
                /**因为跟放大缩小相冲突,所以注释掉了,如果图像小,就显示显示不了。
                if (intBarCodeWidth < 100)
                {
                    intBarCodeWidth = 100;
                    _Width = intBarCodeWidth / g.DpiX * 25.4f;
                    _WidthAdd = 0;
                }
                if (intBarCodeHeight < 30)
                {
                    intBarCodeHeight = 30;
                    _Height = intBarCodeHeight / g.DpiY * 25.4f;
                    _HeightAdd = 0;
                }
                 * */

                if ((intBarCodeWidth < 100) || (intBarCodeHeight < 30))
                {
                    g.DrawString("图像太小显示不了", new Font("Arial", 6), new SolidBrush(Color.Black), poingStr);
                    g.DrawRectangle(new Pen(Color.Black, 0.5f), fltx, flty, fltw, flth);
                }
                else
                {

                    Image myImage = bar.Encode(myType, strBarcodeNumber, intBarCodeWidth, intBarCodeHeight, g.DpiX, g.DpiY);
                    //将最新的宽度更新。好像不用更新。
                    g.DrawImage(myImage, rect);

                }

                bar.Dispose();

            }
            catch (Exception e)
            {
                //因为这个Draw是持续刷新的,为了在条形码数字出错是只提示依次,在此需要这个,而我在条形码数字更改的时候,重新设置那个为空了
                if (_strBarcodeErrorMessage != e.Message)
                {
                    _strBarcodeErrorMessage = e.Message;
                    MessageBox.Show(e.Message);
                    return;
                }

            }

            #endregion

            //throw new NotImplementedException();

            g.ResetTransform();//恢复原先的坐标系。

            //base.Draw(g, arrlistMatrix);
        }
예제 #13
0
        private void CreateQRCodeByZXingAPI()
        {
            int intWidth=300;
            ByteMatrix byteMatrix;

            if (rdbManualSize.Checked)
                intWidth = (int)nudManualSize.Value;
            else if (rdb80.Checked)
                intWidth = 80;
            else if (rdb100.Checked)
                intWidth = 100;
            else if (rdb125.Checked)
                intWidth = 125;
            else if (rdb200.Checked)
                intWidth = 200;
            else if (rdb250.Checked)
                intWidth = 250;
            else if (rdb300.Checked)
                intWidth = 300;
            else if (rdb400.Checked)
                intWidth = 400;
            else if (rdb500.Checked)
                intWidth = 500;

            try
            {
                byteMatrix = new MultiFormatWriter().encode(txtText.Text, BarcodeFormat.QR_CODE, intWidth, intWidth);
                picCode.Image = byteMatrix.ToBitmap();
            }
            catch (Exception)
            {
                picCode.Image = picCode.ErrorImage;
            }
        }
예제 #14
0
        void setQRcode(string content)
        {
            int heigth = this.pictureBox1.Height;
            int width = this.pictureBox1.Width;
            BarcodeFormat format = BarcodeFormat.QR_CODE;

            ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, format, width, heigth);
            Bitmap bitmap = toBitmap(byteMatrix);
            pictureBox1.Image = bitmap;
        }
예제 #15
0
파일: Util.cs 프로젝트: eagledu/wedding
 public static void Display(System.Web.HttpResponse response, string contents)
 {
     COMMON.ByteMatrix byteMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, 350, 350);
     Display(response, byteMatrix, ImageFormat.Jpeg, false);
 }
예제 #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //登录用户名
            string memid = Request.QueryString["memid"] ?? "";

            //微信方提供的APPID,从config配置文件中获取
            appid = ConfigurationManager.AppSettings["appid"].ToString();
            //接口文档里的参数(目前不知用处)
            string auth_code = Request.QueryString["auth_code"] ?? "";
            //商品描述
            string body = Request.QueryString["body"] ?? "";
            //微信支付分配的终端设备号
            string device_info = Request.QueryString["device_info"] ?? "";
            //微信方提供的mch_id,从config配置文件中获取
            string mch_id = ConfigurationManager.AppSettings["mch_id"].ToString();
            //随机字符串
            string nonce_str = TenpayUtil.getNoncestr();
            //通知地址,从config配置文件中获取
            string notify_url = ConfigurationManager.AppSettings["domain_url"].ToString() + "/wxpay/WeiXinNotifyUrl.aspx";

            //订单号
            out_trade_no = Request.QueryString["out_trade_no"] ?? "";
            //IP
            string spbill_create_ip = Request.UserHostAddress;

            //金额
            total_fee = Request.QueryString["total_fee"] ?? "";
            total_fee = Convert.ToInt32((Convert.ToDecimal(total_fee) * 100)).ToString();//微信的单位为分,所以乘100

            //附加数据原样返回
            string attach = string.Format("memid={0}|orderid={1}", memid, out_trade_no);

            //由于二维码支付每次发起支付的订单ID都要唯一,所以这里使用时间字段接在订单末尾获取时截取掉
            out_trade_no = out_trade_no + "|" + DateTime.Now.ToString("yyyyMMddHHmmss");

            //获取package包

            //商户密钥,从config配置文件中获取
            string key = ConfigurationManager.AppSettings["key"].ToString();

            //创建支付应答对象
            RequestHandler packageReqHandler = new RequestHandler(Context);

            //初始化
            packageReqHandler.init();

            packageReqHandler.setParameter("appid", appid);
            packageReqHandler.setParameter("body", body);
            packageReqHandler.setParameter("mch_id", mch_id);
            packageReqHandler.setParameter("nonce_str", nonce_str.ToLower());
            packageReqHandler.setParameter("notify_url", notify_url);

            packageReqHandler.setParameter("out_trade_no", out_trade_no);
            packageReqHandler.setParameter("spbill_create_ip", spbill_create_ip);
            packageReqHandler.setParameter("total_fee", total_fee);//商品金额,以分为单位(money * 100).ToString()
            packageReqHandler.setParameter("trade_type", "NATIVE");
            packageReqHandler.setParameter("product_id", out_trade_no);

            string sign = packageReqHandler.createMd5Sign("key", key);

            packageReqHandler.setParameter("sign", sign);

            string data = packageReqHandler.parseXML();

            var result = TenPayV3.Unifiedorder(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");
            var res    = XDocument.Parse(result);

            string code_url = string.Empty;

            try
            {
                if (res.Element("xml").Element("return_code").Value == "SUCCESS")
                {
                    code_url = res.Element("xml").Element("code_url").Value;
                }
            }
            catch (Exception)
            {
            }

            if (!string.IsNullOrEmpty(code_url))
            {
                //生成二维码图片

                MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
                ByteMatrix        bm         = mutiWriter.encode(code_url, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
                Bitmap            img        = bm.ToBitmap();
                MemoryStream      ms         = new MemoryStream();
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                HttpContext.Current.Response.ClearContent(); //需要输出图象信息 要修改HTTP头
                HttpContext.Current.Response.ContentType = "image/jpeg";
                HttpContext.Current.Response.BinaryWrite(ms.ToArray());
                img.Dispose();
                ms.Dispose();
                HttpContext.Current.Response.End();
            }
        }
 private void txtBarcodeInput_TextChanged(object sender, TextChangedEventArgs e)
 {
     
     if (this.txtBarcodeInput.Text.Length == 13 && barcodeControl != null)
     {
         MultiFormatWriter barcodeWriter = new MultiFormatWriter();
         Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(delegate
         {
             _Global_C_ShowWaitingScreen();
             ByteMatrix barcodeData = barcodeWriter.encode(txtBarcodeInput.Text, BarcodeFormat.EAN_13, (int)(barcodeControl.imgBarcodeImg.Width), (int)(barcodeControl.imgBarcodeImg.Height * 0.8));
             barcodeControl.imgBarcodeImg.Source = getImageSource(barcodeData.ToBitmap());
         }));
         _Barcode_D_Dispose(txtBarcodeInput.Text);
     }
     else if (this.txtBarcodeInput.Text.Length == 16 && membershipControl != null)
     {
         MultiFormatWriter barcodeWriter = new MultiFormatWriter();
         Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(delegate
         {
             _Global_C_ShowWaitingScreen();
         }));
         _Membership_D_Dispose(txtBarcodeInput.Text);
     }
 }