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
相关文档:
在 System.Security.Cryptography 中,我们可以看到有许多类,有些类还很相似,比如:
System.Security.Cryptography.SHA1
System.Security.Cryptography.SHA1Managed
System.Security.Cryptography.SHA1CryptoServiceProvider
这三个类有什么关系呢?
SHA1
是抽象类
,SHA1Managed
和 SHA1CryptoServiceProvider ......
首先了解一下什么是Qname
下面是一篇写的比较好的关于Qname的介绍:
http://blog.csdn.net/fbysss/archive/2007/06/24/1664076.aspx
可见Qname主要是处理namesapce的,是指具有特定前缀的xml element。而且Qname就是QualifiedName的缩写,所以Qname在C#中对应的应该是XmlQualifiedName这个类 ......
新建一个专门用来创建验证码图片的页面ValidateCode.aspx
它的后台cs文件代码如下:
PageLoad
复制代码 代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
string checkCode = CreateRandomCode(4);
Session["CheckCode"] = checkCode;
CreateImage(checkCode);
}
其中CreateRand ......
在合作开发时,C#时常需要调用C++DLL,当传递参数时时常遇到问题,尤其是传递和返回字符串是,现总结一下,分享给大家:
VC++中主要字符串类型为:LPSTR,LPCSTR, LPCTSTR, string, CString, LPCWSTR, LPWSTR等
但转为C#类型却不完全相同。
主要有如下几种转换:
将string转为IntPtr:IntPtr System.Runtime.InteropServ ......
2010这个元旦太无聊了,于是找了个奇迹游戏私服耍,在玩的过程中发现总是要登录到网站上去转生加点之类的操作,1次2次还好,100次你就郁闷了,于是自己想写个简单的程序来做。
以下就是代码部分啦:
(需要注意的是WebClient的Cookie部分)
using System;
using System.Collections.Generic;
using System.ComponentMo ......