pdu格式转换器,自己编的,附源码,源程序
http://cache.amobbs.com/bbs_upload782111/files_49/ourdev_705513ECBL5B.JPG(原文件名:aa.JPG)
点击此处下载 ourdev_705514VSOX1I.rar(文件大小:44K) (原文件名:GBtoUCS2.rar)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GBtoUCS2
{
public partial class Form1 : Form
{
string userDataLenghth;
string userData;
private string protocolDataUnitType = "11";
private string MR = "00";
private string PID = "00";
private string DCS = "08";
private string VP = "C4";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString() == "GBtoUCS2")
{
string userData;
userData = string.Empty;
//数据部分字符串赋空值,以便写入编码
Encoding encodingUTF = Encoding.BigEndianUnicode;
//Encoding.BigEndianUnicode可直接完成数据编码与高低字节的交换,若用Unicode需再加高低字节的互换
byte[] Bytes = encodingUTF.GetBytes(textBox1.Text);
for (int i = 0; i < Bytes.Length; i++)
{
userData += BitConverter.ToString(Bytes, i, 1);
}
userDataLenghth = (userData.Length / 2).ToString("X2");//完成UDL计算与赋值(1个8位组)
textBox2.Text = userData;
}
}
private void button2_Click(object sender, EventArgs e)
{
ud(textBox5.Text);
textBox6.Text = sca(textBox3.Text) + protocolDataUnitType + MR + da(textBox4.Text) + PID + DCS + VP+userDataLenghth+userData;
}
private string sca(string value)
{
string serviceCenterAddress;
if (value == null || value.Length == 0) //号码为空 短消息中心号码为空 则SCA部分编码为”00”
{
serviceCenterAddress = "00";
}
else
{
if (value == '+') //去掉服务中心前导加号
{
value = value.TrimStart('+');
}
if (value.Substring(0, 2) != "86")
{
value = "86" + value; //服务中心加86
}
value = "91" + ParityChange(value); //国际码
serviceCenterAddress = (value.Length / 2).ToString("X2") + value;
}
return serviceCenterAddress;
}
private string da(string value)
{
string destinationAddress;
if (value == null || value.Length == 0) //号码为空
{
destinationAddress = "00";
}
else
{
if (value == '+')
{
value = value.TrimStart('+');
}
if (value.Substring(0, 2) == "86")
{
value = value.TrimStart('8', '6');
}
int len = value.Length;
value = ParityChange(value);
destinationAddress = len.ToString("X2") + "81" + value;
}
return destinationAddress;
}
private string ParityChange(string str)
{
string result = string.Empty;
if (str.Length % 2 != 0) //奇字符串 补F
{
str += "F";
}
for (int i = 0; i < str.Length; i += 2)
{
result += str;
result += str;
}
return result;
}
private void ud(string value)
{
userData = string.Empty;
//数据部分字符串赋空值,以便写入编码
Encoding encodingUTF = Encoding.BigEndianUnicode;
//Encoding.BigEndianUnicode可直接完成数据编码与高低字节的交换,若用Unicode需再加高低字节的互换
byte[] Bytes = encodingUTF.GetBytes(value);
for (int i = 0; i < Bytes.Length; i++)
{
userData += BitConverter.ToString(Bytes, i, 1);
}
userDataLenghth = (userData.Length / 2).ToString("X2");//完成UDL计算与赋值(1个8位组)
}
}
} 顶LZ,资料不错。 回复【1楼】moyuker
顶lz,资料不错。
-----------------------------------------------------------------------
希望对你有用 谢谢lz,能不能出个逆转换的? Thanks.... 标记下 下了,谢谢楼主分享!!! 好东西,谢谢lz! 不错,,可以参考下 好像我以前用过unicode也能发送中文的 谢啦,好东西,正好用的上.
页:
[1]