NEWS

[C#] Hướng dẫn tạo mã qrcode pay trên Ví điện tử Momo

[C#] Hướng dẫn tạo mã qrcode pay trên Ví điện tử Momo
Đăng bởi: Thảo Meo - Lượt xem: 8258 14:07:22, 06/10/2021DEVEXPRESS   In bài viết

Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn cách tạo mã vạch QRcode có logo trên lập trình c#, winform.

[C#] Tutorial Create QRcode with logo Winform

Ở ví dụ này: mình sẻ demo cách tạo một qrcode momo.

Hiện nay với công nghệ 4.0, cách thanh toán giao dịch qua mạng một cách dễ dàng.

Nếu bạn đang sử dụng ví điện tử momo, các bạn sẽ tạo cho mình thông tin như demo bên dưới để gởi cho khách hàng thanh toán chỉ cần scan mã vạch của mình là thanh toán một cách nhanh chóng tiện lợi.

Giao diện demo ứng dụng tạo mã QRcode MOMO C#:

qr_code_pay

Trên mã qrcode momo bao gồm 4 thông tin cơ bản:

  1. Số điện thoại
  2. Tên người nhận
  3. Địa chỉ email
  4. Số tiền muốn để khách hàng thanh toán.

Khi các bạn tạo mã qrcode MOMO xong, khách hàng mở app momo lên quét momo sẽ hiện thị thông tin như hình ảnh dưới đây:

qrcode_momo_pay

Để làm ứng dụng trên, các bạn cần tải thư viện Zxing để tạo mã vạch qrcode từ momo, chi tiết các bạn có thể xem ở video hướng dẫn

Full source code C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing;
using ZXing.Common;
using ZXing.QrCode.Internal;
using ZXing.Rendering;

namespace QRCodeMoMoPay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_pay_Click(object sender, EventArgs e)
        {
            var qrcode_text = $"2|99|{txt_phone.Text.Trim()}|{txt_name.Text.Trim()}|{txt_email.Text.Trim()}|0|0|{txt_sotien.Text.Trim()}";
            BarcodeWriter barcodeWriter = new BarcodeWriter();
            EncodingOptions encodingOptions = new EncodingOptions() { Width = 250, Height = 250, Margin = 0, PureBarcode = false };
            encodingOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            barcodeWriter.Renderer = new BitmapRenderer();
            barcodeWriter.Options = encodingOptions;
            barcodeWriter.Format = BarcodeFormat.QR_CODE;
            Bitmap bitmap = barcodeWriter.Write(qrcode_text);
            Bitmap logo = resizeImage( Properties.Resources.logo_momo, 64,64) as Bitmap;
            Graphics g = Graphics.FromImage(bitmap);
            g.DrawImage(logo, new Point((bitmap.Width - logo.Width) / 2, (bitmap.Height - logo.Height) / 2));
            pic_qrcode.Image = bitmap;
        }

        public Image resizeImage(Image image, int new_height, int new_width)
        {
            Bitmap new_image = new Bitmap(new_width, new_height);
            Graphics g = Graphics.FromImage((Image)new_image);
            g.InterpolationMode = InterpolationMode.High;
            g.DrawImage(image, 0, 0, new_width, new_height);
            return new_image;
        }
    }
}

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hướng dẫn tạo mã qrcode pay trên Ví điện tử Momo
Đăng bởi: Thảo Meo - Lượt xem: 8258 14:07:22, 06/10/2021DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.