c#短信网关中关于短信内容编码的转换
无论在cmpp或sgip中,都会遇到短信编码格式转换的问题。
因为现在短信编码常用的格式有三种:0:ASCII串,8:UCS2编码,15:含GB汉字。在发送或接收短信时,都会用到相应的编码转换。如以下代码:
public static String Decode(Byte[] buf, int StartIndex, int Length, CODING Coding)
{
String str = String.Empty;
if (Coding == CODING.ASCII)
str = System.Text.Encoding.ASCII.GetString(buf, StartIndex, Length);
else if (Coding == CODING.UCS2)
str = System.Text.Encoding.BigEndianUnicode.GetString(buf, 0, Length);
else if (Coding == CODING.GBK)
str = System.Text.UnicodeEncoding.GetEncoding("gb2312").GetString(buf, StartIndex, Length);
return str;
}
public static Byte[] Encode(String str, CODING coding)
{
Byte[] buf = null;
if (str == null)
return buf;
if (coding == CODING.ASCII)
buf = System.Text.Encoding.ASCII.GetBytes(str);
else if (coding == CODING.UCS2)
buf = System.Text.Encoding.BigEndianUnicode.GetBytes(str);
else if (coding == CODING.GBK)
buf = System.Text.UnicodeEncoding.GetEncoding("gb2312").GetBytes(str);
return buf;
}
public static UInt32 CountLength(String str, CODING coding)
{
Byte[] buf = Encode(str, coding);
if (buf != null)
return (UInt32)buf.Length;
else
return 0;
}
在处理接收DELIVER时,也可以这样写
if (Msg_Fmt != 8)
{
if (Msg_Fmt != 15)
{
this.Msg_Content = System.Text.Encoding.ASCII.GetString(buffer, iPos, (int)this.Msg_Length);
}
else
{
this.Msg_Content = Syst
相关文档:
问:C# 加密后为何有两种结果的字符串?
比如 cftea 的 MD5 加密后:
有的人的结果是:c2e1861ca90e67ce1f9a62f9c27d8bdc
有的人的结果是:wuGGHKkOZ84fmmL5wn2L3A
答:这是对字节的两种不同表示结果。
第一种是用十六进制表示的(FormsAuthentication.HashPasswordForStoringInConfigFile 就是这种,只是是大写的), ......
引用命名空间:using System.Xml
1.检查所要操作的xml文件是否存在:
System.IO.File.Exists(文件路径及名称);
2.得到xml文件:
(1)在asp.net中可以这样得到:
XmlDocument xmlDoc = new XmlDocument();
//导入xml文档
xmlDoc.Load( Server.MapPath("xmlTesting.xml"));
//导入字符串
/ ......
问:
1.如何在JavaScript访问C#函数?
2.如何在JavaScript访问C#变量?
3.如何在C#中访问JavaScript的已有变量?
4.如何在C#中访问JavaScript函数?
问题1答案如下:
javaScript函数中执行C#代码中的函数:
方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中;
&n ......
asp.net有时候常常用服务器绑定控件有些麻烦...
代码有些杂....
using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Web;
using System.Text;
namespace pub.mo
{
public class bind
{
p ......