搜索
bottom↓
回复: 10

pdu格式转换器,自己编的,附源码,源程序

[复制链接]

出0入0汤圆

发表于 2011-12-17 13:11:41 | 显示全部楼层 |阅读模式

(原文件名: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[0] == '+')                    //去掉服务中心前导加号
                {
                    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[0] == '+')
                {
                    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[i + 1];
                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位组)
        }
    }
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。

出0入0汤圆

发表于 2011-12-17 13:19:05 | 显示全部楼层
顶LZ,资料不错。

出0入0汤圆

 楼主| 发表于 2011-12-18 13:05:59 | 显示全部楼层
回复【1楼】moyuker  
顶lz,资料不错。
-----------------------------------------------------------------------

希望对你有用

出0入0汤圆

发表于 2013-3-23 11:57:58 | 显示全部楼层
谢谢lz,能不能出个逆转换的?

出0入0汤圆

发表于 2013-5-3 18:34:55 | 显示全部楼层
Thanks....

出0入0汤圆

发表于 2013-5-3 21:39:58 | 显示全部楼层
标记下   

出0入0汤圆

发表于 2013-10-17 08:48:43 | 显示全部楼层
下了,谢谢楼主分享!!!

出0入0汤圆

发表于 2014-2-12 08:58:17 | 显示全部楼层
好东西,谢谢lz!

出5入4汤圆

发表于 2014-10-17 15:46:49 | 显示全部楼层
不错,,可以参考下

出0入0汤圆

发表于 2014-10-17 16:20:23 | 显示全部楼层
好像我以前用过unicode也能发送中文的

出0入0汤圆

发表于 2014-11-23 12:50:29 | 显示全部楼层
谢啦,好东西,正好用的上.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-10-3 00:51

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表