- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
- [C#] Hướng dẫn tạo ứng dụng dock windows giống Taskbar
- [C#] Chia sẻ source code sử dụng Object Listview trên Winform
- [VB.NET] Chia sẻ source code quản lý thu chi mô hình 3 lớp Winform
- [DATABASE] Xóa lịch sử danh sách đăng nhập tài khoản trên SMSS Sqlserver Management Studio
- [C#] Sử dụng FolderBrowserDialog Vista trên Winform
- [DEVEXPRESS] Chia sẻ tool Winform UI Templates Early Access Preview (EAP)
- [C#] Chia sẻ source code Spin Content (Trộn nội dung văn bản theo từ đồng nghĩa) trên Winform
- [VB.NET] Chia sẻ source code lịch âm dương và hẹn lịch nhắc việc
- [C#] Hướng dẫn đọc thông số thiết bị Thiết bị kiểm tra Pin (HIOKI BATTERY HiTESTER BT3562)
- [VB.NET] Hướng dẫn giải captcha sử dụng dịch vụ AZCaptcha API trên winform
- [C#] Hướng dẫn chứng thực đăng nhập ứng dụng bằng vân tay (Finger Print) trên máy tính
- [C#] Color Thief cách xuất màu sắc thiết kế từ hình ảnh
- [C#] Cách tạo bản quyền và cho phép dùng thử ứng dụng Winform
- [C#] Hướng dẫn sử dụng trình duyệt web Chrome convert HTML sang tập tin file PDF
- [C#] Kết nôi điện thoại Android, IOS với App Winform via Bluetooth
- [DATABASE] Cách query cộng trừ dồn dần trong Sqlserver
[C#] Encode và Decode Text to PDU trong lập trình csharp
Bài viết hôm nay, mình sẽ hướng dẫn các bạn cách mã hóa và giải mã PDU trong lập trình C# sử dụng thư viện SMSPDULib
.
[C#] Encode and Decode PDU Winform
PDU là một mã code được sử dụng trong lĩnh vực viễn thông, nếu các bạn nào đã tìm hiểu về lập trình sử dụng tập lệnh AT command để gởi tin nhắn SMS, thì các bạn sẽ thấy PDU này.
Mục đích của bài viết này, là mình giúp các bạn nào đang lập trình gởi SMS với thiết bị DCom 3G hoặc thiết bị chuyên dụng GSM Modem.
Nếu các bạn muốn gởi nội dung tin nhắn dưới dạng Unicode có dấu tiếng việt, thì các bạn cần chuyển đổi Text sang chế độ PDU, để gởi tin nhắn theo chế độ PDU Mode.
Các bạn có thể tìm hiểu thêm về PDU ở link bên dưới:
http://www.gsm-modem.de/sms-pdu-mode.html
Giao diện demo ứng dụng:
Đầu tiên, các bạn cần Import thư viện SMSPDULib
vào, các bạn có thể lấy thư viện ở source code C# mình gởi bên dưới.
Full Source code C# Encode and Decode PDU Mode:
using SMSPDULib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PDU_Decode_Encode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_encode_Click(object sender, EventArgs e)
{
SMS sms = new SMS();
sms.Direction = SMSDirection.Submited;
sms.PhoneNumber = "+84933913122";
sms.ValidityPeriod = new TimeSpan(4, 0, 0, 0);
sms.Message = txt_text.Text;
txt_pdu.Text = sms.Compose(SMS.SMSEncoding.UCS2);
}
private void btn_decode_Click(object sender, EventArgs e)
{
string source = txt_pdu.Text;
SMSType smsType = SMSBase.GetSMSType(source);
switch (smsType)
{
case SMSType.SMS:
SMS sms = new SMS();
SMS.Fetch(sms, ref source);
ShowSMS(sms);
break;
case SMSType.StatusReport:
SMSStatusReport statusReport = new SMSStatusReport();
SMSStatusReport.Fetch(statusReport, ref source);
ShowStatusReport(statusReport);
break;
}
}
private void ShowStatusReport(SMSStatusReport sms)
{
string format = "Service center number: {0}
Service center time stamp: {1}
Message reference #: {2}
Phone number: {3}
Report time stamp: {4}
Report status: {5}";
txt_text.Text = string.Format(format,
sms.ServiceCenterNumber,
sms.ServiceCenterTimeStamp,
sms.MessageReference,
sms.PhoneNumber,
sms.ReportTimeStamp,
sms.ReportStatus);
}
private void ShowSMS(SMS sms)
{
string format = "Service center number: {0}
Service center time stamp: {1}
Message reference #: {2}
Direction: {3}
Phone number: {4}
Status report indication: {5}
Message:
{6}";
txt_text.Text = string.Format(format,
sms.ServiceCenterNumber,
sms.ServiceCenterTimeStamp,
sms.MessageReference,
sms.Direction,
sms.PhoneNumber,
sms.StatusReportIndication,
sms.Message);
}
}
}
HAPPY CODING