VietQR.Deeplink.Client
1.0.6
dotnet add package VietQR.Deeplink.Client --version 1.0.6
NuGet\Install-Package VietQR.Deeplink.Client -Version 1.0.6
<PackageReference Include="VietQR.Deeplink.Client" Version="1.0.6" />
<PackageVersion Include="VietQR.Deeplink.Client" Version="1.0.6" />
<PackageReference Include="VietQR.Deeplink.Client" />
paket add VietQR.Deeplink.Client --version 1.0.6
#r "nuget: VietQR.Deeplink.Client, 1.0.6"
#:package VietQR.Deeplink.Client@1.0.6
#addin nuget:?package=VietQR.Deeplink.Client&version=1.0.6
#tool nuget:?package=VietQR.Deeplink.Client&version=1.0.6
VietQR.Deeplink.Client
Thư viện client C# (.NET) kết nối dịch vụ VietQR Deeplink để lấy link mở ứng dụng ngân hàng khi thanh toán bằng mã VietQR, hỗ trợ Dependency Injection trong ASP.NET Core và phương thức mở rộng cho VietQR.Core.
⚡ Tính năng
- Mở rộng VietQR.Core: Tạo mã thanh toán và lấy link mở app ngân hàng nhanh chóng chỉ với 1 dòng lệnh.
- Tra cứu danh sách App tự động: Cung cấp hàm
GetSupportedAppsAsync()và API công khai để lấy danh sách 43+ ngân hàng & ví điện tử (kèm logo, mã BIN, cờSupportsAutofill). - Truyền mã linh hoạt: Chấp nhận
AppCode("MB"),ShortName("MBBank"), mãBIN6 số ("970422") hoặcAlias(không phân biệt hoa thường). - Dependency Injection: Đăng ký qua
services.AddVietQrDeeplink()trong ASP.NET Core hoặc Generic Host. - Tự động nhận diện Endpoint: Tự động cập nhật domain máy chủ Deeplink qua Discovery Endpoint (có in-memory cache).
- Hỗ trợ đa nền tảng .NET: Chạy tốt trên .NET 6.0, .NET 8.0, .NET 9.0, .NET 10.0.
📦 Cài đặt
dotnet add package VietQR.Core
dotnet add package VietQR.Deeplink.Client
🚀 Hướng dẫn sử dụng
1. Đăng ký dịch vụ trong Program.cs
using VietQR.Deeplink.Client;
// Cách 1: Sử dụng cấu hình mặc định (Zero-config, chạy ngay không cần tham số)
builder.Services.AddVietQrDeeplink();
// Cách 2: Tùy biến domain máy chủ hoặc timeout nếu tự host
builder.Services.AddVietQrDeeplink(options =>
{
options.BaseUrl = "https://deeplink.example.com";
options.TimeoutSeconds = 10;
});
Cấu hình mẫu trong appsettings.json (tùy chọn, không bắt buộc):
{
"Deeplink": {
"BaseUrl": "https://deeplink.example.com",
"TimeoutSeconds": 10
}
}
2. Tạo link mở App Ngân hàng trong Controller / Service
using VietQR.Core;
using VietQR.Deeplink.Client;
public class CheckoutController : ControllerBase
{
private readonly IVietQrDeeplinkClient _deeplinkClient;
public CheckoutController(IVietQrDeeplinkClient deeplinkClient)
{
_deeplinkClient = deeplinkClient;
}
[HttpPost("pay")]
public async Task<IActionResult> CreatePayment(CancellationToken ct)
{
// 1. Tạo chuỗi QR thanh toán chuẩn Napas247 bằng VietQR.Core
var qr = new VietQr()
.SetBeneficiaryOrganization("970422", "113366668888", VietQrServiceType.Account)
.SetTransactionAmount("50000")
.SetAdditionalData(purpose: "Thanh toan don hang #1024");
// 2. Lấy link ngắn hạn mở app ngân hàng
// Tham số thứ 2 chấp nhận: Mã App ("MB"), Tên ngắn ("MBBank") hoặc Mã BIN 6 số ("970422")
var intent = await qr.ToDeeplinkUrlAsync(_deeplinkClient, "MB", ct);
if (intent == null)
{
return BadRequest("Không thể tạo link mở app ngân hàng.");
}
// intent.Url: "https://deeplink.example.com/p/x8K2mN9..."
// intent.ExpiresInSeconds: 60
return Ok(new { paymentUrl = intent.Url, expiresIn = intent.ExpiresInSeconds });
}
}
🔍 Làm sao để biết Ngân hàng / Ví điện tử nào được hỗ trợ?
Bạn có 2 cách để lấy hoặc kiểm tra danh sách các ứng dụng được hỗ trợ mở Deeplink:
Cách 1: Lấy bằng code C# qua SDK (GetSupportedAppsAsync)
Dùng hàm _deeplinkClient.GetSupportedAppsAsync() để lấy danh sách động từ máy chủ (rất tiện để trả về cho Frontend/Mobile dựng màn hình chọn App thanh toán):
[HttpGet("supported-apps")]
public async Task<IActionResult> GetSupportedApps(CancellationToken ct)
{
IReadOnlyList<DeeplinkBankAppInfo> apps = await _deeplinkClient.GetSupportedAppsAsync(ct);
// Ví dụ lọc ra các ngân hàng hỗ trợ tự động điền thông tin chuyển khoản (Autofill)
var autofillApps = apps.Where(a => a.SupportsAutofill).ToList();
return Ok(apps);
}
Mỗi phần tử DeeplinkBankAppInfo trả về gồm:
AppCode: Mã truyền vào hàm tạo link (VD:"MB","VCB","TPB","MOMO").Bin: Mã BIN 6 số chuẩn NAPAS (VD:"970422").ShortName: Tên viết tắt ngân hàng (VD:"MBBank","Vietcombank").AppName: Tên ứng dụng hiển thị (VD:"MB Bank","VCB Digibank").Logo: URL ảnh icon ứng dụng ngân hàng sắc nét.SupportsAutofill:truenếu mở thẳng màn hình chuyển khoản và tự điền STK/Số tiền/Nội dung;falsenếu chỉ mở ứng dụng.
Kết quả JSON mẫu khi trả về cho Frontend:
{
"code": "00",
"desc": "success",
"data": [
{
"appCode": "MB",
"bin": "970422",
"shortName": "MBBank",
"appName": "MB Bank",
"logo": "https://deeplink.example.com/icons/mb.png",
"supportsAutofill": true,
"supportsIos": true,
"supportsAndroid": true
},
{
"appCode": "VCB",
"bin": "970436",
"shortName": "Vietcombank",
"appName": "VCB Digibank",
"logo": "https://deeplink.example.com/icons/vcb.png",
"supportsAutofill": false,
"supportsIos": true,
"supportsAndroid": true
}
]
}
Cách 2: Gọi trực tiếp qua HTTP REST API
GET https://vietqr.hiendev.io.vn/api/v1/vietqr-core/deeplink/apps
Hệ thống sẽ trả về danh mục ngân hàng kèm logo, mã BIN và cờ supportsAutofill (true nếu hỗ trợ tự điền dữ liệu, false nếu chỉ mở ứng dụng).
Lưu ý về cơ chế Deeplink:
- Nhóm 1 (
supportsAutofill = true): Mở app + tự động điền sẵn STK, số tiền, nội dung vào màn hình chuyển khoản (Hiện có 7 app: BIDV, MB, OCB, TPBank, CAKE, MoMo, ZaloPay).- Nhóm 2 (
supportsAutofill = false): Vẫn là Deeplink mở thẳng ứng dụng ngân hàng trên thiết bị (dẫn vào app hoặc màn hình quét mã QR/chuyển tiền), không tự điền sẵn dữ liệu.💡 Mẹo truyền mã: Khi gọi
ToDeeplinkUrlAsync(_deeplinkClient, appCode)hoặcCreateIntentAsync(appCode, qrContent), bạn có thể truyền linh hoạt bất kỳ định danh nào: mãappCode(VD:"MB"), tên viết tắtshortName(VD:"MBBank"), mãBIN6 số chuẩn NAPAS (VD:"970422"), hoặc bí danhaliasesmà không phân biệt chữ hoa/thường.
📄 Giấy phép
Phát hành theo giấy phép MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- VietQR.Core (>= 1.0.6)
-
net6.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- VietQR.Core (>= 1.0.6)
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- VietQR.Core (>= 1.0.6)
-
net9.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- VietQR.Core (>= 1.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
feat(api): Tối ưu giao diện test Deeplink playground và cập nhật tài liệu client (252ad03)